mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-21 04:56:36 +00:00
fix: reflect --namespaces-to-ignore in startup namespace-scope log
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 #1131 Assisted-by: Claude Code (Anthropic, Opus 4.x)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user