Skip to content

BUG/MEDIUM: preserve shared backends when routes are removed - #33

Open
g-patton wants to merge 1 commit into
haproxytech:v1.0from
g-patton:hotfix-hug-routes
Open

g-patton wants to merge 1 commit into
haproxytech:v1.0from
g-patton:hotfix-hug-routes

Conversation

@g-patton

@g-patton g-patton commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

Preserve shared backends when an HTTPRoute or TLSRoute is deleted or invalidated and unchanged routes still reference that backend.

The four affected handlers currently remove route ownership and immediately schedule backend deletion. The same-cycle Upserted safeguard does not protect unchanged surviving owners. Queue the backend in the existing Unreferenced cleanup path instead, so ownership determines whether deletion is appropriate.

This is a targeted four-handler change plus a 12-case regression test; no unrelated refactoring.

Reproduction

  1. Configure separate Gateways/routes referencing the same backend Service (the real-traffic reproduction also used cross-namespace ReferenceGrant).
  2. Verify traffic through each route and a shared generated backend.
  3. Delete one route or its Gateway, leaving surviving routes unchanged.
  4. On stock 1.0.7 and 1.0.8, the shared backend disappears and surviving HTTP/HTTPS requests return 404; TLS passthrough similarly fails.
  5. With this patch, surviving routes retain the backend and traffic without restarting the controller. Removing the final owner still deletes the backend.

Route invalidation exercises the same ownership problem.

Regression coverage

TestSharedBackendRouteRemoval covers HTTPRoute/TLSRoute × deletion/invalidation × zero/one/two surviving owners. It checks deletion decisions, surviving ownership metadata, and retained servers.

  • Stock 1.0.7 and 1.0.8: eight shared-owner cases fail; four final-owner cases pass.
  • Patched 1.0.7 and 1.0.8: all 12 pass.
  • 100 regression repetitions: pass.

Additional completed local validation

  • Gateway package suites on both patched versions: pass.
  • All non-integration Go packages with race detection and shuffled order: pass.
  • Both patched controller binaries compile and run.
  • Existing integration suite: 168 leaf cases across 40 test packages pass, no failures or skipped tests.
  • Lua/HAProxy suite: 47 leaf cases across six test packages pass, no failures or skipped tests.

Disposable kind real-traffic environment: Kubernetes 1.36.1, Gateway API 1.3.0 CRDs, ARM64, and corresponding stock-image HAProxy runtimes with only the patched controller binary replaced. Four stock-image scenarios reproduced the failure (HTTP/HTTPS and TLS passthrough on each version).

Across 18 patched scenarios on the two versions, 6,285 sampled survivor requests had zero observed failures. Coverage included Gateway/route deletion, route invalidation, moving one HTTPRoute to another backend, final-owner cleanup, repeated deletion/recreation, endpoint scaling, controller configuration reconstruction after restart, and two controller replicas with direct traffic checks against each. Restart checks establish recovery, not zero downtime during single-replica restart.

The full existing integration suite separately used embedded Gateway API 1.5.0 CRDs, temporary Kubernetes 1.36.2 API servers, and real HAProxy processes in an offline container. Initial harness readiness/cache/API-server networking issues were resolved before the completed runs; they required no additional application changes.

Branch and validation scope

This PR targets the v1.0 maintenance branch and now includes its upstream history through 72f2128. The original runtime testing described above was on patched 1.0.7 and 1.0.8, not a newly deployed maintenance-tip image. The current head has additionally passed the pinned revive/staticcheck/betteralign linters, commit-policy checking, gofumpt formatting, gateway package tests with race detection and shuffled order, 100 regression repetitions, and controller compilation locally on Go 1.27. The revised regression test still fails all eight shared-owner cases on unpatched 72f2128, while the four final-owner cases pass. All 12 cases pass with the patch.

The CI correction replaces nested test-case loops with an explicit 12-case table and checks the manager type assertion and updated-backend presence. The backend ownership fix is unchanged. Please advise on forward-porting to dev, which has not been validated here.

The additional local traffic harnesses/logs are not committed in this PR. The committed regression test is reproducible with:

POD_IP=127.0.0.1 POD_NAMESPACE=test POD_NAME=test go test ./k8s/gate/haproxy -run TestSharedBackendRouteRemoval -count=1

These are finite local tests, not a production guarantee, long-duration load test, full conformance run, or architecture matrix. No production deployment was changed; the disposable cluster has been removed. No official fixed release is claimed.

Route deletion and invalidation scheduled backend deletion even when
unchanged routes still owned the backend. The same-cycle update safeguard
did not protect those surviving routes.

Use the existing unreferenced-backend cleanup in all four HTTPRoute and
TLSRoute handlers so remaining owners determine backend retention. Add
twelve regression cases covering deletion, invalidation, shared owners,
and final-owner cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant