Skip to content

cni: persist the rendered aether entry so the re-assert loop can prime after a boot-time strip - #689

Merged
bpalermo merged 2 commits into
mainfrom
fix/680-durable-cni-entry
Sep 5, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/680-durable-cni-entry

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Follow-up to #681, which named this as residual case 3 and left it open on purpose.

The priming window

cni-install renders aether's chained plugin entry once per agent pod start and, until now, kept it in memory only. The re-assert loop never re-renders it: it primes Reasserter.entry from what it observes in the conflist on its first successful check, deliberately, because the netconf carries installer-time parameters (OTLP endpoint, redirect-all default, mesh-DNS DNAT target) the agent has no business re-deriving.

So a competing writer that strips the entry between cni-install's write and the loop's first check() leaves the loop with nothing cached:

aether is not chained in the active CNI conflist and no known-good entry was ever observed; cni-install must run

r.entry then stayed empty for the life of the agent process. Every later re-check found the entry missing and refused to repair. Because init containers do not re-run on a container restart, the only recovery was recreating the agent pod — a kubectl delete pod, by hand, per node.

It is a short window, but it is precisely the window a Talos bootstrap-manifest re-sync opens: flannel and aether-agent pods are recreated in the same event, and kube-flannel's unconditional cp -f can land after cni-install and before the first check (#645, the 2026-08-29 fleet-wide outage).

The design

Single writer, single artifact. cni-install writes the entry it just chained, on its own, to /etc/cni/net.d/.aether-cni-entry. The agent only ever reads it. It is written unconditionally — --cni-conflist-reassert governs the loop, not the artifact — atomically via common/file.AtomicWrite, with the same 0644 the conflist gets.

