Skip to content

fix(init): write CNI configuration files only when their content changes - #203

Merged
woehrl01 merged 1 commit into
woehrl01:mainfrom
crazyproger:fix/skip-unchanged-cni-config
Nov 17, 2026
Merged

woehrl01 merged 1 commit into
woehrl01:mainfrom
crazyproger:fix/skip-unchanged-cni-config

Conversation

@crazyproger

Copy link
Copy Markdown
Contributor

Problem

cni-init rewrites 20-pod-pacemaker.conflist on every start of init-cni and cni-config-sync, even when the content is the same (generateCNIConfig ends with an unconditional os.WriteFile). On a node where pods are waiting for a slot, that write turns the node NotReady for about maxWaitTimeInSeconds − 30 s:

  • containerd reloads the CNI configuration on every Write/Rename event in the configuration directory, only Create and Chmod are ignored (cni_conf_syncer.go L94–L105, v2.3.7);
  • the reload, libcni.Load, takes go-cni's write lock (cni.go L123–L125, v1.1.13) and waits for every Setup in flight, which holds the read lock for the whole CNI ADD (L167–L169); with pod-pacemaker in the chain an ADD can wait up to maxWaitTimeInSeconds for a slot;
  • while the writer waits, new readers block too (sync.RWMutex), so the CRI Status call that reads the network status through libcni.Status (L140–L142) hangs, and kubelet reports container runtime is down and sets the node NotReady. The reload gets the lock only after the ADDs in flight return; in our runs the node stayed NotReady for 3 min 8 s – 3 min 12 s with maxWaitTimeInSeconds: 220, 1 min 30 s with 120, 26 s with 60 and 8 s with 40.

A restart of the DaemonSet pod (a rollout, an eviction, a fresh node where the pod starts while the first workload pods already wait) is enough to trigger it.

Fix

generateCNIConfig writes through a new writeFileIfChanged: an unchanged file is not touched; a changed one is written to <name>.tmp and renamed over it, as mergeTwoConfigs already did. mergeTwoConfigs now uses the same helper; its behaviour does not change.

A real configuration change (other flags, an update of the primary CNI config) still writes and still makes containerd reload while ADDs wait; that part is in containerd/go-cni and is not addressed here.

Tests

  • TestGenerateCNIConfigWritesOnlyOnChange in cmd/init/main_test.go: the first generation writes, a second one with the same flags leaves the file and its mtime alone, a flag change rewrites it and leaves no .tmp behind.
  • EKS 1.35 (kubelet v1.35.9, containerd 2.3.7, Amazon VPC CNI), one t3a.large node, maxConcurrent 2, maxWaitTimeInSeconds: 220: 14 pods scaled up at once, each with a 60 s startupProbe; 15 s later, with 2 pods in slots and 12 waiting in CNI ADD, the pod-pacemaker pod on the node was deleted:
    • v1.8.6: node NotReady (container runtime is down) for 3 min 8 s, 16 FailedCreatePodSandBox (12 slot timeouts, 4 VPC CNI failed to assign an IP address), 562 s until all pods were Ready;
    • this branch: the node stayed Ready, 8 FailedCreatePodSandBox (4 slot timeouts at the tail of the queue, 4 VPC CNI failed to assign an IP address), 397 s until all pods were Ready.

Every write in the CNI configuration directory makes containerd reload the network configuration
(cni_conf_syncer.go). go-cni takes its write lock for the reload, and since go-cni v1.1.11 Setup holds
the read lock for the whole ADD, so the reload waits for every pod network setup in flight. With this
plugin a setup can wait up to maxWaitTimeInSeconds for a slot. Meanwhile the CRI Status call, which
takes the same read lock behind the pending writer, blocks, and after 30 s kubelet reports
"container runtime is down" and the node turns NotReady until the waiting setups return.

The init container rewrote 20-pod-pacemaker.conflist on every start, also as the cni-config-sync
sidecar, while the merged file was already written only on change. On a fresh node the sidecar starts
while DaemonSet pods wait for the daemon, right before the startup taint is lifted and many pods
queue for slots: the node went NotReady for 3.5 min on EKS 1.35 (containerd 2.3, go-cni 1.1.13).

Both files now go through writeFileIfChanged: an unchanged file is not touched, a changed one is
written to a temporary name and renamed over it.
@woehrl01
woehrl01 merged commit cfba245 into woehrl01:main Nov 17, 2026
1 check passed
@crazyproger
crazyproger deleted the fix/skip-unchanged-cni-config branch November 19, 2026 07:59
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.

2 participants