Skip to content

Commit

Permalink
Fixing WATCH_NAMESPACE env variable handling for single namespace val…
Browse files Browse the repository at this point in the history
…ue (#2606)
  • Loading branch information
davidhaja authored Feb 7, 2024
1 parent 52ad5cc commit 94c8420
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix_2589-watch-single-namespace.yaml
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 5 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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,
Expand Down

0 comments on commit 94c8420

Please sign in to comment.