fix: Do not mutate a Service kgateway does not own.#14145
Merged
davidjumani merged 8 commits intoJun 9, 2026
Merged
Conversation
Fixes kgateway-dev#13499 Signed-off-by: David L. Chandler <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents kgateway from accidentally taking over and mutating an existing Kubernetes Service that happens to share the same name as a reconciled Gateway, unless ownership can be proven via a controller ownerReference or matching kgateway/Gateway metadata.
Changes:
- Add an ownership validation gate before patching an existing
ServiceduringGatewayreconciliation. - Render
gateway.kgateway.dev/gateway-full-nameonto GatewayServiceresources as an ownership/identity signal (including for long Gateway names). - Update deployer Helm-render golden YAML test outputs and add unit tests covering the new “refuse to patch” behavior.
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/deployer/deployer.go | Refuses to patch existing Services unless ownership is proven (ownerRef or matching kgateway/Gateway metadata). |
| pkg/deployer/deployer_test.go | Adds tests for refusing/allowing Service patches based on ownership signals. |
| pkg/kgateway/helm/envoy/templates/service.yaml | Adds Gateway full-name ownership annotation into rendered Service annotations. |
| test/deployer/testdata/base-gateway-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/base-gateway-tls-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/both-gwc-and-gw-have-envoy-extra-args-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/both-gwc-and-gw-have-params-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/both-gwc-and-gw-have-params-reversed-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-all-autoscalers-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-both-gwc-and-gw-have-overlays-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-configs-and-overlays-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-dns-resolver-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-dns-resolver-zero-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-hpa-overlay-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-image-digest-erases-tag-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-infrastructure-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-log-json-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-log-text-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-overlay-ordering-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-pdb-overlay-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-readiness-listener-proxy-protocol-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-sds-and-custom-sidecar-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-strategic-merge-patch-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/envoy-vpa-overlay-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/gwc-with-replicas-null-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/gwc-with-replicas-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/gwc-with-replicas-zero-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/istio-enabled-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/istio-enabled-waypoint-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/loadbalancer-class-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/loadbalancer-source-ranges-api-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/loadbalancer-source-ranges-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/loadbalancer-static-ip-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/long-gateway-name-exactly-63-chars-out.yaml | Updates expected rendered Service to include gateway-full-name annotation for boundary-length Gateway name. |
| test/deployer/testdata/long-gateway-name-over-63-chars-out.yaml | Updates expected rendered Service to include gateway-full-name annotation for >63 char Gateway name. |
| test/deployer/testdata/omit-default-security-context-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/omit-default-security-context-via-gw-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/openshift-two-params-security-context-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/priority-class-name-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/stats-matcher-exclusion-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
| test/deployer/testdata/stats-matcher-inclusion-out.yaml | Updates expected rendered Service to include gateway-full-name annotation. |
…erwriteotherservice
Signed-off-by: David L. Chandler <[email protected]>
Contributor
|
Thanks, looks like this will close #13499 based on PR description. Would love to see this in an upcoming 2.3 release. |
Signed-off-by: David L. Chandler <[email protected]>
…erwriteotherservice' into chandler/13499fixoverwriteotherservice
…writeotherservice
…erwriteotherservice
davidjumani
approved these changes
Jun 9, 2026
This was referenced Jul 3, 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.
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