Skip to content

refactor(agent): gamma and l4route reconcilers share referencegrant.ResolveBackends - #1172

Merged
bpalermo merged 1 commit into
mainfrom
refactor/consolidate-backends-resolve
Oct 4, 2026
Merged

bpalermo merged 1 commit into
mainfrom
refactor/consolidate-backends-resolve

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #1168. The base is refactor/consolidate-backendref-helpers because this PR uses referencegrant.BackendNamespace, which #1168 adds. Before #1168 merges, retarget this PR to main with gh pr edit 1172 --base main. Otherwise deleting the base branch auto-closes this PR.

What

The node agent's two route reconcilers each had a backendsResolve method with the same body:

  • agent/internal/gamma/reconciler.go:428 (HTTPRoute/GRPCRoute)
  • agent/internal/l4route/reconciler.go:342 (TCPRoute/TLSRoute/UDPRoute)

Neither copy used its receiver or its context.Context. The logic is the ReferenceGrant-plus-shape check for a route's ResolvedRefs condition, and both packages already import common/referencegrant. It now lives there once as referencegrant.ResolveBackends(routeNamespace, routeKind, refs, grants) (bool, reason, message). The doc comment is merged from both copies. Both reconcilers call the shared function.

The edge reconciler's backendsResolveL4 is not the same function, so it is left alone. It adds a registry/k8s existence check (backendExists) after the grant check.

Tests: TestBackendsResolve_Shapes moved from agent/internal/gamma/reconciler_test.go to common/referencegrant/backendref_test.go as TestResolveBackends_Shapes. All five cases are kept. The only change is that the calls go to the function instead of r.backendsResolve(ctx, ...). l4route had no direct test of its copy.

Proof the copies were identical

Signatures and bodies on origin/main, compared with a function-extracting diff:

IDENTICAL: agent/internal/gamma/reconciler.go:backendsResolve == agent/internal/l4route/reconciler.go:backendsResolve (16 lines)

The doc comments differ only in the last sentence, which lists the route kinds each caller passes.

Module counts (bazel query 'deps(<bin>)', external repos / external labels)

binary before after
//agent/cmd/agent 116 / 7408 116 / 7408
//controller/cmd/controller 109 / 6765 109 / 6765
//registrar/cmd/registrar 117 / 6921 117 / 6921
//cni/cmd/cni 47 / 2082 47 / 2082
//agent/cmd/mesh-dns 37 / 2023 37 / 2023
//agent/cmd/proxy-supervisor 31 / 1645 31 / 1645

Verification

  • bazel test --config=race on //common/referencegrant, //agent/internal/gamma and //agent/internal/l4route: all pass.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.
  • make format-check: clean.
  • make gazelle: done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

@bpalermo
bpalermo changed the base branch from refactor/consolidate-backendref-helpers to main October 3, 2026 22:19
…esolveBackends

The two reconcilers each had a backendsResolve method with the same body. It
never used its receiver or context. It is now one function,
referencegrant.ResolveBackends, which both call. TestBackendsResolve_Shapes
moved with it as TestResolveBackends_Shapes, with every case kept.

Pure refactor: no behaviour change, no binary gains a module.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo force-pushed the refactor/consolidate-backends-resolve branch from d4b985d to 6dcdf89 Compare October 4, 2026 01:28
@bpalermo
bpalermo merged commit 71cf73c into main Oct 4, 2026
24 checks passed
@bpalermo
bpalermo deleted the refactor/consolidate-backends-resolve branch October 4, 2026 01:39
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