Skip to content

refactor(networking): use typed gateway-api client for HTTPRoute#316

Merged
bdchatham merged 1 commit into
mainfrom
refactor/httproute-typed-client
May 21, 2026
Merged

refactor(networking): use typed gateway-api client for HTTPRoute#316
bdchatham merged 1 commit into
mainfrom
refactor/httproute-typed-client

Conversation

@bdchatham
Copy link
Copy Markdown
Collaborator

Summary

Replaces the unstructured / map[string]any HTTPRoute construction in internal/controller/nodedeployment/networking.go with the typed sigs.k8s.io/gateway-api/apis/v1 client. Same wire behavior, cleaner code, compile-time field validation, and a typed foundation for envtest assertions in the upcoming Phase 1 work.

Net: 6 files, +127 / -143.

Why

  1. The hand-rolled map[string]any in generateHTTPRoute() is a typo waiting to happen — any field-name change in the gateway-api spec lands as a silent runtime no-op.
  2. Envtest assertions for HTTPRoute go from route.Object["spec"].(map[string]any)["rules"].([]any)[0]... to route.Spec.Rules[0] — both writing and reading test code becomes orders of magnitude cleaner.
  3. Drops three internal helpers that exist only to wrap unstructured: httpRouteGVK(), deleteUnstructured() (which was already orphaned with zero callers), and toStringInterfaceMap().

Changes

File Change
internal/controller/nodedeployment/networking.go generateHTTPRoute returns *gatewayv1.HTTPRoute; deleteHTTPRoutesByLabel / deleteOrphanedHTTPRoutes / orphanNetworkingResources HTTPRoute branch use *gatewayv1.HTTPRouteList. Three dead helpers removed. SSA apply path unchanged.
cmd/main.go utilruntime.Must(gatewayv1.Install(scheme)) — required so the typed client knows the kind at runtime.
internal/controller/nodedeployment/networking_test.go Assertions rewritten to typed field access. Test intent unchanged; assertions are now ~50% shorter.
internal/controller/nodedeployment/plan_test.go Shared test scheme (newPlanTestScheme) adds gatewayv1.Install so fake-client List(HTTPRouteList) succeeds in tests that exercise the networking teardown path.
go.mod / go.sum Adds sigs.k8s.io/gateway-api v1.5.1 as a direct dep (was already an indirect dep via controller-runtime; net new transitive surface is minimal).

Behavior preservation

  • CRDNotInstalled graceful degradation still works: when the cluster doesn't have the gateway-api CRDs installed, the typed client surfaces the same meta.IsNoMatchError from the apiserver that the unstructured client did. The existing condition-flip + event remain.
  • SSA apply path unchanged — same client.Patch(..., client.Apply, fieldOwner, client.ForceOwnership) call site, same field manager.
  • Production manifests are unaffected; HTTPRoute wire shape is byte-identical (verified against apiVersion: gateway.networking.k8s.io/v1, same fields, same defaults).

Test plan

  • go build ./... exits 0
  • go test ./... exits 0 (all 8 test-bearing packages pass)
  • All 8 TestGenerateHTTPRoute_* tests pass against typed assertions
  • TestInternalService_SurvivesNetworkingTeardown (which exercises deleteHTTPRoutesByLabel against a fake client) passes after registering gatewayv1 in the shared test scheme

Follow-up

This unblocks envtest Phase 1 — the planned TestInPlaceRollout_EndToEnd and future networking assertions get typed access from day one. No vendoring of gateway-api CRDs needed for tests that don't set spec.networking; future networking-aware tests will install the CRDs into envtest's apiserver via CRDDirectoryPaths.

🤖 Generated with Claude Code

@cursor
Copy link
Copy Markdown

cursor Bot commented May 20, 2026

You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace.

To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard.

@bdchatham bdchatham force-pushed the refactor/httproute-typed-client branch from 3881bf3 to 07bfde0 Compare May 20, 2026 23:57
@cursor
Copy link
Copy Markdown

cursor Bot commented May 20, 2026

You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace.

To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard.

Replaces the unstructured/map[string]any construction of HTTPRoute
resources with the typed sigs.k8s.io/gateway-api v1 client. Same wire
behavior, cleaner code, compile-time field validation, and a foundation
for typed envtest assertions in upcoming Phase 1 work.

Changes
- networking.go: HTTPRoute construction (`generateHTTPRoute`), list
  operations (`deleteHTTPRoutesByLabel`, `deleteOrphanedHTTPRoutes`,
  `orphanNetworkingResources` HTTPRoute branch) all converted to
  *gatewayv1.HTTPRoute / *gatewayv1.HTTPRouteList. Apply-patch path
  unchanged (still SSA via client.Patch). The CRDNotInstalled graceful
  degradation continues to work: typed client returns the same
  meta.IsNoMatchError when the apiserver doesn't recognize the kind.
- Drops three now-dead helpers: httpRouteGVK(), deleteUnstructured()
  (was already orphaned), toStringInterfaceMap().
- cmd/main.go: register gatewayv1.Install on the manager scheme so
  the typed client knows the kind.
- networking_test.go: rewrites assertions to typed field access
  (route.Spec.ParentRefs[0].Name, route.Spec.Rules[i].BackendRefs[0].Port
  etc.) instead of navigating map[string]any. Test intent is unchanged.
- plan_test.go: adds gatewayv1.Install to the shared test scheme so
  fake-client List(HTTPRouteList) succeeds for tests that exercise the
  networking teardown path.

Adds sigs.k8s.io/gateway-api v1.5.1 as a direct dep (it was already an
indirect dep via controller-runtime; net new transitive surface is
minimal).

go build ./... and go test ./... both green.
@bdchatham bdchatham force-pushed the refactor/httproute-typed-client branch from 07bfde0 to 74dac1b Compare May 21, 2026 00:09
@cursor
Copy link
Copy Markdown

cursor Bot commented May 21, 2026

You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace.

To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard.

@bdchatham bdchatham merged commit fc4b397 into main May 21, 2026
2 checks passed
bdchatham added a commit that referenced this pull request May 21, 2026
…TTPRoute (#322)

Follow-up to #316. Two regression-armor tests the Coral review surfaced
as load-bearing but didn't make it into the original PR.

- TestGenerateHTTPRoute_TypeMeta: asserts APIVersion + Kind are populated
  on the typed object. The SSA apply path relies on these top-level keys
  matching what the unstructured builder produced pre-#316; an empty
  TypeMeta would silently break server-side apply.
- TestGenerateHTTPRoute_BackendRefDefaultsServerSide: asserts every
  BackendObjectReference leaves Group and Kind nil. Setting them
  explicitly would cause field-manager "seinode-controller" to claim
  those paths via SSA, fighting any future operator who tries to
  retarget a backend. Locks down the no-server-default-claim invariant
  the Coral k8s-specialist flagged in their finding #5.

Test-only change. go test ./... green.
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