Skip to content

refactor(l4route,edge): one shared L4 backendRef projector in common/l4project (#772) - #783

Merged
bpalermo merged 3 commits into
mainfrom
refactor/772-a8-unify-l4-backends
Sep 16, 2026
Merged

bpalermo merged 3 commits into
mainfrom
refactor/772-a8-unify-l4-backends

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Phase A8 of #772. Data path (TCP floor / TLS SNI / UDP): no CI e2e covers L4, so this gets the talos-main hitless-rollout validation with the Phase A batch.

refactor(l4route,edge): one shared L4 backendRef projector in common/l4project (#772 A8)

buildL4Backends existed twice, with the same signature and — line by line —
the same semantics: agent/internal/l4route/reconciler.go:466 (node agent,
capture-path TCP/TLS/UDP routes, proposal 018 Phase 3b) and
agent/internal/edge/gatewayapi/reconciler.go:946 (edge gateway, proposals
003/018/021). The duplicated TestBuildL4Backends_* tests were the symptom the
test review flagged ("do not consolidate the tests until the two methods are
merged").

Behavioural diff, decided per row (no proposal documents a mesh-vs-edge
difference, and #492 — weight:0 = drain — lives in the proxy layer, not here,
so both copies already passed an explicit 0 through):

backendRef group filter identical (non-empty group skipped) → kept
backendRef kind filter identical (kind != Service skipped) → kept
empty name identical (skipped) → kept
ReferenceGrant check identical logic, different helper
(l4route local vs attachment.*) → one impl
weight defaulting identical (nil → 1) → kept
weight: 0 identical (passed through as drain) → kept
namespace defaulting identical (backendRef ns, else route ns) → kept
service key identical (serviceref "/") → kept
cluster naming ONLY real difference: edge is TCP-only,
the agent also needs "udp:" clusters → ClusterNameFunc
port neither qualifies L4 backends by port → documented
missing Service neither resolves existence here (the
reconcilers report it via ResolvedRefs) → documented

New package common/l4project (not common/gammaproject: that package's doc
scopes it to the HTTPRoute/GRPCRoute → registryv1.GammaRoute proto
projection; L4 backends are a plain Go model and are not exported
cross-cluster). It mirrors gammaproject's shape, including the private
backendPermitted/backendServiceKey/derefBackendNamespace helpers, and
stays free of agent internals — the caller passes a ClusterNameFunc, because
the "tcp:"/"udp:" cluster naming lives in the agent's Envoy builders.

proxy.L4Backend becomes a type alias for l4project.Backend, so the cache and
the Envoy builders are untouched and both reconcilers return the shared type
directly instead of converting.

Tests: the two TestBuildL4Backends_* sets collapse into one table-driven
TestBackends in //common/l4project, a strict superset of both — foreign
group, non-Service kind, explicit core group/Service kind, empty name, nil
weight → 1, explicit weight 0 as drain (#492), weighted splits, ungranted
cross-namespace dropped, granted cross-namespace keeping its own namespace key,
a grant naming the wrong route kind, UDP cluster naming, and the empty-input
case — plus unit tests for the three helpers. Each reconciler keeps one thin
TestBuildL4Backends_Wiring case proving it wires the projector with the right
cluster namer; l4route's existing rule-level tests (TCP/TLS/UDP) are unchanged.

Production code: 117 lines deleted, 24 added across the three touched files;
127 lines added in the shared package (net ~ -30 including its doc comment).
Tests: 81 deleted, 19 added in the reconcilers; 280 added in the shared table.

Verification: bazel build //... //test/e2e:e2e_test OK; bazel test //...
101/101 PASSED (incl. //test/envoy_validate:envoy_validate_test);
bazel run //:format.check clean; bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... clean; bazel run //:gazelle
no churn; bazel mod tidy idempotent; scripts/go-deps-audit.sh exit 0.

Cluster validation (data path) is pending and happens separately. Note for the
orchestrator: e2e.yaml has NO tcp/tls/udp job — its jobs are build,
gateway-http, mesh-http, waypoint, replicator, uds, and both conformance
profiles are HTTP-only. The L4 path's automated coverage is the unit tests plus
//test/envoy_validate; end-to-end TCP-floor/TLS-SNI/UDP exercise is a
hands-on talos run.

docs: list common/l4project in the Core Packages map (#772 A8)

The new shared L4 projector introduced by the previous commit gets an entry
next to its L7 sibling common/gammaproject.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits September 15, 2026 20:28
…l4project (#772 A8)

`buildL4Backends` existed twice, with the same signature and — line by line —
the same semantics: `agent/internal/l4route/reconciler.go:466` (node agent,
capture-path TCP/TLS/UDP routes, proposal 018 Phase 3b) and
`agent/internal/edge/gatewayapi/reconciler.go:946` (edge gateway, proposals
003/018/021). The duplicated `TestBuildL4Backends_*` tests were the symptom the
test review flagged ("do not consolidate the tests until the two methods are
merged").

Behavioural diff, decided per row (no proposal documents a mesh-vs-edge
difference, and #492 — weight:0 = drain — lives in the proxy layer, not here,
so both copies already passed an explicit 0 through):

  backendRef group filter   identical (non-empty group skipped)      → kept
  backendRef kind filter    identical (kind != Service skipped)      → kept
  empty name                identical (skipped)                      → kept
  ReferenceGrant check      identical logic, different helper
                            (l4route local vs attachment.*)          → one impl
  weight defaulting         identical (nil → 1)                      → kept
  weight: 0                 identical (passed through as drain)      → kept
  namespace defaulting      identical (backendRef ns, else route ns) → kept
  service key               identical (serviceref "<ns>/<svc>")      → kept
  cluster naming            ONLY real difference: edge is TCP-only,
                            the agent also needs "udp:" clusters     → ClusterNameFunc
  port                      neither qualifies L4 backends by port    → documented
  missing Service           neither resolves existence here (the
                            reconcilers report it via ResolvedRefs)  → documented

New package `common/l4project` (not `common/gammaproject`: that package's doc
scopes it to the HTTPRoute/GRPCRoute → `registryv1.GammaRoute` *proto*
projection; L4 backends are a plain Go model and are not exported
cross-cluster). It mirrors gammaproject's shape, including the private
`backendPermitted`/`backendServiceKey`/`derefBackendNamespace` helpers, and
stays free of agent internals — the caller passes a `ClusterNameFunc`, because
the "tcp:"/"udp:" cluster naming lives in the agent's Envoy builders.

`proxy.L4Backend` becomes a type alias for `l4project.Backend`, so the cache and
the Envoy builders are untouched and both reconcilers return the shared type
directly instead of converting.

Tests: the two `TestBuildL4Backends_*` sets collapse into one table-driven
`TestBackends` in `//common/l4project`, a strict superset of both — foreign
group, non-Service kind, explicit core group/Service kind, empty name, nil
weight → 1, explicit weight 0 as drain (#492), weighted splits, ungranted
cross-namespace dropped, granted cross-namespace keeping its own namespace key,
a grant naming the wrong route kind, UDP cluster naming, and the empty-input
case — plus unit tests for the three helpers. Each reconciler keeps one thin
`TestBuildL4Backends_Wiring` case proving it wires the projector with the right
cluster namer; l4route's existing rule-level tests (TCP/TLS/UDP) are unchanged.

Production code: 117 lines deleted, 24 added across the three touched files;
127 lines added in the shared package (net ~ -30 including its doc comment).
Tests: 81 deleted, 19 added in the reconcilers; 280 added in the shared table.

Verification: `bazel build //... //test/e2e:e2e_test` OK; `bazel test //...`
101/101 PASSED (incl. `//test/envoy_validate:envoy_validate_test`);
`bazel run //:format.check` clean; `bazel build --config=lint
--@aspect_rules_lint//lint:fail_on_violation //...` clean; `bazel run //:gazelle`
no churn; `bazel mod tidy` idempotent; `scripts/go-deps-audit.sh` exit 0.

Cluster validation (data path) is pending and happens separately. Note for the
orchestrator: `e2e.yaml` has NO tcp/tls/udp job — its jobs are build,
gateway-http, mesh-http, waypoint, replicator, uds, and both conformance
profiles are HTTP-only. The L4 path's automated coverage is the unit tests plus
`//test/envoy_validate`; end-to-end TCP-floor/TLS-SNI/UDP exercise is a
hands-on talos run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
The new shared L4 projector introduced by the previous commit gets an entry
next to its L7 sibling common/gammaproject.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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