Skip to content

fix(registrar): kubernetes backend pushes a pod's drain to every replica, not only the one the agent's mark reached (#1124) - #1142

Merged
bpalermo merged 5 commits into
mainfrom
fix/1124-k8s-backend-drain-marks
Oct 3, 2026
Merged

bpalermo merged 5 commits into
mainfrom
fix/1124-k8s-backend-drain-marks

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Closes #1124

Finding: a drain mark sent to one replica never reached the other one

With the kubernetes registry backend (the chart default), the destination agent's DRAINING mark reached only the registrar replica it was sent to. The other replica kept listing the pod HEALTHY until the pod was gone. Sources attached to that replica kept sending it new requests for the whole preStop.

How it works today, from the code:

  • Writes are no-ops. RegisterEndpoint, UnregisterEndpoint and UnregisterEndpoints do nothing on this backend (registry/internal/k8s), so the mark is never written to anything shared. The receiving replica applies it to its own snapshot and broadcasts it (RegistrarServer.RegisterEndpoint). Its write-behind op "flushes" as a no-op, and Overlay keeps the mark on that replica only.
  • The peer replica learns only by polling. Its sync loop calls ListAllEndpoints every --sync-interval, 5 s by default. This backend implemented no ChangeNotifier, so the loop was poll-only.
  • Health came only from the Ready condition. podHealth read nothing else, and the kubelet keeps a terminating pod Ready through its preStop. So the poll kept returning HEALTHY until the containers stopped. A peer replica could not learn the mark before the pod left; the mark was effectively lost.

Measured on kind, before and after (e2e/drain-propagation.sh, cluster aether-1124, 2 registrar replicas, 15 s preStop, leg S)

registrar same replica: mark → last request cross replica: mark → last request requests > 1 s after the mark (cross)
main 0.224, 0.239, 0.255 s 14.938, 14.960, 15.002 s (the full preStop) 372, 334, 343
this PR 0.173, 0.238, 0.250, 0.250 s 0.459, 0.460, 0.518, 0.599 s 0, 0, 0, 0

There were no non-200 responses in either arm. The late requests landed on a pod that was still in its preStop, so they succeeded. With a shorter preStop, or an app that exits on SIGTERM, they would be the #1087/#1104 failures.

Fix: the peer replica gets a push, not a poll, as on etcd

  1. podHealth: a pod whose deletion has been requested lists as DRAINING while it is still Ready, and UNHEALTHY once it is not. The agent's termination watch marks the pod DRAINING on this same deletionTimestamp. Every replica reads it from the shared object, the Pod.
  2. The kubernetes backend implements registry.ChangeNotifier from a Pod informer on the manager cache. The informer is label-scoped to aether.io/managed=true and has managedFields stripped, because the registrar runs on a 64Mi limit and nothing else in it reads Pods. The handler signals only on changes that can alter an endpoint: deletion requested, Ready, phase, IP, node, ServiceAccount, annotations, or the managed label. The syncer therefore re-lists within its 200 ms debounce, as it does for the etcd watch. The poll stays as the backstop.
    • This is wired in the registrar only when --registry-backend=kubernetes.
    • The existing RBAC already grants watch on pods, so there is no chart change.
    • The syncer logs "supports change notifications" only when it really has a channel.

e2e/drain-propagation.sh changes:

  • REGISTRY_BACKEND=kubernetes.
  • Every run reports which registrar replica the source agent and the destination agent are on. It reads this from the node's conntrack table: the agent's flow to the Service VIP is DNATed to one replica. Registration and the watch share that one gRPC connection.
  • DRP_PLACEMENT (default alternate on this backend) restarts the source agent until it lands on the same replica (odd runs) or the other one (even runs).
  • Summaries are split same-replica / cross-replica.
  • New swap-registrar <tag> command.

Runbook: new paragraph in "A source keeps picking an endpoint seconds after its drain mark (#1103)".

Remaining difference between replicas

The agent's phase-2 UNHEALTHY still reaches only the receiving replica. That is the pool close about 1 s before SIGTERM. The other replicas see UNHEALTHY when the pod's Ready condition drops. New selections stop on both replicas at DRAINING, which is what this issue measures. I left that difference as is.

Evidence

Unit tests, each seen red first:

  • //registry/internal/k8s TestPodHealth_DeletionRequested and TestListAllEndpoints_TerminatingPodListsDraining. Red with the deletion branch disabled: expected: 3 (DRAINING) actual: 1 (HEALTHY).
  • //registry/internal/k8s TestChanges_SignalsWhenAManagedPodsEndpointCanChange (plus TestChanges_NilWithoutInformers). Red with the signal disabled.
  • //registrar/internal/server TestPeerReplicaLearnsADrainWithoutWaitingForThePoll. It runs two replicas through backend.New("kubernetes") with a 1 h poll. Replica A receives the agent's mark; replica B must list DRAINING within 1 s. Red with either half disabled: Condition never satisfied.

Checks:

  • bazel test and --config=race on //registry/internal/k8s:all, //registrar/internal/server:all, //registrar/internal/cmd:all, //registry/...: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits October 2, 2026 19:28
…ica, not only the one the agent's mark reached (#1124)

The kubernetes registry backend ignores writes, so the destination agent's
DRAINING mark lived only in the snapshot of the registrar replica it was
sent to. The other replica polled every 5 s and listed the pod HEALTHY for
its whole preStop (the kubelet keeps a terminating pod Ready), so sources
watching it kept sending new requests into the dying pod: 14.9 s mark ->
last request cross-replica on kind (the full 15 s preStop) vs 0.22-0.26 s
same-replica.

- k8s backend: a pod with a deletionTimestamp lists DRAINING while Ready,
  UNHEALTHY once not (the same signal the agent's termination watch uses).
- k8s backend implements registry.ChangeNotifier from a managed-pod
  informer (the manager cache, label-scoped, managedFields stripped), so
  the syncer re-lists at watch speed (200 ms debounce) like etcd.
- e2e/drain-propagation.sh: REGISTRY_BACKEND=kubernetes, reports which
  registrar replica each agent is on (node conntrack), steers leg S onto
  same/cross placement, splits the gap summary; swap-registrar.

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 DRAINING mark reaches only the replica that received it — cross-replica propagation not measured

1 participant