The entry is read back out of the merged conflist rather than from the pre-merge render, so the durable copy is byte-identical to what is actually chained (Insert drops the entry's own cniVersion; the enclosing conflist owns it) and a re-assert from the file reproduces the install exactly. A test pins that round trip.

The observed entry always wins. prime() is consulted only when len(r.entry) == 0 — an observed entry is proof of what the node actually accepted, and there is no second source of truth. A file that is missing or does not parse as a type: aether-cni plugin object is ignored with a WARN and the pre-existing fail-closed path is kept verbatim; the recovery input rewrites the node's live network config, so it is trusted only after it has been proven to be what it claims.

The shared contract (EntryFilename, EntryPath, ParseEntry) lives in cni/conflist alongside Insert/Parse, so the on-disk shape cannot drift between the one-shot installer and the loop — the same reason that package exists.

Why not .json — the proof

The issue proposed .aether-cni-entry.json on the grounds that conflist.ConfigFilenames only considers .conf/.conflist. That is true of our loader and of kubelet, but not of the runtime that actually reads this directory.

Every loader selects config files through libcni.ConfFiles(dir, extensions), which matches filepath.Ext against a caller-supplied list and does not skip dotfiles (libcni v1.3.0, libcni/conf.go:298). The lists in use:

Caller Extensions
conflist.ConfigFilenames (ours), kubelet {.conf, .conflist}
containerd go-cni {.conf, .conflist, .json}
libcni LoadConf (deprecated) {.conf, .json}

A .json file would be selected by containerd and loaded as a single-plugin network config — and a lone aether entry is a syntactically valid one (name: aether, type: aether-cni). So .json is not safe, and the file is named .aether-cni-entry instead: filepath.Ext(".aether-cni-entry") is ".aether-cni-entry", which matches none of the three lists. The leading dot additionally hides it from a plain ls.

This is pinned by tests in both packages that run the durable file past all three extension lists via real libcni.ConfFiles, plus ConfigFilenames/ActivePath, and assert it is never selected. It is also ignored by the loop's own isConfigEvent (same extension test), so writing it cannot trigger a re-check.

What changes for the #667 fail-closed path

Nothing about the mechanisms — the taint gate still refuses to remove the startup taint while unchained, the agent still reports NotReady past the dwell, the ghost sweep still withholds eviction, AetherCNIConflistUnchained still pages. What changes is what they are firing against: a state the node now heals by itself in one check (~2.5s), instead of one that structurally required an operator to delete a pod.

The unrepairable state is not gone, it is narrowed: it now means the durable file is also missing or unusable. The log line changed to match — "no known-good entry could be recovered" — and the docs/observability/ alert mirror quotes the new string. The deployed GitOps rule (bpalermo/k8s-talos-main#38) still quotes the old text; it is an annotation, not an expression, so nothing misfires, and it can be refreshed on the next pass over that repo.

Test matrix

cni/internal/install (TestWriteCNIConfigPersistsTheDurableEntry)

Case Asserted
written beside the conflist content is JSONEq to the entry actually chained, and is a valid ParseEntry input
mode 0644, matching the conflist
invisible to loaders not selected by ConfigFilenames, ActivePath, or libcni.ConfFiles under any of the three extension lists

cni/conflist (new entry_test.go)

  • EntryFilename extension matches none of the three lists, and is dot-prefixed
  • ParseEntry table: valid entry; not JSON; a JSON array; empty; someone else's plugin (flannel); a whole conflist rather than one entry; a non-string type
  • ParseEntry → Insert round trip reproduces the chained conflist byte for byte

agent/internal/cniconflist (TestPrimeFromDurableEntry)

Case Asserted
(a) unchained + durable file repaired in the same check, ChainStatus{Observed, Chained: true}, primed known-good entry from durable file logged; a later strip is still repaired after the file is deleted (priming lasts the process)
(b) unchained + no file conflist untouched, entry empty, unchained published — the pre-existing behaviour, byte for byte
(c) file present but garbage (4 shapes) ignored, fail-closed path, WARN the durable aether entry is unusable
(d) file present and a live entry observed the observed entry wins; the repaired conflist carries the observed socket path and not the durable one

Existing reassert_test.go / state_test.go / readyz_test.go cases are unchanged and pass. Helpers (flannelOnly, chained(t), writeConf, isChained, pluginTypes) reused as-is.

bazel test --test_output=errors //cni/... //agent/internal/cniconflist/... //agent/internal/node/...
  10 tests, all PASSED
bazel test //website:site_test                    PASSED   (docs build)
bazel build --config=ci //cni/... //agent/internal/cniconflist/... //agent/internal/cni/server:server //agent/internal/node/...
  clean (gocognit included; no new helper scores above the threshold)

Talos validation recipe

The bug is about an agent process restart, not a pod restart — recreating the pod re-runs cni-install and proves nothing. The window is reproduced by stripping the conflist and killing the agent process inside the loop's 750ms settle delay, so the old process never repairs it and the new one starts with nothing observed and a stripped file.

NODE=talos-main-worker-01
POD=$(kubectl -n aether get pod -l app.kubernetes.io/name=aether-agent \
        --field-selector spec.nodeName=$NODE -o jsonpath='{.items[0].metadata.name}')

# 0. The durable entry must be on the node (this PR's cni-install has run there).
kubectl debug node/$NODE -q --image=busybox -- ls -la /host/etc/cni/net.d/
#    -> .aether-cni-entry   10-flannel.conflist

# 1. Open the priming window: strip aether from the live conflist and kill the
#    agent process in one shot. The container restarts in place — the init
#    container does NOT re-run, which is the whole point.
kubectl debug node/$NODE -q --image=alpine --profile=sysadmin -- sh -c '
  apk add -q --no-cache jq &&
  jq "del(.plugins[] | select(.type == \"aether-cni\"))" \
     /host/etc/cni/net.d/10-flannel.conflist > /tmp/stripped &&
  cp /tmp/stripped /host/etc/cni/net.d/10-flannel.conflist &&
  pkill -f "agent --node-name"'

# 2. Expect, on the restarted container, within ~2.5s of its first check:
kubectl -n aether logs $POD -c agent | \
  grep -E "primed known-good entry from durable file|re-asserted the aether entry"

kubectl debug node/$NODE -q --image=busybox -- \
  grep -c aether-cni /host/etc/cni/net.d/10-flannel.conflist        # 1

# 3. No taint, agent Ready — the #667 gates never engage.
kubectl get node $NODE -o jsonpath='{.spec.taints}'                 # no aether.io/agent-not-ready
kubectl -n aether get pod $POD \
  -o jsonpath='{.status.containerStatuses[?(@.name=="agent")].ready}'   # true

# 4. Negative control: same sequence with the durable file removed first
#    (rm /host/etc/cni/net.d/.aether-cni-entry) must reproduce the OLD behaviour —
#    "no durable aether entry on disk to prime from", conflist left stripped,
#    taint held, agent NotReady after the 3-minute dwell. Recover by deleting the
#    agent pod.

kubectl debug node/... runs with hostPID, so pkill reaches the agent in its container; --profile=sysadmin is what allows signalling it. Before this PR, step 2 logs no known-good entry was ever observed instead and the node stays broken until the pod is deleted.

Not included

  • No chart change, no Chart.yaml bump. Both the cni-install init container and the agent container already mount the same host /etc/cni/net.d (cni-conf-dir) read-write — the init container writes the file, the agent reads it out of the directory it already watches.
  • No new flags (proposal 031). The kill switch is still --cni-conflist-reassert, and it governs the loop, not the artifact.

Closes #680

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 5, 2026 09:56
…r can prime after a boot-time strip (#680)

cni-install renders aether's chained plugin entry once per agent POD start and
kept it in memory only. The re-assert loop primes its known-good entry from what
it OBSERVES on disk — deliberately, since the netconf carries installer-time
parameters the agent has no business re-deriving — so a competing writer that
strips the conflist between cni-install's write and the loop's first check left
the loop with nothing to re-append for the life of the agent PROCESS. Init
containers do not re-run on a container restart, so the node stayed unrepairable
(taint held, agent NotReady since #667) until the pod itself was recreated.

cni-install now also writes the entry it just chained, alone, to
/etc/cni/net.d/.aether-cni-entry, and the loop primes from that file when — and
only when — it has never observed a healthy one. An observed entry still wins:
it is proof of what the node actually accepted. cni-install stays the file's
single writer; the agent only reads it.

The name matters: every CNI config loader selects files by filepath.Ext against
an extension list — {.conf,.conflist} for kubelet and for us,
{.conf,.conflist,.json} for containerd's go-cni, {.conf,.json} for libcni's
deprecated LoadConf — and ".aether-cni-entry" matches none of them, so a lone
aether plugin object can never be loaded as a network of its own. A ".json"
suffix would NOT have been safe.

No chart change: both the cni-install init container and the agent already mount
the same host /etc/cni/net.d read-write.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 95b158e into main Sep 5, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/680-durable-cni-entry branch September 5, 2026 13:13
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]>
bpalermo added a commit that referenced this pull request Sep 5, 2026
…d tag (#692) (#713)

* fix(ci): serialise publishes and give the aether chart a commit-pinned tag (#692)

Two `publish` runs for consecutive merges to `main` raced on the same chart
version tag and the older build won: 0.92.1 was pushed by the newer commit
(95b158e) at 13:15:59Z and overwritten by the older one (77a7d45) four seconds
later, so the 13:16:27Z deploy silently shipped without #689.

Two independent causes, both fixed:

* `publish.yaml` had no `concurrency` group, so runs for `main` overlapped.
  Added `group: publish-main, cancel-in-progress: false` — a publish is not a
  redundant check to supersede; cancelling one mid-push would leave images
  pushed and the chart not.

  `proxy-release.yml` gets the same treatment for the same class of bug: its
  `bump-chart` job rewrites `charts/aether/values.yaml` on top of whatever
  `main` is at checkout and force-pushes the single rolling
  `chore/proxy-image-bump` branch, so overlapping runs drop one run's image pin.

  `main.yaml` (main-post-merge) deliberately gets none, and now says so: it
  writes no shared state, and serialising it would delay — or, via queued-run
  eviction, skip — the detection it exists to provide.

* The `aether` chart was published only under its bare `Chart.yaml` version, a
  tag that does not change per commit. It is now also published as
  `charts/aether:<X.Y.Z>-<full git sha>`, the scheme crds/prober/udsecho
  already use, via a second packaging of the same chart whose `Chart.yaml` is
  *derived* from the first (a genrule appends `-{GIT_COMMIT}`), so the two tags
  can never disagree about X.Y.Z. Only the chart is pushed for the commit tag —
  the images went up by digest with the bare push. The bare tag stays, for Flux
  and the documented deploy procedure, and is now safe because of the
  serialisation.

The documented deploy procedure (docs/runbook.md, docs/getting-started.md) now
pins the commit tag and, after `helm upgrade`, asserts that
`helm get metadata -n aether-system aether -o json | jq -r .appVersion`
contains the intended commit, failing otherwise — the only check that catches a
chart tag serving a different build than the one asked for. Substring, not
equality: appVersion is `git describe --tags --always --long --dirty
--abbrev=40`, so the sha can carry a `v1.2.3-N-g` prefix or a `-dirty` suffix.

Validated: `bazel build --stamp //charts/aether:aether //charts/aether:aether_commit`
produces `version: 0.92.4` and `version: 0.92.4-<40-char sha>` with the same
appVersion; `bazel test //charts/...` (9/9, including the new
`aether_commit_lint_test`) and `--config=lint //charts/...` pass;
`scripts/check-chart-version-bump.sh` passes on the 0.92.3 -> 0.92.4 bump; all
three edited workflows parse as YAML (actionlint not installed locally).

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

* chore(chart): bump aether chart to 0.92.5 after #711 took 0.92.4 (#692)

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]>
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: persist cni-install's rendered entry so the re-assert loop can prime from disk

1 participant