Skip to content

fix(registrar): kubernetes backend releases an agent's write at the next sync, so every replica serves the Pod-derived endpoint (#1145) - #1152

Merged
bpalermo merged 2 commits into
mainfrom
fix/1145-k8s-overlay-release
Oct 3, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/1145-k8s-overlay-release

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Fixes #1145

What was wrong

On the kubernetes registry backend (the chart default) RegisterEndpoint / UnregisterEndpoint are no-ops. The write-behind queue still "flushed" each agent intent and kept it to shield the snapshot until a sync listing reflected it. For a register, Overlay released the op only when the listed endpoint was proto.Equal to the agent's.

On this backend the listing is built by podToEndpoint and the agent's endpoint by the CNI registration path. Those two never agree field for field. For example, the CNI path defaults an unset health-check-mode to EDS and this backend defaults it to UNSPECIFIED. So the op was never released. The receiving replica served the agent's version of the endpoint for the pod's whole lifetime, and every other replica served the Pod's. collectDueOps skips flushed ops before its max-age check, so nothing expired it either.

Fix: the Pod is the single source of truth on a derived backend

  • New optional capability registry.DerivedEndpoints. The kubernetes backend implements it: writes are ignored and every endpoint is derived at listing time.
  • For such a backend, WriteBehindQueue.Overlay(state, listedAt) releases an intent at the first sync whose listing started after the intent was received. That listing is taken as it is, so every replica serves the same Pod-derived endpoint.
  • An intent newer than the listing is still overlaid. This covers a sync that was already in flight when the RPC landed, so the snapshot-first apply is never regressed. The syncer passes the time it started listing.
  • etcd keeps its observed-back rule unchanged. etcd stores what was written, so proto.Equal is the right check there. A test pins this.

Why this shape and not the alternatives

  • Drop the overlay entirely for this backend. This would let a sync that listed before the RPC overwrite the receiving replica's just-applied mark. The result is a DRAINING → HEALTHY → DRAINING flap, broadcast to every watcher.
  • Release at flush time. Same problem: on this backend the flush is instantaneous.
  • Expire by max age. This leaves the replicas diverging for up to wbMaxAge (5 min).

"Released by the first listing newer than the intent" is the earliest point at which the shared state is guaranteed to include what the agent reacted to. It is also never earlier than that.

Interaction with #1144 (the next PR in this stack)

The overlay was the only thing holding the agent's phase-2 UNHEALTHY on the receiving replica. With this PR alone, the receiving replica lists the Pod's view again at its next sync, which is DRAINING while the pod is still Ready.

This is harmless for routing:

  • the pools were already closed at UNHEALTHY;
  • a DRAINING host gets no new selections.

The stacked PR for #1144 removes the gap: the Pod-derived view itself turns UNHEALTHY at the phase-2 moment on every replica.

Tests (red on main, green here)

  • //registrar/internal/server TestReplicasAgreeOnAnEndpointAnAgentRegisteredOnOne: two replicas over backend.New("kubernetes") and one fake API server, with a 50 ms poll. The agent registers on replica A an endpoint that differs from the pod-derived view only in HealthCheckMode (EDS, as the CNI path builds it). The test asserts both snapshots agree and equal the Pod view.
    • Red on main (Condition never satisfied: replica A still serves the agent's version of the endpoint, replica B the pod's). Green here, 15/15 runs under --config=race.
  • TestWriteBehindEtcdBackendStillShieldsUntilObserved: on the etcd backend (backend.New("etcd")), a flushed intent stays overlaid against a listing an hour newer that still differs. It is released only when the listing returns exactly what was written. The etcd path is unchanged.
  • TestWriteBehindDerivedBackendReleasesAtTheFirstNewerListing:
    • a register and an unregister are both overlaid onto a listing that predates them;
    • both are released by the first newer listing, which is then served as listed.
  • The existing TestPeerReplicaLearnsADrainWithoutWaitingForThePoll (registrar (kubernetes backend): a DRAINING mark reaches only the replica that received it — cross-replica propagation not measured #1124) still passes.

Checks

  • bazel test --config=race on //registrar/internal/server:all, //registrar/internal/cmd:all, //registry/...: pass.
  • make gazelle, make format-check, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.
  • Overlay needed a helper (overlayOp) to stay under the gocognit threshold.

Runbook: one paragraph in the #1124 section.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…ext sync, so every replica serves the Pod-derived endpoint (#1145)

The kubernetes backend ignores writes, and the write-behind overlay released
a flushed register only once a listing returned the agent's endpoint
proto.Equal. The Pod-derived listing never reproduces the CNI path's view
field for field (the health-check mode, for one), so the receiving replica
served the agent's version for the pod's lifetime while every other replica
served the Pod's.

A backend that implements the new registry.DerivedEndpoints capability now
releases an intent at the first sync whose listing started after the intent
was received; a listing that may predate it still gets the overlay, so the
snapshot-first apply is never regressed by a sync already in flight. The
etcd backend keeps its observed-back rule (pinned by a test).

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.

registrar (kubernetes backend): a flushed write-behind register op is never released, so two replicas can serve different versions of the same endpoint

1 participant