Skip to content

feat(agent): key TCP cache entries by cluster identity (037 Phase 1) - #889

Merged
bpalermo merged 1 commit into
mainfrom
feat/037-phase1-cluster-identity-keys
Sep 21, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/037-phase1-cluster-identity-keys

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Proposal 037 Phase 1. Follows #888 (Phase 0).

The bug this closes

Both cluster passes wrote c.clusters[serviceName]. The HTTP pass built the service's h2 cluster, outbound vhost and GAMMA cap_http vhost; the TCP pass ran second and overwrote the same key with a vhost-less tcp:true entry. A service in both listings lost its cluster and both vhosts, and captured requests 503'd with no_healthy_upstream — the #430 failure mode.

This was unreachable while a service could only be one protocol. It is not any more. The registry key is <ns>/<serviceAccount> and the protocol is a per-pod annotation, so a ServiceAccount whose pods disagree — protocol: tcp on half a Deployment — puts one service in both listings. That has been true on etcd all along (the CNI registers each pod under its own protocol key) and is true on the kubernetes backend since #888.

What changed

TCP entries are keyed by their own Envoy cluster name, tcp:<fqdn> — as per-port and alias entries already were. The four readers follow:

reader before after
captureTCPClusters bare key TCP entry
edgeTCPClusters bare key TCP entry
captureUDPClusters bare key whichever entry carries the service-level facts
edgeMeshClusterNameLocked bare key correctly reports not found for a TCP-only service

Taking SANs from the TCP entry is also more correct than before: for a split service the two entries have different endpoints, and the floor must pin the namespaces of the pods it actually reaches.

That last row fixes a latent bug. Today a TCP-only service has a bare-key entry, so edgeMeshClusterNameLocked returns the h2 meshFQDN — a cluster clustersEndpointsAndVhosts never emits for a TCP entry, so the edge route referenced something that does not exist.

Bare-name CLA ownership. Both entries reference an EDS resource named for the service, so exactly one may publish it: the HTTP entry when the service has one, else the TCP entry. Two EDS resources under one name is a snapshot-consistency error in go-control-plane, or a silent last-writer-wins.

retainAbsentClustersLocked now names a rebuilt load assignment after the one it replaces rather than after the map key. Those coincide for HTTP and per-port entries, but a TCP entry is keyed tcp:<fqdn> while publishing the bare-name resource its floor cluster resolves through. Keying off the map key would have retained an empty CLA under a name nothing references and left the real one unpublished — a bug this change would have introduced.

Two deviations from the accepted proposal

Both recorded in the proposal itself rather than left silent:

  • RequireProtocolDisjoint is not retired here. Its specified replacement asserts the two listings' port_protocols agree, and that field arrives in Phase 2. Retiring now would drop a working cross-backend guard and put nothing in its place, while no test exercises the mixed case at registry level. Annotated in place as a convention rather than an invariant, with the swap deferred.
  • envoy_validate gains no case. Phase 1 changes no Envoy resource shape, and the risk it introduces — duplicate EDS name — is invisible to envoy --mode validate, which does not resolve dynamic cluster references. Adding a case there would be decoration; the cache unit test is the gate that can actually fail (No shell script in the root workspace is linted: the shellcheck aspect has no sh_* target to visit #853).

Verification

Two new tests: the mixed-service milestone (h2 cluster and vhost and tcp: floor cluster all survive, with exactly one bare-name EDS resource), and the TCP-only ownership case (the TCP entry publishes the bare-name CLA itself, named for the service and not for the tcp: key).

Negative control: with both production files restored to main and the new test file unchanged, exactly the two new tests fail and no existing test does — so Phase 1 is additive at the xDS contract. My first attempt at this control was impure (I reverted the keying but left the readers on the new key, which failed an existing test as an artifact); redone properly, and the test was changed to spell out the key rather than route through the helper under test.

//agent/..., //registry/..., //test/... — 42 tests pass. bazel build //... clean. --config=race on the touched package passes. Lint clean — buildTCPEndpointsLocked was extracted because the additions pushed buildTCPClustersLocked past the gocognit threshold of 15.

Not yet a usable mixed service

The capture chain is still the portless /32 for TCP-classified services, so a split service's HTTP side is still shadowed by it. This is a correctness fix for the cache. Phase 2 adds the TCP mesh port.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Both cluster passes wrote c.clusters[serviceName]. The HTTP pass built a
service's h2 cluster, outbound vhost and GAMMA cap_http vhost; the TCP pass ran
second and OVERWROTE the same key with a vhost-less tcp:true entry. A service
present in both listings therefore lost its cluster and both vhosts, and
captured requests to it 503'd with no_healthy_upstream -- the #430 failure
mode.

That was unreachable while a service could only be one protocol. It is not any
more. The registry key is <ns>/<serviceAccount> and the protocol is a PER-POD
annotation, so a ServiceAccount whose pods disagree -- `protocol: tcp` on half
a Deployment -- puts one service in both listings. True on etcd all along (the
CNI registers each pod under its own protocol key), and on the kubernetes
backend since #878.

TCP entries are now keyed by their own Envoy cluster name, "tcp:<fqdn>", as
per-port and alias entries already were. The four readers that looked a TCP
service up by bare key follow: captureTCPClusters and edgeTCPClusters take the
TCP entry (which also pins the right SANs -- for a split service the two
entries have DIFFERENT endpoints), captureUDPClusters takes whichever entry
carries the service-level facts it needs, and edgeMeshClusterNameLocked now
correctly reports "not found" for a TCP-only service instead of returning an h2
cluster name that clustersEndpointsAndVhosts never emits.

Bare-name CLA ownership: both entries reference an EDS resource named for the
service, so exactly one may publish it. The HTTP entry owns it when the service
has one; otherwise the TCP entry does. Two EDS resources under one name is a
snapshot-consistency error in go-control-plane, or a silent last-writer-wins.

retainAbsentClustersLocked now names a rebuilt load assignment after the one it
replaces rather than after the map key. Those coincide for HTTP and per-port
entries, but a TCP entry is keyed "tcp:<fqdn>" while publishing the BARE-name
resource its floor cluster resolves through -- keying off the map key there
would have retained an empty CLA under a name nothing references and left the
real one unpublished.

Two deviations from the accepted proposal, both recorded in it:

  - RequireProtocolDisjoint is NOT retired here. Its specified replacement
    asserts the two listings' port_protocols agree, and that field arrives in
    Phase 2; retiring now drops a working guard for nothing. Annotated in place
    as a convention rather than an invariant.
  - envoy_validate gains no case. Phase 1 changes no Envoy resource SHAPE, and
    the risk it introduces (duplicate EDS name) is invisible to
    `envoy --mode validate`, which does not resolve dynamic cluster refs. A
    gate that cannot fail is not a gate (#853).

Negative control: with both production files restored to main and the new test
file unchanged, exactly the two new tests fail and no existing test does --
Phase 1 is additive at the xDS contract.

Not yet a usable mixed service: the capture chain is still the portless /32 for
TCP-classified services, so a split service's HTTP side is still shadowed by
it. That is Phase 2, which adds the TCP mesh port.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit c2e2c2b into main Sep 21, 2026
22 checks passed
@bpalermo
bpalermo deleted the feat/037-phase1-cluster-identity-keys branch September 21, 2026 12:26
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