Skip to content

refactor(common): one copy of the backendRef key / ReferenceGrant / namespace helpers, in common/referencegrant - #1168

Merged
bpalermo merged 2 commits into
mainfrom
refactor/consolidate-backendref-helpers
Oct 4, 2026
Merged

bpalermo merged 2 commits into
mainfrom
refactor/consolidate-backendref-helpers

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

What

backendServiceKey, backendPermitted and derefBackendNamespace existed as identical copies in two shared projectors, and derefBackendNamespace was copied twice more into the agent's route reconcilers. The edge attachment package carried exported copies of two of them as well. They now live once in common/referencegrant, which every caller already imported:

was (unexported, ×N) now
backendServiceKey (l4project, gammaproject) referencegrant.BackendKey
backendPermitted (l4project, gammaproject), attachment.BackendPermitted (edge) referencegrant.BackendPermitted
derefBackendNamespace (l4project, gammaproject, agent/internal/gamma, agent/internal/l4route), attachment.DerefBackendNamespace (edge) referencegrant.BackendNamespace

Sites:

  • common/l4project/l4project.go (was lines 115-140)
  • common/gammaproject/project.go (was lines 249-270)
  • agent/internal/gamma/reconciler.go and agent/internal/l4route/reconciler.go (derefBackendNamespace only)
  • agent/internal/edge/gatewayapi/attachment/refs.go (BackendPermitted + DerefBackendNamespace, exported copies used by the edge reconciler; second commit)

The only new import edge is common/referencegrant -> common/serviceref. serviceref is stdlib-only, and every package that imports referencegrant already imported it.

Tests: TestBackendServiceKey, TestBackendPermitted and TestDerefBackendNamespace moved from l4project_test.go to common/referencegrant/backendref_test.go. Every assertion is kept. The grant fixture is now built with that package's existing grant/from/to helpers, and it is the same object as l4project's crossNSGrant("TCPRoute").

Proof the copies were identical

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

IDENTICAL: common/l4project/l4project.go:backendServiceKey == common/gammaproject/project.go:backendServiceKey (7 lines)
IDENTICAL: common/l4project/l4project.go:backendPermitted == common/gammaproject/project.go:backendPermitted (7 lines)
IDENTICAL: common/l4project/l4project.go:derefBackendNamespace == common/gammaproject/project.go:derefBackendNamespace (6 lines)
IDENTICAL: common/l4project/l4project.go:derefBackendNamespace == agent/internal/gamma/reconciler.go:derefBackendNamespace (6 lines)
IDENTICAL: common/l4project/l4project.go:derefBackendNamespace == agent/internal/l4route/reconciler.go:derefBackendNamespace (6 lines)

The edge attachment copies differ only in their exported names:

-func backendPermitted(backendNamespace *gatewayv1.Namespace, routeNamespace, routeKind, name string, grants []gatewayv1beta1.ReferenceGrant) bool {
-	ns := derefBackendNamespace(backendNamespace)
+func BackendPermitted(backendNamespace *gatewayv1.Namespace, routeNamespace, routeKind, name string, grants []gatewayv1beta1.ReferenceGrant) bool {
+	ns := DerefBackendNamespace(backendNamespace)
@@
-func derefBackendNamespace(ns *gatewayv1.Namespace) string {
+func DerefBackendNamespace(ns *gatewayv1.Namespace) string {

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, //common/l4project, //common/gammaproject, //agent/internal/gamma, //agent/internal/l4route and //agent/internal/edge/gatewayapi/...: 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 and others added 2 commits October 3, 2026 22:18
…amespace helpers, in common/referencegrant

backendServiceKey, backendPermitted and derefBackendNamespace were
byte-identical in common/l4project and common/gammaproject, and
derefBackendNamespace was copied a further two times into the agent's
gamma and l4route reconcilers. They now live once in common/referencegrant
(which every one of those packages already imported) as BackendKey,
BackendPermitted and BackendNamespace. Their unit tests moved with them.

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
…ackendNamespace

attachment.BackendPermitted and attachment.DerefBackendNamespace were further
copies of the same two helpers (same bodies). Their callers in the edge
reconciler now use referencegrant.BackendPermitted and BackendNamespace.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo force-pushed the refactor/consolidate-backendref-helpers branch from c662d43 to d75dc79 Compare October 4, 2026 01:18
@bpalermo
bpalermo merged commit 928bcb2 into main Oct 4, 2026
24 checks passed
@bpalermo
bpalermo deleted the refactor/consolidate-backendref-helpers branch October 4, 2026 01:28
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