Skip to content

Commit 94c8420

Browse files
authored
Fixing WATCH_NAMESPACE env variable handling for single namespace value (#2606)
1 parent 52ad5cc commit 94c8420

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Fixing WATCH_NAMESPACE for a single namespace value"
9+
10+
# One or more tracking issues related to the change
11+
issues: [2589]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

main.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,14 @@ func main() {
196196
setupLog.Error(err, "failed to autodetect config variables")
197197
}
198198

199+
var namespaces map[string]cache.Config
199200
watchNamespace, found := os.LookupEnv("WATCH_NAMESPACE")
200201
if found {
201202
setupLog.Info("watching namespace(s)", "namespaces", watchNamespace)
203+
namespaces = map[string]cache.Config{}
204+
for _, ns := range strings.Split(watchNamespace, ",") {
205+
namespaces[ns] = cache.Config{}
206+
}
202207
} else {
203208
setupLog.Info("the env var WATCH_NAMESPACE isn't set, watching all namespaces")
204209
}
@@ -211,13 +216,6 @@ func main() {
211216
optionsTlSOptsFuncs := []func(*tls.Config){
212217
func(config *tls.Config) { tlsConfigSetting(config, tlsOpt) },
213218
}
214-
var namespaces map[string]cache.Config
215-
if strings.Contains(watchNamespace, ",") {
216-
namespaces = map[string]cache.Config{}
217-
for _, ns := range strings.Split(watchNamespace, ",") {
218-
namespaces[ns] = cache.Config{}
219-
}
220-
}
221219

222220
mgrOptions := ctrl.Options{
223221
Scheme: scheme,

0 commit comments

Comments
 (0)