Make env var overwrite configmap setting for watching namespaces
This commit is contained in:
parent
0ef801f4e0
commit
8b7bbde06e
11
cmd/main.go
11
cmd/main.go
|
|
@ -27,14 +27,9 @@ func init() {
|
||||||
flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API")
|
flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config.Namespace = os.Getenv("WATCH_NAMESPACE")
|
configMapRawName := os.Getenv("CONFIG_MAP_NAME")
|
||||||
if config.Namespace == "" {
|
if configMapRawName != "" {
|
||||||
config.Namespace = "default"
|
err := config.ConfigMapName.Decode(configMapRawName)
|
||||||
}
|
|
||||||
|
|
||||||
configMap := os.Getenv("CONFIG_MAP_NAME")
|
|
||||||
if configMap != "" {
|
|
||||||
err := config.ConfigMapName.Decode(configMap)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("incorrect config map name")
|
log.Fatalf("incorrect config map name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ metadata:
|
||||||
name: postgres-operator
|
name: postgres-operator
|
||||||
data:
|
data:
|
||||||
# assumes the ns exists before the operator starts
|
# 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
|
# watched_namespace: development
|
||||||
service_account_name: operator
|
service_account_name: operator
|
||||||
cluster_labels: application:spilo
|
cluster_labels: application:spilo
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,10 @@ spec:
|
||||||
image: registry.opensource.zalan.do/acid/postgres-operator:c17aabb
|
image: registry.opensource.zalan.do/acid/postgres-operator:c17aabb
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
env:
|
env:
|
||||||
- name: WATCH_NAMESPACE
|
# uncomment to overwrite a similar setting from operator configmap
|
||||||
valueFrom:
|
# - name: WATCHED_NAMESPACE
|
||||||
fieldRef:
|
# valueFrom:
|
||||||
fieldPath: metadata.namespace
|
# fieldRef:
|
||||||
|
# fieldPath: metadata.namespace
|
||||||
- name: CONFIG_MAP_NAME
|
- name: CONFIG_MAP_NAME
|
||||||
value: "postgres-operator"
|
value: "postgres-operator"
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,21 @@ func (c *Controller) initOperatorConfig() {
|
||||||
c.logger.Infoln("no ConfigMap specified. Loading default values")
|
c.logger.Infoln("no ConfigMap specified. Loading default values")
|
||||||
}
|
}
|
||||||
|
|
||||||
if configMapData["watched_namespace"] == "" { // Namespace in ConfigMap has priority over env var
|
// env var takes priority over the same param from the operator ConfigMap
|
||||||
configMapData["watched_namespace"] = c.config.Namespace
|
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 {
|
if c.config.NoDatabaseAccess {
|
||||||
configMapData["enable_database_access"] = "false"
|
configMapData["enable_database_access"] = "false"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue