Repository navigation
feat(agent): key TCP cache entries by cluster identity (037 Phase 1) - #889
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 GAMMAcap_httpvhost; the TCP pass ran second and overwrote the same key with a vhost-lesstcp:trueentry. A service in both listings lost its cluster and both vhosts, and captured requests 503'd withno_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: tcpon 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:captureTCPClustersedgeTCPClusterscaptureUDPClustersedgeMeshClusterNameLockedTaking 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
edgeMeshClusterNameLockedreturns the h2meshFQDN— a clusterclustersEndpointsAndVhostsnever 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.
retainAbsentClustersLockednow 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 keyedtcp:<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:
RequireProtocolDisjointis not retired here. Its specified replacement asserts the two listings'port_protocolsagree, 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_validategains no case. Phase 1 changes no Envoy resource shape, and the risk it introduces — duplicate EDS name — is invisible toenvoy --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 thetcp:key).Negative control: with both production files restored to
mainand 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=raceon the touched package passes. Lint clean —buildTCPEndpointsLockedwas extracted because the additions pushedbuildTCPClustersLockedpast the gocognit threshold of 15.Not yet a usable mixed service
The capture chain is still the portless
/32for 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