Skip to content

fix(agent): self-heal pods left unmeshed by the reboot CNI boot race - #641

Merged
bpalermo merged 3 commits into
mainfrom
fix/640-cni-boot-race-self-heal
Aug 23, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/640-cni-boot-race-self-heal

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Summary

Fixes #640 (scope A + the metric half of C from the issue).

After a whole-node reboot, kubelet recreates every bound pod's sandbox before cni-install restores the chained conflist, so pre-existing pods come up on the base CNI with no mesh registration — Running and Ready per Kubernetes, invisible to the mesh. The 2026-08-23 power failure turned this into a ~2h04m total mesh data-plane outage ended only by a manual roll.

The deadlock

Storage still holds each pod's pre-reboot entry (same namespace/name, dead netns), which deadlocks the two existing self-heal guards:

The fix

A third ghost-sweep classification: an entry whose netns has been gone for 3 consecutive passes while the API reports its pod Running with an IP:

coverage meaning action
a fresher live entry exists for the same pod superseded leftover of a missed CNI DEL prune just the entry (kills the unbounded warn spam)
no live entry covers the pod pod is running outside the mesh (the boot race) evict (Eviction API, PDB-respecting) → sandbox recreation → fresh CNI ADD

Guardrails: evictions share one per-pass budget (2/node/pass) with the #567 lost-ADD path, honor the #566 mass-breaker interlock, log + record a AetherCNIStaleRegistration Event on the pod, and reset streaks on any state change. With the 60s sweep interval a rebooted 13-pod node self-heals in ~7 minutes instead of waiting for a human.

Observability (issue scope C, metric half)

First commit is unrelated formatter drift from the module rename (import-group ordering in 6 files), kept separate for a clean second commit.

Test plan

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits August 23, 2026 11:43
Formatter drift left by the aethermesh.dev rename (#632): gofumpt now sorts
the module's own imports into a different group position in these files.
No code changes.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…640)

After a node reboot, kubelet recreates every bound pod's sandbox before
cni-install restores the chained conflist, so pre-existing pods come up on
the base CNI with no mesh registration. Storage still holds each pod's
pre-reboot entry (same namespace/name, dead netns), which deadlocked the
two existing guards: the #566 cross-check refuses to prune a Running pod,
and the #567 missing-storage self-heal never fires because the
namespace/name IS in storage. Result on 2026-08-23: a ~2h total mesh
outage ended only by a manual roll.

Break the deadlock with a third classification in the ghost sweep — an
entry whose netns has been gone for 3 consecutive passes while the API
reports its pod Running with an IP:

- covered by a fresher live entry: the old entry is a superseded leftover
  of a missed CNI DEL; prune just the entry (also ends the previously
  unbounded per-minute "not pruning" warn spam for this case);
- not covered: the pod is running outside the mesh; evict it (Eviction
  API, PDB-respecting) so sandbox recreation re-runs CNI ADD.

Evictions share one per-pass budget with the #567 lost-ADD path and honor
the #566 breaker interlock, so recovery stays gradual (2/node/min) and a
correlated netns-stat failure still never triggers mass action.

Also exports aether.agent.ghost_sweep.unmeshed_pods, a gauge of Running
mesh-managed pods currently outside the mesh (recorded every pass, zero
included), so this condition can page directly instead of via downstream
DNS symptoms; plus a stale_running_evictions counter and a per-pass
aether.sweep.stale_running span attribute.

Closes #640

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…eshold

Extract accrueNetnsFailStreak and classifyDeadNetnsRunningEntry; no
behavior change (31 -> under 15).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit ac943e3 into main Aug 23, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/640-cni-boot-race-self-heal branch August 23, 2026 14:57
bpalermo added a commit that referenced this pull request Aug 30, 2026
…writer strips it (#645) (#650)

* refactor(cni): extract the conflist mutation into a shared package

The aether-cni entry is appended to another CNI's conflist by exactly one
component today — the cni-install init container — and the agent cannot
reuse that logic: cni/internal/install is internal to //cni.

Move the mutation (insert/replace the aether entry, kubelet's config-file
resolution, the marshalling shape) into the importable aethermesh.dev/cni/conflist,
so the upcoming agent-side re-assert loop (#645) shares ONE implementation
with the installer and the on-disk shape can never diverge between them.
Adds the parse-side helpers that loop needs (AetherEntry, HasAether,
HasBasePlugin, ActivePath).

No behavior change: the installer keeps writing exactly what it wrote, and
the moved tests move with it. cni/internal/util/plugin.go had no other
caller and goes away; the /etc/cni/net.d path joins common/constants next
to the registry path, as both the CNI and the agent now need it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* fix(agent): re-assert the aether-cni conflist entry when a competing writer strips it (#645)

cni-install appends aether's chained plugin entry to the primary CNI's
conflist ONCE, from the agent pod's init container. kube-flannel's init
container does an unconditional `cp -f /etc/kube-flannel/cni-conf.json
/etc/cni/net.d/10-flannel.conflist` on every flannel pod recreation — which
Talos triggers on every bootstrap-manifest re-sync (boot, apply-config, k8s
upgrade). aether appends once, flannel overwrites forever, so aether always
loses eventually: on 2026-08-29 a manifest re-sync 37 minutes after boot
stripped the entry on all 5 workers, and every pod started afterwards ran
outside the mesh. Workload rolls could not fix it (a replacement pod just
goes through plain flannel again) and #641's eviction self-heal is actively
counterproductive there.

Add a re-assert loop to the long-running agent: a controller-runtime
runnable watching the CNI config dir with fsnotify (settle delay so a
partial in-place write is never parsed) plus a 60s re-check for events
fsnotify never delivers. When the aether entry is missing from the conflist
kubelet actually uses, it is re-appended via the shared cni/conflist
mutation and written atomically (tmp+rename).

Guardrails — the loop only ever repairs, never creates:
  - the file must exist, parse as a conflist, and still carry a primary CNI
    plugin (aether chains ONTO someone else's network config; boot ordering
    stays cni-install's job),
  - the entry re-appended is the last one OBSERVED in the file, so the
    installer-time netconf parameters (OTLP endpoint, redirect-all default,
    mesh-DNS DNAT target) are never re-derived by the agent; cni-install
    re-renders them at every agent pod start, priming the cache on the first
    check of every agent lifetime,
  - a broken watch degrades to periodic re-checks and never fails the
    manager (which would take the CNI socket down with it).

Observability: aether.agent.cni_conflist.reasserts counts every repair (each
one is a window in which new pods were created unmeshed), and the
aether.agent.cni_conflist.chained gauge is recorded on every check, zero
included, so 0 is the alertable "pods on this node are bypassing the mesh"
state — same recording philosophy as the #641 unmeshed_pods gauge.

Gated by --cni-conflist-reassert, default ON (it is a safety net), with the
matching agent.cniConflistReassert chart value. The agent container now
mounts /etc/cni/net.d read-write; the cni-install init container already
mounted it for the one-shot append.

Fix shape (1) from #645 — a standalone 05-aether.conflist with no competing
writer — remains open; this is shape (2) + (3).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* fix(agent): survive a dead CNI config watcher without spinning

fsnotify closes both of its channels when the watcher dies (a lost inotify
instance, a Close from under us). A closed channel is always ready, so the
select would take the event branch forever on zero-valued events and burn a
core. Drop the channels to nil on close — nil never fires — and fall back to
the periodic re-check, which is what the loop already does when the watch
could not be established in the first place.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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.

CNI boot race: pods restarted before cni-install come up unregistered — no self-heal, total mesh outage after node reboot

1 participant