Repository navigation
fix(cni): guarantee the local storage delete on CNI DEL (#261) - #262
Merged
Merged
Conversation
RemovePod removed local storage LAST, gated behind a fatal, request-context-bound UnregisterEndpoints (and the listener removal). So a canceled request ctx (the plugin's del timeout, a kubelet cancel, or agent SIGTERM — the xDS server force-stops in-flight RPCs after ShutdownTimeout) OR a transient registrar outage (observed during a registrar roll: UnregisterEndpoints fails with "context canceled") made the handler return BEFORE storage.RemoveResource — leaving a ghost storage entry whose netns pin lingers (so the #245 stale-netns guard can't prune it) and whose listener is re-emitted on agent restart against a dead netns. This is the prevention root cause behind the prober/edge connection_error degradation. Make DEL mirror AddPod (which stores first + treats registration as best-effort): - Run the removal on a detached context (context.WithoutCancel) so request-ctx cancellation can't skip it. - Remove LOCAL STORAGE FIRST — the authoritative local truth. It's the only fatal error (kubelet retries the DEL). Once gone, the liveness loop can't resurrect the endpoint and the ghost sweep deregisters whatever is left in the registry. - Listener removal + endpoint deregistration are now BEST-EFFORT (logged, not fatal); the snapshot rebuild / restart drops the listener and the ghost sweep reconciles the registry. The deregister is bounded (unregisterTimeout) so it can't hang the DEL when the registrar is rolling. Tests: the old "unregister failure returns error" case now asserts the DEL is tolerated (SUCCESS); new TestRemovePodDurableDeleteOnCanceledCtx proves storage is still removed with an already-canceled ctx AND a down registrar. This is the prevention layer; the storage<->pods reconcile (cure) and the startup taint (cold-start) are separate PRs on #261. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S
bpalermo
added a commit
that referenced
this pull request
Jun 22, 2026
…sue #261) (#264) The ghost sweep reconciled the registry against local storage but never reconciled local storage against the node's real pods, so two desync classes went uncured (talos worker-01, 2026-06-22): - Orphan ghost: a missed CNI DEL that left the netns bind-mount pin behind. netnsExists() stats the lingering pin and reports present, so the existing stale-prune never removed it; the agent kept emitting a listener bound to a dead netns (prober-vhbp8) — a connection sink and a latent #245 segfault. - Missing pod: a live, mesh-managed pod with no storage entry (a lost CNI ADD) that therefore had no listener and 100% connection_error (prober-k7vsm), and never self-healed. The agent's manager cache is already scoped to spec.nodeName=<this node>, so listing the node's pods is local and cheap (no new RBAC — it already has pods get/list/watch). The sweep now: - Prunes a stored pod when EITHER its netns is gone (existing) OR its Kubernetes pod no longer exists — by pod identity, regardless of a lingering pin. The pruned pod's registry endpoint then falls through to ghost deregistration as before. If the pod list fails we skip prune-by-absence (an empty list would nuke every entry) but still run the netns prune. - Surfaces live, Running, mesh-managed pods that storage has no entry for: the agent can't synthesize the CNI data to self-heal, so it emits a metric + warning (the pod must be rolled) instead of silently serving no listener. New metrics: ghost_sweep.orphans_pruned, ghost_sweep.missing_storage. Tests: TestSweepPrunesOrphanedPods (lingering-pin orphan pruned + ghost-deregistered, live pod kept) and TestIsMeshManagedK8sPod; existing sweep tests keep a nil k8sClient and skip the pod reconcile via a defensive guard. This is the cure layer; the guaranteed-delete reorder (#262) is the prevention and the startup taint (#263) closes the cold-start window. Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
The prevention layer for #261 (ghost storage entries → dead-netns listeners →
connection_error).Root cause
RemovePodremoved local storage last, gated behind a fatal, request-ctx-boundUnregisterEndpoints(and the listener removal). So when the request ctx is canceled — the plugin's del timeout, a kubelet cancel, or agent SIGTERM (the xDS server force-Stop()s in-flight RPCs afterShutdownTimeout) — or the registrar is briefly unavailable (we observedUnregisterEndpointsfailcontext canceledduring a registrar roll), the handler returns beforestorage.RemoveResource. That leaves a ghost storage entry whose netns pin lingers (so the #245 stale-netns guard can't prune it) and whose listener is re-emitted against a dead netns on agent restart.AddPodis already robust the right way: it stores first and treatsRegisterEndpointas best-effort.RemovePodwas the asymmetric opposite.Fix
Make DEL mirror ADD:
context.WithoutCancel) so request-ctx cancellation can't skip the removal.unregisterTimeout) so a rolling registrar can't hang the DEL.Why this is safe (the reconcile question)
The ghost sweep already deregisters any registry endpoint with no live local pod (every 60s + on registrar reconnect), with local storage as the source of truth. So removing storage-first + best-effort unregister self-heals: a failed unregister leaves an orphan that the next sweep (this agent, or its successor after SIGTERM) deregisters. No resurrection — the sweep only re-registers live local pods, and this one is gone.
Tests
unregister failure returns errorcase now asserts the DEL is tolerated (SUCCESS).TestRemovePodDurableDeleteOnCanceledCtx: with an already-canceled ctx AND a down registrar, the DEL succeeds and local storage is still removed.Code-only;
bazel build //...green; cni-server tests pass. The reconcile (cure) and startup taint (cold-start) are separate PRs on #261.