From 02af78c23efef4827f56d4105a2a23c39e49d718 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Thu, 4 Aug 2022 18:23:44 +0200 Subject: [PATCH 1/9] PoC of new sidecars definition --- api/v1/postgres_types.go | 3 +++ pkg/operatormanager/operatormanager.go | 27 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index 199580a3..a74e719a 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -731,6 +731,9 @@ func (p *Postgres) buildSidecars(c *corev1.ConfigMap) []zalando.Sidecar { } } + // TODO only use envs here, leave the rest to the postgres-operator configmap? + // TODO also set PG_EXPORTER_CONSTANT_LABELS with partitionid and postgres cluster name + return sidecars } diff --git a/pkg/operatormanager/operatormanager.go b/pkg/operatormanager/operatormanager.go index 65de66bf..98c02ae8 100644 --- a/pkg/operatormanager/operatormanager.go +++ b/pkg/operatormanager/operatormanager.go @@ -73,7 +73,8 @@ type OperatorManager struct { log logr.Logger meta.MetadataAccessor *runtime.Scheme - options Options + options Options + globalSidecarsCM *corev1.ConfigMap } // New creates a new `OperatorManager` @@ -415,6 +416,11 @@ func (m *OperatorManager) editConfigMap(cm *corev1.ConfigMap, namespace string, cm.Data["replication_username"] = "standby" cm.Data["enable_pod_antiaffinity"] = strconv.FormatBool(options.PodAntiaffinity) + + if sidecarsCM, err := m.getSidecarsCM(); err == nil && sidecarsCM != nil { + cm.Data["sidecars"] = sidecarsCM.Data["sidecars"] + } + } // ensureCleanMetadata ensures obj has clean metadata @@ -618,3 +624,22 @@ func (m *OperatorManager) UpdateAllOperators(ctx context.Context) error { m.log.Info("Done updating postgres operators in managed namespaces") return nil } + +func (m *OperatorManager) getSidecarsCM() (*corev1.ConfigMap, error) { + // return cached version + if m.globalSidecarsCM != nil { + return m.globalSidecarsCM, nil + } + + // try to fetch the global sidecars configmap + cns := types.NamespacedName{ + Namespace: m.options.PostgresletNamespace, + Name: m.options.SidecarsConfigMapName, + } + m.globalSidecarsCM = &corev1.ConfigMap{} + if err := m.Get(context.Background(), cns, m.globalSidecarsCM); err != nil { + // configmap with configuration does not exists, nothing we can do here... + return nil, fmt.Errorf("could not fetch config for sidecars") + } + return m.globalSidecarsCM, nil +} From 47d7b97e0d46d06464f641979db6719e2b4f9e25 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 08:27:25 +0200 Subject: [PATCH 2/9] Temporarily disable sidecars definition in CR --- api/v1/postgres_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index a74e719a..1125d00c 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -569,7 +569,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor // skip if the configmap does not exist if c != nil { z.Spec.AdditionalVolumes = p.buildAdditionalVolumes(c) - z.Spec.Sidecars = p.buildSidecars(c) + // z.Spec.Sidecars = p.buildSidecars(c) // TODO temporaily disabled } if p.HasSourceRanges() { From b0388968a2e474ff3d30c377101e646db20d168f Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 08:29:11 +0200 Subject: [PATCH 3/9] Temporarily disable sidecars definition in CR --- api/v1/postgres_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index 1125d00c..cce25300 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -569,7 +569,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor // skip if the configmap does not exist if c != nil { z.Spec.AdditionalVolumes = p.buildAdditionalVolumes(c) - // z.Spec.Sidecars = p.buildSidecars(c) // TODO temporaily disabled + _ = p.buildSidecars(c) // TODO temporaily disabled } if p.HasSourceRanges() { From 4643a9b1d0d44da1be69c6ca818c7b43d5b48274 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 11:12:58 +0200 Subject: [PATCH 4/9] set the enable_sidecars option as well --- pkg/operatormanager/operatormanager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/operatormanager/operatormanager.go b/pkg/operatormanager/operatormanager.go index 98c02ae8..d39bf287 100644 --- a/pkg/operatormanager/operatormanager.go +++ b/pkg/operatormanager/operatormanager.go @@ -419,6 +419,7 @@ func (m *OperatorManager) editConfigMap(cm *corev1.ConfigMap, namespace string, if sidecarsCM, err := m.getSidecarsCM(); err == nil && sidecarsCM != nil { cm.Data["sidecars"] = sidecarsCM.Data["sidecars"] + cm.Data["enable_sidecars"] = strconv.FormatBool(true) } } From d07d83c9afab6339ff111acf8f8494ce77d84f86 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 11:13:51 +0200 Subject: [PATCH 5/9] re-enable the sidecars definition within the cr, but disable variable/secret setting --- api/v1/postgres_types.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index cce25300..77096e94 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -569,7 +569,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor // skip if the configmap does not exist if c != nil { z.Spec.AdditionalVolumes = p.buildAdditionalVolumes(c) - _ = p.buildSidecars(c) // TODO temporaily disabled + z.Spec.Sidecars = p.buildSidecars(c) } if p.HasSourceRanges() { @@ -721,15 +721,15 @@ func (p *Postgres) buildSidecars(c *corev1.ConfigMap) []zalando.Sidecar { return nil } - // Deal with dynamically assigned name - for i := range sidecars { - for j := range sidecars[i].Env { - if sidecars[i].Env[j].ValueFrom != nil && sidecars[i].Env[j].ValueFrom.SecretKeyRef != nil { - sidecars[i].Env[j].ValueFrom.SecretKeyRef.Name = "postgres." + p.ToPeripheralResourceName() + ".credentials" - break - } - } - } + // // Deal with dynamically assigned name + // for i := range sidecars { + // for j := range sidecars[i].Env { + // if sidecars[i].Env[j].ValueFrom != nil && sidecars[i].Env[j].ValueFrom.SecretKeyRef != nil { + // sidecars[i].Env[j].ValueFrom.SecretKeyRef.Name = "postgres." + p.ToPeripheralResourceName() + ".credentials" + // break + // } + // } + // } // TODO only use envs here, leave the rest to the postgres-operator configmap? // TODO also set PG_EXPORTER_CONSTANT_LABELS with partitionid and postgres cluster name From d56db8f38da916b05e99c79591692a891c47755a Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 13:44:01 +0200 Subject: [PATCH 6/9] Disable sidecars in cr --- api/v1/postgres_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index 77096e94..220abb22 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -569,7 +569,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor // skip if the configmap does not exist if c != nil { z.Spec.AdditionalVolumes = p.buildAdditionalVolumes(c) - z.Spec.Sidecars = p.buildSidecars(c) + _ = p.buildSidecars(c) // TODO temporaily disabled sidecar definition in custom ressource } if p.HasSourceRanges() { From 1709a9dce9538f0d98bd4fb08bd1a1e699bff69f Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 13:44:26 +0200 Subject: [PATCH 7/9] play around with cm --- pkg/operatormanager/operatormanager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operatormanager/operatormanager.go b/pkg/operatormanager/operatormanager.go index d39bf287..96822123 100644 --- a/pkg/operatormanager/operatormanager.go +++ b/pkg/operatormanager/operatormanager.go @@ -418,7 +418,7 @@ func (m *OperatorManager) editConfigMap(cm *corev1.ConfigMap, namespace string, cm.Data["enable_pod_antiaffinity"] = strconv.FormatBool(options.PodAntiaffinity) if sidecarsCM, err := m.getSidecarsCM(); err == nil && sidecarsCM != nil { - cm.Data["sidecars"] = sidecarsCM.Data["sidecars"] + cm.Data["sidecars"] = "|\n" + sidecarsCM.Data["sidecars"] cm.Data["enable_sidecars"] = strconv.FormatBool(true) } From d42a9c9785ab2936126b632da5d355b78f8051a9 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 14:48:39 +0200 Subject: [PATCH 8/9] Try disabling even more sidecar configs --- api/v1/postgres_types.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index 220abb22..ad5bc098 100644 --- a/api/v1/postgres_types.go +++ b/api/v1/postgres_types.go @@ -568,8 +568,8 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor // skip if the configmap does not exist if c != nil { - z.Spec.AdditionalVolumes = p.buildAdditionalVolumes(c) - _ = p.buildSidecars(c) // TODO temporaily disabled sidecar definition in custom ressource + _ = p.buildAdditionalVolumes(c) // TODO temporarily disable additional volumes as well + _ = p.buildSidecars(c) // TODO temporaily disabled sidecar definition in custom ressource } if p.HasSourceRanges() { @@ -717,9 +717,9 @@ func (p *Postgres) buildSidecars(c *corev1.ConfigMap) []zalando.Sidecar { // Unmarshal yaml-string of exporter sidecars := []zalando.Sidecar{} - if err := yaml.Unmarshal([]byte(c.Data["sidecars"]), &sidecars); err != nil { - return nil - } + // if err := yaml.Unmarshal([]byte(c.Data["sidecars"]), &sidecars); err != nil { + // return nil + // } // // Deal with dynamically assigned name // for i := range sidecars { From 267a60916d07d8d5a1de71aef98c369f6994c2f1 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 8 Aug 2022 14:49:16 +0200 Subject: [PATCH 9/9] Revert "play around with cm" This reverts commit 1709a9dce9538f0d98bd4fb08bd1a1e699bff69f. --- pkg/operatormanager/operatormanager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operatormanager/operatormanager.go b/pkg/operatormanager/operatormanager.go index 96822123..d39bf287 100644 --- a/pkg/operatormanager/operatormanager.go +++ b/pkg/operatormanager/operatormanager.go @@ -418,7 +418,7 @@ func (m *OperatorManager) editConfigMap(cm *corev1.ConfigMap, namespace string, cm.Data["enable_pod_antiaffinity"] = strconv.FormatBool(options.PodAntiaffinity) if sidecarsCM, err := m.getSidecarsCM(); err == nil && sidecarsCM != nil { - cm.Data["sidecars"] = "|\n" + sidecarsCM.Data["sidecars"] + cm.Data["sidecars"] = sidecarsCM.Data["sidecars"] cm.Data["enable_sidecars"] = strconv.FormatBool(true) }