Skip to content

fix: reflect --namespaces-to-ignore in startup namespace-scope log#1163

Open
nikolauspschuetz wants to merge 1 commit into
stakater:masterfrom
nikolauspschuetz:fix/1131-misleading-all-namespaces-log
Open

fix: reflect --namespaces-to-ignore in startup namespace-scope log#1163
nikolauspschuetz wants to merge 1 commit into
stakater:masterfrom
nikolauspschuetz:fix/1131-misleading-all-namespaces-log

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

Problem

When KUBERNETES_NAMESPACE is unset (global mode), Reloader logs at startup:

level=warning msg="KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces."

This message is printed unconditionally, even when --namespaces-to-ignore is
configured, so the log claims it watches all namespaces while namespace
filtering is actually active. Reported in #1131 (confirmed on v1.4.2 and v1.4.14).

Root cause

internal/pkg/cmd/reloader.go logged the "all namespaces" message inside the
len(currentNamespace) == 0 block (formerly line 118), before
ignoredNamespacesList := options.NamespacesToIgnore was resolved (line 132).
The log had no visibility into the ignore list.

Fix

  • Extract the message into a small, testable helper
    namespaceWatchScopeMessage(ignoredNamespaces []string) string.
  • Move the log to after ignoredNamespacesList is resolved (still gated on
    global mode).
  • When --namespaces-to-ignore is non-empty, the message now reads:
    KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces except: <ns1>, <ns2>.
    Otherwise the original message is unchanged.

Minimal diff: 17 insertions, 1 deletion in reloader.go plus a new unit test.

Test / verification

  • Added internal/pkg/cmd/reloader_test.go (TestNamespaceWatchScopeMessage)
    covering nil/empty (all-namespaces) and single/multiple ignored-namespace
    cases. Verified it fails against the old behavior and passes with the
    fix.
  • go test ./internal/pkg/cmd/... → ok
  • go vet ./internal/pkg/cmd/, go build ./..., gofmt -l → clean

AI assistance

This change was prepared with AI assistance (Claude Code, Anthropic, Opus 4.x).
A human reviewed the root-cause analysis, the fix, and the test before opening
this PR. The commit carries an Assisted-by: trailer.

Closes #1131

When KUBERNETES_NAMESPACE is unset, startReloader logged
"will detect changes in all namespaces." unconditionally, even when
--namespaces-to-ignore was set, which is misleading.

Extract the scope message into namespaceWatchScopeMessage(), move the log
after ignoredNamespacesList is resolved, and include the excluded
namespaces in the message when filtering is active.

Closes stakater#1131

Assisted-by: Claude Code (Anthropic, Opus 4.x)
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.

Misleading 'will detect changes in all namespaces' log when --namespaces-to-ignore is set

1 participant