[2.2] fix: Do not mutate a Service kgateway does not own.#14350
Merged
davidjumani merged 2 commits intoJul 10, 2026
Merged
Conversation
Signed-off-by: David L. Chandler <[email protected]> (cherry picked from commit fb8b18f)
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents kgateway’s deployer from overwriting an existing Kubernetes Service for a Gateway unless the Service demonstrates ownership (via controller ownerReference or matching kgateway/Gateway labels), avoiding accidental takeover when an unrelated Service shares the same name.
Changes:
- Added ownership validation before patching an existing
ServiceduringDeployObjsWithSource. - Added deployer unit tests covering “refuse patch”, “allow via labels”, and “allow via controller ownerRef”.
- Stabilized a multiinstall e2e policy test by using non-fatal assertions within
Eventuallyand increasing the wait timeout.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/e2e/features/multiinstall/suite.go | Makes the log-verification Eventually block non-fatal per-iteration and increases timeout for stability. |
| pkg/kgateway/helm/envoy/templates/service.yaml | Minor Helm templating formatting adjustment (whitespace). |
| pkg/deployer/deployer.go | Introduces Service ownership validation gate before patching existing Services. |
| pkg/deployer/deployer_test.go | Adds tests to ensure Services are only patched when owned via ownerRef or labels. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2869
to
+2874
| APIVersion: wellknown.GatewayGVK.GroupVersion().String(), | ||
| Kind: wellknown.GatewayGVK.Kind, | ||
| Name: gw.GetName(), | ||
| UID: gw.GetUID(), | ||
| Controller: new(true), | ||
| }} |
Comment on lines
+449
to
+465
| func hasMatchingGatewayServiceMetadata(existingObj, desiredObj client.Object) bool { | ||
| existingLabels := existingObj.GetLabels() | ||
| desiredLabels := desiredObj.GetLabels() | ||
| if existingLabels[appKubernetesManagedByLabel] != kgatewayManagedByValue || | ||
| desiredLabels[appKubernetesManagedByLabel] != kgatewayManagedByValue { | ||
| return false | ||
| } | ||
|
|
||
| if desiredClassName, ok := desiredLabels[wellknown.GatewayClassNameLabel]; ok { | ||
| if existingLabels[wellknown.GatewayClassNameLabel] != desiredClassName { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| desiredGatewayLabel, desiredHasGatewayLabel := desiredLabels[wellknown.GatewayNameLabel] | ||
| return desiredHasGatewayLabel && existingLabels[wellknown.GatewayNameLabel] == desiredGatewayLabel | ||
| } |
davidjumani
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport of #14145 to
v2.2.x.Description
Fixes #13499.
kgateway now refuses to patch an existing Gateway
Serviceunless theServiceproves ownership through either:ownerReferencefor the sourceGatewayapp.kubernetes.io/managed-by: kgatewaygateway.networking.k8s.io/gateway-class-namegateway.networking.k8s.io/gateway-nameorgateway.kgateway.dev/gateway-full-nameThis prevents accidental takeover of unrelated Services with the same name as a Gateway.
Upgrade behavior
2.2.0
ownerReferenceand kgateway labels.2.3.0, main
Change Type
/kind fix
Changelog
Additional Notes