Skip to content

fix: improve daemon robustness - #197

Merged
woehrl01 merged 2 commits into
woehrl01:mainfrom
crazyproger:fix/daemon-robustness
Nov 6, 2026
Merged

woehrl01 merged 2 commits into
woehrl01:mainfrom
crazyproger:fix/daemon-robustness

Conversation

@crazyproger

@crazyproger crazyproger commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Robustness fixes for the node daemon, plus follow-ups to #194, #195 and #196 that missed their merge. Rebased on main as one commit.

Problems

  • The daemon exits on transient API errors. Selecting the PacemakerConfig gets the node, and removing the startup taint does a full Update of the Node. Both end the daemon with log.Fatalf on any error. On a starting node the kubelet and node provisioners update the Node too, so a conflict is expected now and then. The restart loses the slots held in memory, up to N more pods start at once, and new pods wait for the socket meanwhile.
  • One broken PacemakerConfig stops the daemon on every node: a failed conversion is log.Fatalf too.
  • Panic on a missed pod delete. After a watch outage the informer delivers a missed delete as cache.DeletedFinalStateUnknown; obj.(*v1.Pod) in DeleteFunc panics and all slots are lost.
  • A pod without container statuses counts as started and as terminated. allStarted and allTerminated start as true and loop over an empty list, so a pod that has not reported container statuses yet (right after the CNI ADD) loses its slot before it starts.
  • Panic on shutdown. The gRPC server goroutine calls wg.Done() twice; when the server returns, e.g. on SIGTERM, the daemon panics with sync: negative WaitGroup counter.
  • Shutdown waits for blocked slot requests. GracefulStop waits for the requests in flight, and a request waiting for a slot blocks until its deadline, so with the double wg.Done() fixed the daemon would hang on SIGTERM for up to maxWaitTimeInSeconds (the e2e test deleting the daemon pod caught it).
  • Exit code 1 on a regular stop. log.Fatal(srv.ListenAndServe()) also fires on http.ErrServerClosed after the graceful shutdown of the metrics server.
  • Nil dereference in the plugin. shouldSkipThrotteling reads conf.RuntimeConfig.PodAnnotations without a nil check; a runtime that passes no runtimeConfig makes every ADD panic.

Follow-ups:

Fix

  • Getting the node and removing the taint retry with backoff (retry.OnError, 6 attempts, about 30 s). If the node still cannot be read, the current throttlers stay and the error is logged; only before the first successful configuration the daemon still exits, so that a restart retries instead of leaving the node unthrottled until the next config change. Removing the taint still exits after the retries: the taint keeps pods off the node and a restart tries again.
  • A config that fails to convert is skipped with an error.
  • DeleteFunc unwraps the tombstone.
  • allStarted / allTerminated require at least one container status.
  • The second wg.Done() is removed; http.ErrServerClosed is not treated as an error.
  • The gRPC server stops with Stop: the waiting requests are dropped and the CNI plugin retries them against the next daemon (covered by a plugin test with a daemon restart).
  • RuntimeConfig is checked for nil.
  • ErrImagePull and ImagePullBackOff release the slot only after the pull has kept failing for 2 minutes (imagePullGracePeriod), counted from the first failure; InvalidImageName, CrashLoopBackOff and the CreateContainer* errors still release it right away. The --max-slot-hold help says it is checked on pod events and the 30s resync.
  • cni-config-sync is not rendered for any zero cni.watchInterval (0, 0s, 0m, ...).

Tests

  • Unit tests for the image pull grace period (counted from the first failure, restarted when the pull recovers), the pod without container statuses and shouldSkipThrotteling without runtimeConfig; go test -race ./... and helm lint pass; helm template renders cni-config-sync for 10s/1m/0.5s and not for empty/0/0s/0m/0m0s.
  • EKS 1.35 (containerd, Amazon VPC CNI v1.21.1), this commit on top of main, maxConcurrent.value: 3:
    • two pods with a missing image tag and one with a failing init container took all 3 slots: the init container slot was released right away, the image pull slots 2 minutes after the first failure (three new pods then got their slots at the same moment);
    • cni-config-sync re-merged the configuration 8 s after an aws-node restart with changed env;
    • with the DaemonSet removed from the node, new pods started without a slot after maxWaitTimeInSeconds (220 s).

@woehrl01

woehrl01 commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thank you @crazyproger for all your nice contributions! Please rebase this PR.

…oehrl01#194-woehrl01#196

Node daemon:
- Getting the node for the PacemakerConfig selection and removing the startup taint retry
  (6 attempts, about 30s) instead of log.Fatalf. A restart loses the slots held in memory, so up to
  N more pods start at once. When the node still cannot be read the current throttlers stay; only
  before the first successful configuration the daemon still exits, so that a restart retries
  instead of leaving the node unthrottled until the next config change.
- A PacemakerConfig that fails to convert is skipped instead of stopping the daemon on every node.
- A missed pod delete arrives after a re-list as cache.DeletedFinalStateUnknown; DeleteFunc unwraps
  it instead of panicking.
- A pod without container statuses yet no longer counts as started and terminated.
- The gRPC server goroutine no longer calls wg.Done twice (panic on SIGTERM), and
  http.ErrServerClosed of the metrics server is not fatal.
- ErrImagePull and ImagePullBackOff release the slot only after the pull has kept failing for
  imagePullGracePeriod (2m) from the first failure: a pull also fails while the registry throttles,
  and releasing those slots at once would start all waiting pods of the node together.

CNI plugin: shouldSkipThrotteling checks runtimeConfig for nil; the acquireSlot comment describes
the connect logic from woehrl01#194.

Chart: cni-config-sync is not rendered for a zero cni.watchInterval (0, 0s, 0m, ...);
cni-init exits right after the setup then and the container restarted forever.
@crazyproger
crazyproger force-pushed the fix/daemon-robustness branch from 9a8fb4f to 828fb6a Compare November 6, 2026 17:01
GracefulStop waits for the requests in flight, and a request waiting for a slot can block until its
deadline (maxWaitTimeInSeconds), so the daemon did not exit on SIGTERM. Before this branch that went
unnoticed: the double wg.Done made the daemon panic and exit right away. The e2e test deletes the
daemon pod while pods wait and its kubectl delete was killed after 5s.

Stop drops the waiting requests; the CNI plugin sees a connection error and retries against the next
daemon. A test covers the plugin side of a restart.
@woehrl01 woehrl01 changed the title Fix/daemon robustness fix: improve daemon robustness Nov 6, 2026
@woehrl01
woehrl01 merged commit 8f7e949 into woehrl01:main Nov 6, 2026
1 check passed
@crazyproger
crazyproger deleted the fix/daemon-robustness 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