Merge pull request #1163 from nikolauspschuetz/fix/1131-misleading-all-namespaces-log

fix: reflect --namespaces-to-ignore in startup namespace-scope log
This commit is contained in:
Muhammad Safwan Karim
2026-07-01 15:57:04 +05:00
committed by GitHub
2 changed files with 57 additions and 1 deletions
+17 -1
View File
@@ -102,6 +102,20 @@ func getHAEnvs() (string, string) {
return podName, podNamespace
}
// namespaceWatchScopeMessage returns the startup log message describing the
// namespace scope Reloader will watch when KUBERNETES_NAMESPACE is unset
// (global mode). It reflects --namespaces-to-ignore so the log is not
// misleading when namespace filtering is configured.
func namespaceWatchScopeMessage(ignoredNamespaces []string) string {
if len(ignoredNamespaces) > 0 {
return fmt.Sprintf(
"KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces except: %s.",
strings.Join(ignoredNamespaces, ", "),
)
}
return "KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces."
}
func startReloader(cmd *cobra.Command, args []string) {
common.GetCommandLineOptions()
err := configureLogging(options.LogFormat, options.LogLevel)
@@ -115,7 +129,6 @@ func startReloader(cmd *cobra.Command, args []string) {
if len(currentNamespace) == 0 {
currentNamespace = v1.NamespaceAll
isGlobal = true
logrus.Warnf("KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces.")
}
// create the clientset
@@ -130,6 +143,9 @@ func startReloader(cmd *cobra.Command, args []string) {
}
ignoredNamespacesList := options.NamespacesToIgnore
if isGlobal {
logrus.Warn(namespaceWatchScopeMessage(ignoredNamespacesList))
}
namespaceLabelSelector := ""
if isGlobal {
+40
View File
@@ -0,0 +1,40 @@
package cmd
import "testing"
func TestNamespaceWatchScopeMessage(t *testing.T) {
tests := []struct {
name string
ignoredNamespaces []string
want string
}{
{
name: "no ignored namespaces - all namespaces",
ignoredNamespaces: nil,
want: "KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces.",
},
{
name: "empty ignored namespaces - all namespaces",
ignoredNamespaces: []string{},
want: "KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces.",
},
{
name: "single ignored namespace",
ignoredNamespaces: []string{"kube-system"},
want: "KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces except: kube-system.",
},
{
name: "multiple ignored namespaces",
ignoredNamespaces: []string{"kube-system", "kube-public"},
want: "KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces except: kube-system, kube-public.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := namespaceWatchScopeMessage(tt.ignoredNamespaces); got != tt.want {
t.Errorf("namespaceWatchScopeMessage(%v) = %q, want %q", tt.ignoredNamespaces, got, tt.want)
}
})
}
}