diff --git a/cmd/main.go b/cmd/main.go index f8215ab54..7bb501885 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -27,14 +27,9 @@ func init() { flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API") flag.Parse() - config.Namespace = os.Getenv("WATCH_NAMESPACE") - if config.Namespace == "" { - config.Namespace = "default" - } - - configMap := os.Getenv("CONFIG_MAP_NAME") - if configMap != "" { - err := config.ConfigMapName.Decode(configMap) + configMapRawName := os.Getenv("CONFIG_MAP_NAME") + if configMapRawName != "" { + err := config.ConfigMapName.Decode(configMapRawName) if err != nil { log.Fatalf("incorrect config map name") } diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 680af0453..5afc7db31 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -4,6 +4,7 @@ metadata: name: postgres-operator data: # assumes the ns exists before the operator starts + # the env var with the same name may overwrite it in the operator pod # watched_namespace: development service_account_name: operator cluster_labels: application:spilo diff --git a/manifests/postgres-operator.yaml b/manifests/postgres-operator.yaml index b71f19f19..84c4a0770 100644 --- a/manifests/postgres-operator.yaml +++ b/manifests/postgres-operator.yaml @@ -15,9 +15,10 @@ spec: image: registry.opensource.zalan.do/acid/postgres-operator:c17aabb imagePullPolicy: IfNotPresent env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace + # uncomment to overwrite a similar setting from operator configmap + # - name: WATCHED_NAMESPACE + # valueFrom: + # fieldRef: + # fieldPath: metadata.namespace - name: CONFIG_MAP_NAME value: "postgres-operator" diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0986e1a28..379eab04c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -97,9 +97,21 @@ func (c *Controller) initOperatorConfig() { c.logger.Infoln("no ConfigMap specified. Loading default values") } - if configMapData["watched_namespace"] == "" { // Namespace in ConfigMap has priority over env var - configMapData["watched_namespace"] = c.config.Namespace + // env var takes priority over the same param from the operator ConfigMap + watchedNamespace := os.Getenv("WATCHED_NAMESPACE") + if watchedNamespace != "" { + c.logger.Infof("Watch the %q namespace specified in the env variable WATCHED_NAMESPACE\n", watchedNamespace) + configMapData["watched_namespace"] = watchedNamespace } + + if configMapData["watched_namespace"] == "" { + c.logger.Infoln("No namespace to watch specified. Fall back to watching the 'default' namespace.") + configMapData["watched_namespace"] = v1.NamespaceDefault + } + + // display the actual namespace in case someone checks the value manually + os.Setenv("WATCHED_NAMESPACE", configMapData["watched_namespace"]) + if c.config.NoDatabaseAccess { configMapData["enable_database_access"] = "false" }