From b5b0b027f24bd92b79dbd16e2cd78ca34bf2250d Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Thu, 8 Feb 2018 14:51:45 +0100 Subject: [PATCH] Handle watched namespace set in operator config map --- pkg/controller/controller.go | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0b500315f..f2e88ca83 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -98,33 +98,26 @@ func (c *Controller) initOperatorConfig() { } // by default, the operator listens to all namespaces - // by setting the env variable, one can restrict the operator to a single namespace - watchedNamespace, isPresentInEnv := os.LookupEnv("WATCHED_NAMESPACE") - if isPresentInEnv { - // special case: v1.NamespaceAll currently also evaluates to the empty string - // so when the env var is set to the empty string, use the default ns - // since the meaning of this env var is only one namespace - if watchedNamespace == "" { - c.logger.Infof("The WATCHED_NAMESPACE env var evaluates to the empty string, falling back to watching the 'default' namespace.\n", watchedNamespace) - configMapData["watched_namespace"] = v1.NamespaceDefault - } else { - c.logger.Infof("Watch the %q namespace specified in the env variable WATCHED_NAMESPACE\n", watchedNamespace) - configMapData["watched_namespace"] = watchedNamespace - } - - } else { - c.logger.Infof("Watch all namespaces. Set the WATCHED_NAMESPACE env var to restrict to a single namespace.\n", watchedNamespace) + if configMapData["watched_namespace"] == "" { + c.logger.Infoln("The operator config map specifies no namespace to watch. Falling back to watching all namespaces.") configMapData["watched_namespace"] = v1.NamespaceAll } - /* - // env var takes priority over the same param from the operator ConfigMap + watchedNsEnvVar, isPresentInEnv := os.LookupEnv("WATCHED_NAMESPACE") + if isPresentInEnv { + c.logger.Infoln("The WATCHED_NAMESPACE env variable takes priority over the same param from the operator configMap\n") + // special case: v1.NamespaceAll currently also evaluates to the empty string + // so when the env var is set to the empty string, use the default ns + // since the meaning of this env var is only one namespace + if watchedNsEnvVar == "" { + c.logger.Infof("The WATCHED_NAMESPACE env var evaluates to the empty string, falling back to watching the 'default' namespace.\n", watchedNsEnvVar) + configMapData["watched_namespace"] = v1.NamespaceDefault + } else { + c.logger.Infof("Watch the %q namespace specified in the env variable WATCHED_NAMESPACE\n", watchedNsEnvVar) + configMapData["watched_namespace"] = watchedNsEnvVar + } + } - if configMapData["watched_namespace"] == "" { - c.logger.Infoln("No namespace to watch specified. Fall back to watching the 'default' namespace.") - configMapData["watched_namespace"] = v1.NamespaceDefault - } - */ if c.config.NoDatabaseAccess { configMapData["enable_database_access"] = "false" }