diff --git a/api/v1/postgres_types.go b/api/v1/postgres_types.go index 199580a3..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) - z.Spec.Sidecars = p.buildSidecars(c) + _ = 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,19 +717,22 @@ 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 - } - - // 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 - } - } - } + // if err := yaml.Unmarshal([]byte(c.Data["sidecars"]), &sidecars); err != nil { + // 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 + // } + // } + // } + + // 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..d39bf287 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,12 @@ 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"] + cm.Data["enable_sidecars"] = strconv.FormatBool(true) + } + } // ensureCleanMetadata ensures obj has clean metadata @@ -618,3 +625,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 +}