fix(api-gateway): prevent gateway controller from processing non-consul gateways #4952
+177
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes proposed in this PR
Add early return check in gateway controller Reconcile method to skip
gateways that don't belong to the consul controller. This prevents the
controller from processing and potentially deleting resources for
gateways managed by other gateway controllers in multi-controller
environments.
The fix checks the GatewayClass.Spec.ControllerName against the consul
controller name (consul.hashicorp.com/gateway-controller) and returns
early if there's no match or if the GatewayClass is missing.
This follows the same pattern already used in the GatewayClass controller
and prevents unauthorized resource deletion that could occur when multiple
gateway controllers are deployed in the same cluster.
Fixes: Gateway controller reconciliation of non-consul gateways
Addresses Issue #4894
How I've tested this PR
Added comprehensive unit tests (TestGatewayControllerReconcile) to validate:
Locally built a docker image, deployed consul to k8s cluster via Helm chart to validate functionality
How I expect reviewers to test this PR
Run unit tests, build image locally, deploy to k8s with helm chart.
Checklist
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.