diff --git a/main.go b/main.go index 4750bc8c..bd0795e7 100644 --- a/main.go +++ b/main.go @@ -103,7 +103,9 @@ func main() { LeaderElectionID: "19fd6fcc.emqx.io", LeaseDuration: ptr.To(time.Second * 30), RenewDeadline: ptr.To(time.Second * 20), - Cache: getCacheOptions(), + Cache: cache.Options{ + DefaultNamespaces: getWatchNamespace(), + }, }) if err != nil { setupLog.Error(err, "unable to start manager") @@ -176,26 +178,15 @@ func main() { } } -func getCacheOptions() cache.Options { +// getWatchNamespace returns the Namespace the operator should be watching for changes +func getWatchNamespace() map[string]cache.Config { var watchNamespaceEnvVar = "WATCH_NAMESPACE" ns, found := os.LookupEnv(watchNamespaceEnvVar) - if !found { - return cache.Options{} - } - - return cache.Options{ - DefaultNamespaces: map[string]cache.Config{ns: {}}, + if found { + return map[string]cache.Config{ + ns: {}, + } } + return nil } - -// getWatchNamespace returns the Namespace the operator should be watching for changes -// func getWatchNamespace() string { -// var watchNamespaceEnvVar = "WATCH_NAMESPACE" - -// ns, found := os.LookupEnv(watchNamespaceEnvVar) -// if !found { -// return metav1.NamespaceAll -// } -// return ns -// }