Skip to content

[2.3] fix: Do not mutate a Service kgateway does not own.#14351

Merged
davidjumani merged 2 commits into
kgateway-dev:v2.3.xfrom
chandler-solo:chandler/backport-14145-v2.3.x
Jul 10, 2026
Merged

[2.3] fix: Do not mutate a Service kgateway does not own.#14351
davidjumani merged 2 commits into
kgateway-dev:v2.3.xfrom
chandler-solo:chandler/backport-14145-v2.3.x

Conversation

@chandler-solo

Copy link
Copy Markdown
Contributor

Backport of #14145 to v2.3.x.


Description

Fixes #13499.

kgateway now refuses to patch an existing Gateway Service unless the Service proves ownership through either:

  • a controller ownerReference for the source Gateway
  • kgateway metadata matching the rendered Gateway Service:
    • app.kubernetes.io/managed-by: kgateway
    • matching gateway.networking.k8s.io/gateway-class-name
    • matching gateway.networking.k8s.io/gateway-name or gateway.kgateway.dev/gateway-full-name

This prevents accidental takeover of unrelated Services with the same name as a Gateway.

Upgrade behavior

  • 2.2.0

    • Communicates ownership with the Gateway controller ownerReference and kgateway labels.
    • Existing Services normally continue through the Gateway ownerRef. The label check is a fallback for orphaned or manually migrated kgateway Services, not the common path.
  • 2.3.0, main

    • See 2.2.0.
    • For long Gateway names, 2.3.0 uses the safe hashed Gateway name label.

Change Type

/kind fix

Changelog

kgateway no longer overwrites an existing Kubernetes Service for a Gateway unless the Service has a matching Gateway ownerReference or kgateway ownership metadata.

Additional Notes

Signed-off-by: David L. Chandler <[email protected]>
(cherry picked from commit fb8b18f)
Copilot AI review requested due to automatic review settings July 3, 2026 04:04
@gateway-bot gateway-bot added kind/fix Categorizes issue or PR as related to a bug. release-note labels Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This backport hardens the Gateway deployer to avoid accidentally taking over and patching an existing Kubernetes Service that wasn’t created/owned by kgateway, addressing the “Gateway name collides with Service name” scenario from #13499.

Changes:

  • Add a Service-ownership guard in the deployer to refuse patching an existing Service unless it is proven to be owned (controller ownerRef or matching kgateway ownership labels).
  • Add deployer unit tests covering allowed/denied patch scenarios for existing Services.
  • Improve E2E stability in the multiinstall suite by making the access-log polling more tolerant and increasing the timeout.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/e2e/features/multiinstall/suite.go Makes log polling assertions non-fatal per retry and increases polling timeout.
pkg/kgateway/helm/envoy/templates/service.yaml Minor Helm template formatting adjustment (no functional change).
pkg/deployer/deployer.go Adds Service ownership validation before patching an existing Service.
pkg/deployer/deployer_test.go Adds tests for refusing/allowing patch based on ownership signals.

Comment thread pkg/deployer/deployer.go
Comment on lines 285 to +289
// If the object doesn't exist or there's an error other than "not found", proceed with patching
switch {
case err == nil:
if err := validateExistingServiceOwnership(sourceObj, obj, existing); err != nil {
return err
@davidjumani
davidjumani added this pull request to the merge queue Jul 10, 2026
Merged via the queue into kgateway-dev:v2.3.x with commit d309fb9 Jul 10, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/fix Categorizes issue or PR as related to a bug. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants