Repository navigation
fix(init): write CNI configuration files only when their content changes - #203
Merged
woehrl01 merged 1 commit intoNov 17, 2026
Merged
Conversation
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
approved these changes
Nov 17, 2026
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.
Problem
cni-initrewrites20-pod-pacemaker.confliston every start ofinit-cniandcni-config-sync, even when the content is the same (generateCNIConfigends with an unconditionalos.WriteFile). On a node where pods are waiting for a slot, that write turns the node NotReady for aboutmaxWaitTimeInSeconds − 30 s:cni_conf_syncer.goL94–L105, v2.3.7);libcni.Load, takes go-cni's write lock (cni.goL123–L125, v1.1.13) and waits for everySetupin flight, which holds the read lock for the whole CNI ADD (L167–L169); with pod-pacemaker in the chain an ADD can wait up tomaxWaitTimeInSecondsfor a slot;sync.RWMutex), so the CRIStatuscall that reads the network status throughlibcni.Status(L140–L142) hangs, and kubelet reportscontainer runtime is downand 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 withmaxWaitTimeInSeconds: 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
generateCNIConfigwrites through a newwriteFileIfChanged: an unchanged file is not touched; a changed one is written to<name>.tmpand renamed over it, asmergeTwoConfigsalready did.mergeTwoConfigsnow 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
TestGenerateCNIConfigWritesOnlyOnChangeincmd/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.tmpbehind.maxConcurrent2,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:container runtime is down) for 3 min 8 s, 16FailedCreatePodSandBox(12 slot timeouts, 4 VPC CNIfailed to assign an IP address), 562 s until all pods were Ready;FailedCreatePodSandBox(4 slot timeouts at the tail of the queue, 4 VPC CNIfailed to assign an IP address), 397 s until all pods were Ready.