diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 93966ce2c7626ee09bb8b71ebf8054585af6b11c..a71ce21fd70a90aa191028dc35f8c09b3286c39c 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -927,7 +927,7 @@ type ClusterObjectDelete func(name string) error func (c *Cluster) deletePatroniClusterObjects() error { // TODO: figure out how to remove leftover patroni objects in other cases - if !c.patroniUsesKubernetes() { + if !c.OpConfig.PatroniUseKubernetes { c.logger.Infof("not cleaning up Etcd Patroni objects on cluster delete") } c.logger.Debugf("removing leftover Patroni objects (endpoints or configmaps)") diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index f216797c022ba39bd22c296ad17995119f0829b5..209e2469ebd3a3f5bc1abdcee9be338ac54b4a97 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -399,7 +399,7 @@ func (c *Cluster) generatePodTemplate( envVars = append(envVars, v1.EnvVar{Name: "LOG_BUCKET_SCOPE_PREFIX", Value: ""}) } - if c.patroniUsesKubernetes() { + if c.OpConfig.PatroniUseKubernetes { envVars = append(envVars, v1.EnvVar{Name: "DCS_ENABLE_KUBERNETES_API", Value: "true"}) } else { envVars = append(envVars, v1.EnvVar{Name: "ETCD_HOST", Value: c.OpConfig.EtcdHost}) diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index e7db26d82b288e29230858f8f9c92722c5b6b5e8..476d39e52ee238cfac845d60d86af93b1ea19bbe 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -460,7 +460,3 @@ func (c *Cluster) GetSpec() (*spec.Postgresql, error) { defer c.specMu.RUnlock() return cloneSpec(&c.Postgresql) } - -func (c *Cluster) patroniUsesKubernetes() bool { - return c.OpConfig.EtcdHost == "" -} diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 84a07811b1f99e10fbd2235a66ad12aaf92c8482..3fbe9afa44585f316b291cb64457c6cfdc310c3a 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -112,6 +112,7 @@ func (c *Controller) initOperatorConfig() { c.opConfig = config.NewFromMap(configMapData) c.warnOnDeprecatedOperatorParameters() + c.processDeprecatedOperatorParameters() scalyrAPIKey := os.Getenv("SCALYR_API_KEY") if scalyrAPIKey != "" { @@ -126,6 +127,20 @@ func (c *Controller) warnOnDeprecatedOperatorParameters() { c.logger.Warningf("Operator configuration parameter 'enable_load_balancer' is deprecated and takes no effect. " + "Consider using the 'enable_master_load_balancer' or 'enable_replica_load_balancer' instead.") } + if c.opConfig.EtcdHost == "" && !c.opConfig.PatroniUseKubernetes { + c.logger.Warningf("Set 'patroni_use_kubernetes' instead of setting 'etcd_host' set to an empty string to enable " + + "support for Kubernetes API in Patroni.") + } + if c.opConfig.EtcdHost != "" && c.opConfig.PatroniUseKubernetes { + c.logger.Warningf("both 'patroni_use_kubernetes' is enabled and 'etcd_host' is set to a non-empty value, " + + "'patroni_use_kubernetes' is ignored.") + } +} + +func (c *Controller) processDeprecatedOperatorParameters() { + if c.opConfig.EtcdHost == "" && !c.opConfig.PatroniUseKubernetes { + c.opConfig.PatroniUseKubernetes = true + } } func (c *Controller) initPodServiceAccount() { diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 3ffdfb93211ea745f7125c2ea9b5ba9bc5c14cb9..1ff9a5ea7c2cfb890eb4bb6af0781e37626da28d 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -68,9 +68,10 @@ type Config struct { Auth Scalyr - WatchedNamespace string `name:"watched_namespace"` // special values: "*" means 'watch all namespaces', the empty string "" means 'watch a namespace where operator is deployed to' - EtcdHost string `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"` - DockerImage string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"` + WatchedNamespace string `name:"watched_namespace"` // special values: "*" means 'watch all namespaces', the empty string "" means 'watch a namespace where operator is deployed to' + EtcdHost string `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"` + PatroniUseKubernetes bool `name:"patroni_use_kubernetes" default:"false"` + DockerImage string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"` // default name `operator` enables backward compatibility with the older ServiceAccountName field PodServiceAccountName string `name:"pod_service_account_name" default:"operator"` // value of this string must be valid JSON or YAML; see initPodServiceAccount