diff --git a/.chloggen/fix_2589-watch-single-namespace.yaml b/.chloggen/fix_2589-watch-single-namespace.yaml new file mode 100644 index 0000000000..50498d493f --- /dev/null +++ b/.chloggen/fix_2589-watch-single-namespace.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: operator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Fixing WATCH_NAMESPACE for a single namespace value" + +# One or more tracking issues related to the change +issues: [2589] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/main.go b/main.go index f8250d10b7..074e3905d2 100644 --- a/main.go +++ b/main.go @@ -196,9 +196,14 @@ func main() { setupLog.Error(err, "failed to autodetect config variables") } + var namespaces map[string]cache.Config watchNamespace, found := os.LookupEnv("WATCH_NAMESPACE") if found { setupLog.Info("watching namespace(s)", "namespaces", watchNamespace) + namespaces = map[string]cache.Config{} + for _, ns := range strings.Split(watchNamespace, ",") { + namespaces[ns] = cache.Config{} + } } else { setupLog.Info("the env var WATCH_NAMESPACE isn't set, watching all namespaces") } @@ -211,13 +216,6 @@ func main() { optionsTlSOptsFuncs := []func(*tls.Config){ func(config *tls.Config) { tlsConfigSetting(config, tlsOpt) }, } - var namespaces map[string]cache.Config - if strings.Contains(watchNamespace, ",") { - namespaces = map[string]cache.Config{} - for _, ns := range strings.Split(watchNamespace, ",") { - namespaces[ns] = cache.Config{} - } - } mgrOptions := ctrl.Options{ Scheme: scheme,