Skip to content

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

Merged
bpalermo merged 3 commits into
mainfrom
fix/645-conflist-reassert
Aug 30, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/645-conflist-reassert

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Fixes shapes (2) and (3) of #645.

Mechanism

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. aether appends once, flannel overwrites on every re-sync, so aether always loses eventually — and when it does, the plugin binary stays on disk but is unchained: no CNI ADD ever reaches the agent and every subsequently-started pod runs outside the mesh.

This PR adds a re-assert loop to the long-running agent (agent/internal/cniconflist), registered as a controller-runtime runnable alongside the other agent runnables:

  • fsnotify watch on the CNI config directory, with a 750ms settle delay — a writer doing an in-place cp -f walks the file through a truncated state that would parse as garbage, and the delay also collapses one rewrite's event burst into a single check. Events for temp files (atomic writers' .tmp-ish names) and chmod-only ops are filtered out.
  • 60s periodic re-check as belt-and-suspenders for events fsnotify never delivers (watch dropped, mount replaced, an event lost while the agent was restarting).
  • On detecting the entry missing from the conflist kubelet actually uses (lexicographically first usable config, same rule the installer follows), it is re-appended through the shared mutation and written atomically (tmp+rename, common/file.AtomicWrite, 0644).

The mutation is not forked: the first commit extracts it from cni/internal/install (which the agent cannot import — it is internal to //cni) into the importable aethermesh.dev/cni/conflist, now used by both the installer and the agent. The installer keeps writing byte-for-byte what it wrote before; its moved tests moved with it.

Incident reference

2026-08-29, third power-blip incident — but not the boot race (#640). Talos re-applied its bundled bootstrap manifests (node-fetch field manager) at 19:01:09Z, ~37 min after apiserver came up, rolling all 6 kube-flannel pods (restartCount 0, fresh pods). Each node's conflist mtime matched its new flannel pod's init container to the second; plugins=[flannel, portmap] on all 5 workers. Total mesh outage. Workload rolls were proven useless (39 pods rolled, SLI stayed at 100% failure) — recovery required rolling ds/aether-agent to re-run cni-install. Talos re-syncs those manifests on boot, on talosctl apply-config, and on Kubernetes upgrades, so this is not power-event-specific.

Guardrails

The loop only ever repairs, never creates:

  • the active config must exist, parse as a conflist, and still carry a primary CNI plugin (any non-aether entry — flannel here). aether chains ONTO someone else's network config; if there is no base plugin, or no usable conflist at all, the directory is left untouched and boot ordering stays cni-install's job. Invalid JSON → warn, no write.
  • the entry re-appended is the last one observed in the file, not one the agent re-renders. The netconf carries installer-time parameters (OTLP endpoint, redirect-all default, mesh-DNS DNAT target, host IP) the agent has no business re-deriving — and since cni-install is the agent pod's own init container, it re-renders and re-appends the entry at every agent start, priming the cache on the first check of every agent lifetime. With no known-good entry ever observed, the loop warns and does nothing.
  • a watch that cannot be established degrades to periodic re-checks; Start never returns an error, because failing the manager would take the CNI socket down with it. NeedLeaderElection() == false — every node's conflist is that node's own.

Gated by --cni-conflist-reassert, default ON (safety net, same posture as the other default-on kill switches), 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); charts/aether/Chart.yaml bumped 0.91.1 → 0.91.2.

Metrics + the alert to come

  • aether.agent.cni_conflist.reasserts (counter) — every repair is a window in which new pods were created unmeshed. INFO log on each; WARN on any failed re-assert.
  • aether.agent.cni_conflist.chained (gauge) — 1 when aether's entry is present in the active conflist, 0 when missing or when no usable conflist exists. Recorded on every check tick, zero included, so it clears the instant the entry is back — same recording philosophy as the fix(agent): self-heal pods left unmeshed by the reboot CNI boot race #641 unmeshed_pods gauge.

The gauge is the detection fix the incident asked for: nothing watched the conflist, and the failure surfaced only as downstream symptoms (prober SLI 100% failure, ghost-sweep "live mesh pod missing from local storage" warnings). A GitOps-side alert on aether_agent_cni_conflist_chained == 0 (with a for: window so a repaired blip doesn't page) is the follow-up, to be wired like AetherUnmeshedPods in bpalermo/k8s-talos-main — not in this repo.

Test evidence

  • cni/conflist: the moved insert/parse/filename tests plus new coverage for the parse-side helpers, including a round-trip assertion that an entry recovered from a chained conflist re-inserts byte-identically to what cni-install writes.
  • agent/internal/cniconflist: table-driven check tests — missing entry → re-appended; already chained → byte-identical no-op; invalid JSON → untouched; no primary CNI plugin → untouched; missing entry with no known-good entry → untouched; absent dir and empty dir → no-op and nothing created; only the active conflist is repaired while other configs in the dir are left alone; and priming (chained file observed → strip → restored to exactly the installer's bytes).
  • End-to-end over a real fsnotify watcher in a temp dir (TestStartConverges): a flannel-only conflist is written over the chained one mid-watch and the file converges back to chained, with the periodic re-check set to 1h so only the watcher can be what fixed it. Plus TestStartWithoutConflistDir for the degraded path.
  • bazel test //agent/... //cni/... green (30 + 9 targets); the new test passed --runs_per_test=20. bazel build //... green, bazel build --config=ci green on the touched packages, --config=lint clean (gocognit included), make format-check clean, helm template renders the flag and the read-write mount.

Still open

Fix shape (1) of #645 — a standalone 05-aether.conflist with no competing writer — remains open and is tracked there. It needs the aether conflist to become self-sufficient (delegate/chain to flannel from aether's own file), which is a design change; this PR is the pragmatic first step that closes the window to seconds and makes the condition alertable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits August 30, 2026 16:57
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
…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
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
@bpalermo

Copy link
Copy Markdown
Owner Author

Follow-up commit 0c176f1: fsnotify closes both of its channels when the watcher dies (lost inotify instance, close from under us), and a closed channel is always ready — the select would have taken the event branch forever on zero-valued events and burned a core. The channels are now dropped to nil on close (nil never fires) and the loop falls back to the periodic re-check, the same degraded mode it already uses when the watch cannot be established at all.

@bpalermo
bpalermo merged commit aaae36d into main Aug 30, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/645-conflist-reassert branch August 30, 2026 20:07
bpalermo added a commit that referenced this pull request Sep 5, 2026
…#710)

`cni/internal/install` logged half the install through `ctrl.Log` —
controller-runtime's global logger — but nothing in `cni/` ever calls
`ctrl.SetLogger`, so controller-runtime discarded every one of those
records. On talos-main the `cni-install` init container therefore ended
at `CNI binaries installed`: the pre-existing `Wrote CNI config`
confirmation (the #645/#650 class signal that aether was chained into
the node's conflist) and #689's `Wrote the durable aether CNI entry`,
plus both of its `Error` paths, were silent in production.

Take the issue's preferred fix: drop `ctrl.Log` and thread the
installer's own logger down. The installer now holds a `*slog.Logger`
instead of a logr bridge — the cni-install command already built the
slog logger and only bridged it for controller-runtime's sake — and
`cniconfig.go` and `cni/internal/util`'s file watcher take it as a
parameter. controller-runtime is gone from all three packages;
`cni/cmd/cni-install/main.go` keeps `ctrl.SetupSignalHandler`, which
does not log.

Messages and attribute keys are unchanged so operator greps still
match. The two `Info` calls whose key/value list was malformed (a
dangling value, and a bare filepath) get their `filepath`/`alternate`
keys so slog does not render `!BADKEY`; logr's error argument becomes
the repo-standard `"error", err` pair.

Tests capture the installer's logger through a slog JSON handler and
assert `Wrote CNI config` and `Wrote the durable aether CNI entry` are
emitted at INFO with their filepath, and that both durable-entry
failure paths (unwritable location, no aether entry to extract) log at
ERROR — that ERROR line is the operator's only signal, since the
durable write is deliberately swallowed.

Verified end to end by running the built binary against a scratch
conflist: six lines now, including the two that were missing.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[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.

1 participant