Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion internal/pkg/cmd/reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -130,6 +143,9 @@ func startReloader(cmd *cobra.Command, args []string) {
}

ignoredNamespacesList := options.NamespacesToIgnore
if isGlobal {
logrus.Warn(namespaceWatchScopeMessage(ignoredNamespacesList))
}
namespaceLabelSelector := ""

if isGlobal {
Expand Down
40 changes: 40 additions & 0 deletions internal/pkg/cmd/reloader_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading