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
data:
# 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
service_account_name: operator
cluster_labels: application:spilo

View File

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