Skip to content

fix(cni): make the installer's log lines actually reach stdout (#696) - #710

Merged
bpalermo merged 1 commit into
mainfrom
fix/696-cni-install-logger
Sep 5, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/696-cni-install-logger

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Fixes #696.

The bug

cni/internal/install logged part of the install through installLog = ctrl.Log.WithName("installer") — controller-runtime's global logger — but nothing in cni/ ever calls ctrl.SetLogger. controller-runtime discards writes to an unbound global logger, so every one of those records was dropped in production. On talos-main the cni-install init container log ended at CNI binaries installed, and two things an operator needs were silent:

cni/internal/util's file watcher had the same unbound ctrl.Log.

The fix

The issue's preferred option: drop ctrl.Log and thread the installer's own logger down.

  • Installer now holds a *slog.Logger rather than a logr bridge. cni/internal/cmd already built the shared slog logger and only wrapped it in logr.FromSlogHandler because the install package used controller-runtime; that wrapper is gone.
  • cniconfig.go and util.CreateFileWatcher take the logger as a parameter.
  • controller-runtime is no longer a dependency of cni/internal/install, cni/internal/cmd, or cni/internal/util. cni/cmd/cni-install/main.go still uses ctrl.SetupSignalHandler, which does not log — nothing in cni/ touches ctrl.Log any more.

Log messages and attribute keys are unchanged, so existing greps still match. Two secondary Info calls had malformed key/value lists (one dangling value, one bare filepath) that slog would render as !BADKEY; they get their filepath/alternate keys. logr's leading error argument becomes the repo-standard "error", err pair.

Validation

  • New tests in cni/internal/install/cniconfig_test.go 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 log at ERROR — an unwritable location (a regular file standing in for the conf dir, so it fails as root too) and a conflist with no aether entry to extract. That ERROR line is the operator's only signal, since the durable write is deliberately swallowed so a lost safety net never fails an install that already meshed the node.
  • bazel test //cni/... — 8/8 pass.
  • bazel run //:gazelle, make format-check clean.
  • End to end: the built binary run against a scratch conflist now emits six lines instead of three, including the two that were missing:
{"level":"INFO","message":"installing CNI binaries","logger":"cni-install"}
{"level":"INFO","message":"running CNI installer","logger":"cni-install"}
{"level":"INFO","message":"CNI config file exists, proceeding","filepath":".../10-flannel.conflist","logger":"cni-install"}
{"level":"INFO","message":"Wrote CNI config","filepath":".../10-flannel.conflist","logger":"cni-install"}
{"level":"INFO","message":"Wrote the durable aether CNI entry","filepath":".../.aether-cni-entry","logger":"cni-install"}
{"level":"INFO","message":"CNI binaries installed","binaries":[".../aether-cni"],"logger":"cni-install"}

Related: #680, #689, #645, #650.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

`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.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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-install: cniconfig.go logs via an unbound ctrl.Log — 'Wrote CNI config' and #689's durable-entry write/error lines never reach stdout

1 participant