Repository navigation
fix(registrar): kubernetes backend pushes a pod's drain to every replica, not only the one the agent's mark reached (#1124) - #1142
Merged
Conversation
…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
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This was referenced Oct 2, 2026
This was referenced Oct 3, 2026
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.
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:
RegisterEndpoint,UnregisterEndpointandUnregisterEndpointsdo 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, andOverlaykeeps the mark on that replica only.ListAllEndpointsevery--sync-interval, 5 s by default. This backend implemented noChangeNotifier, so the loop was poll-only.podHealthread 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, clusteraether-1124, 2 registrar replicas, 15 s preStop, leg S)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
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 samedeletionTimestamp. Every replica reads it from the shared object, the Pod.registry.ChangeNotifierfrom a Pod informer on the manager cache. The informer is label-scoped toaether.io/managed=trueand 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.--registry-backend=kubernetes.watchon pods, so there is no chart change.e2e/drain-propagation.shchanges:REGISTRY_BACKEND=kubernetes.DRP_PLACEMENT(defaultalternateon this backend) restarts the source agent until it lands on the same replica (odd runs) or the other one (even runs).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/k8sTestPodHealth_DeletionRequestedandTestListAllEndpoints_TerminatingPodListsDraining. Red with the deletion branch disabled:expected: 3 (DRAINING) actual: 1 (HEALTHY).//registry/internal/k8sTestChanges_SignalsWhenAManagedPodsEndpointCanChange(plusTestChanges_NilWithoutInformers). Red with the signal disabled.//registrar/internal/serverTestPeerReplicaLearnsADrainWithoutWaitingForThePoll. It runs two replicas throughbackend.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 testand--config=raceon//registry/internal/k8s:all,//registrar/internal/server:all,//registrar/internal/cmd:all,//registry/...: pass.make gazelle,make format, andbazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr