Watch all namespaces if the relevant param is empty string / 'default' if param is unset

This commit is contained in:
Sergey Dudoladov 2018-02-12 11:47:56 +01:00
parent 066f11cbbd
commit 4c23917d42
2 changed files with 11 additions and 10 deletions

View File

@ -4,7 +4,8 @@ metadata:
name: postgres-operator name: postgres-operator
data: data:
# the env var with the same name in the operator pod may overwrite this value # the env var with the same name in the operator pod may overwrite this value
# if neither is set, listen to all namespaces # if neither is set, listen to the 'default' namespace
# if set to the empty string "", listen to all namespaces
# watched_namespace: development # watched_namespace: development
service_account_name: operator service_account_name: operator
cluster_labels: application:spilo cluster_labels: application:spilo

View File

@ -101,18 +101,18 @@ func (c *Controller) initOperatorConfig() {
watchedNsEnvVar, isPresentInOperatorEnv := os.LookupEnv("WATCHED_NAMESPACE") watchedNsEnvVar, isPresentInOperatorEnv := os.LookupEnv("WATCHED_NAMESPACE")
if (!isPresentInOperatorConfigMap) && (!isPresentInOperatorEnv) { if (!isPresentInOperatorConfigMap) && (!isPresentInOperatorEnv) {
c.logger.Infoln("Neither the operator config map nor operator pod's environment define a namespace to watch. Default to watching all namespaces.") c.logger.Infoln("Neither the operator config map nor operator pod's environment define a namespace to watch. Fall back to watching the 'default' namespace.")
configMapData["watched_namespace"] = v1.NamespaceAll configMapData["watched_namespace"] = v1.NamespaceDefault
} }
if (isPresentInOperatorConfigMap) && (!isPresentInOperatorEnv) { if (isPresentInOperatorConfigMap) && (!isPresentInOperatorEnv) {
// special case: v1.NamespaceAll currently also evaluates to the empty string // explicitly specify the policy for handling the empty string
// so when the param evaluates to the empty string, we use the default ns // v1.NamespaceAll currently also evaluates to the empty string
// since the meaning of the param is a single namespace and *not* all namespaces // so when the param is set to this value, we watch all ns
if watchedNsConfigMapVar == "" { if watchedNsConfigMapVar == "" {
c.logger.Infof("The watched namespace field in the operator config map evaluates to the empty string, falling back to watching the 'default' namespace.\n") c.logger.Infof("The watched namespace field in the operator config map evaluates to the empty string, falling back to watching all namespaces.\n")
configMapData["watched_namespace"] = v1.NamespaceDefault configMapData["watched_namespace"] = v1.NamespaceAll
} }
} }
@ -124,8 +124,8 @@ func (c *Controller) initOperatorConfig() {
// handle the empty string consistently // handle the empty string consistently
if watchedNsEnvVar == "" { if watchedNsEnvVar == "" {
c.logger.Infoln("The WATCHED_NAMESPACE env var evaluates to the empty string, falling back to watching the 'default' namespace") c.logger.Infoln("The WATCHED_NAMESPACE env var evaluates to the empty string, falling back to watching all namespaces")
configMapData["watched_namespace"] = v1.NamespaceDefault configMapData["watched_namespace"] = v1.NamespaceAll
} else { } else {
c.logger.Infof("Watch the %q namespace specified in the env variable WATCHED_NAMESPACE\n", watchedNsEnvVar) c.logger.Infof("Watch the %q namespace specified in the env variable WATCHED_NAMESPACE\n", watchedNsEnvVar)
configMapData["watched_namespace"] = watchedNsEnvVar configMapData["watched_namespace"] = watchedNsEnvVar