Skip to content

Commit 48cd617

Browse files
authored
Create postgres-pod-config when missing (#444)
* Create postgres-pod-config when missing * Create postgres-pod-config when missing * Create postgres-pod-config when missing * Revert "Create postgres-pod-config when missing" This reverts commit 80abfc7. * Create postgres-pod-config when missing * Revert "Create postgres-pod-config when missing" This reverts commit f06c73b. * Revert "Revert "Create postgres-pod-config when missing"" This reverts commit 1723f97. * Slightly improve logging * Slightly improve logging
1 parent 0033706 commit 48cd617

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

controllers/postgres_controller.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (r *PostgresReconciler) ensureZalandoDependencies(ctx context.Context, p *p
391391
}
392392

393393
func (r *PostgresReconciler) updatePodEnvironmentConfigMap(ctx context.Context, p *pg.Postgres) error {
394-
log := r.Log.WithValues("postgres", p.UID)
394+
log := r.Log.WithValues("postgres", p.Name)
395395
if p.Spec.BackupSecretRef == "" {
396396
log.Info("No configured backupSecretRef found, skipping configuration of postgres backup")
397397
return nil
@@ -457,7 +457,15 @@ func (r *PostgresReconciler) updatePodEnvironmentConfigMap(ctx context.Context,
457457
Namespace: p.ToPeripheralResourceNamespace(),
458458
}
459459
if err := r.SvcClient.Get(ctx, ns, cm); err != nil {
460-
return fmt.Errorf("error while getting the pod environment configmap from service cluster: %w", err)
460+
// when updating from v0.7.0 straight to v0.10.0, we neither have that ConfigMap (as we use a Secret in version
461+
// v0.7.0) nor do we create it (the new labels aren't there yet, so the selector does not match and
462+
// operatormanager.OperatorManager.UpdateAllManagedOperators does not call InstallOrUpdateOperator)
463+
// we previously aborted here (before the postgresql resource was updated with the new labels), meaning we would
464+
// simply restart the loop without solving the problem.
465+
if cm, err = r.CreatePodEnvironmentConfigMap(ctx, ns.Namespace); err != nil {
466+
return fmt.Errorf("error while creating the missing Pod Environment ConfigMap %v: %w", ns.Namespace, err)
467+
}
468+
log.Info("mising Pod Environment ConfigMap created!")
461469
}
462470
cm.Data = data
463471
if err := r.SvcClient.Update(ctx, cm); err != nil {

pkg/operatormanager/operatormanager.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (m *OperatorManager) InstallOrUpdateOperator(ctx context.Context, namespace
120120
}
121121

122122
// Add our (initially empty) custom pod environment configmap
123-
if err := m.createPodEnvironmentConfigMap(ctx, namespace); err != nil {
123+
if _, err := m.CreatePodEnvironmentConfigMap(ctx, namespace); err != nil {
124124
return fmt.Errorf("error while creating pod environment configmap %v: %w", namespace, err)
125125
}
126126

@@ -462,33 +462,33 @@ func (m *OperatorManager) createNamespace(ctx context.Context, namespace string)
462462
return nil
463463
}
464464

465-
// createPodEnvironmentConfigMap creates a new ConfigMap with additional environment variables for the pods
466-
func (m *OperatorManager) createPodEnvironmentConfigMap(ctx context.Context, namespace string) error {
465+
// CreatePodEnvironmentConfigMap creates a new ConfigMap with additional environment variables for the pods
466+
func (m *OperatorManager) CreatePodEnvironmentConfigMap(ctx context.Context, namespace string) (*corev1.ConfigMap, error) {
467467
ns := types.NamespacedName{
468468
Namespace: namespace,
469469
Name: PodEnvCMName,
470470
}
471-
if err := m.Get(ctx, ns, &corev1.ConfigMap{}); err == nil {
471+
cm := &corev1.ConfigMap{}
472+
if err := m.Get(ctx, ns, cm); err == nil {
472473
// configmap already exists, nothing to do here
473474
// we will update the configmap with the correct S3 config in the postgres controller
474475
m.log.Info("Pod Environment ConfigMap already exists")
475-
return nil
476+
return cm, nil
476477
}
477478

478-
cm := &corev1.ConfigMap{}
479479
if err := m.SetName(cm, PodEnvCMName); err != nil {
480-
return fmt.Errorf("error while setting the name of the new Pod Environment ConfigMap to %v: %w", namespace, err)
480+
return nil, fmt.Errorf("error while setting the name of the new Pod Environment ConfigMap to %v: %w", namespace, err)
481481
}
482482
if err := m.SetNamespace(cm, namespace); err != nil {
483-
return fmt.Errorf("error while setting the namespace of the new Pod Environment ConfigMap to %v: %w", namespace, err)
483+
return nil, fmt.Errorf("error while setting the namespace of the new Pod Environment ConfigMap to %v: %w", namespace, err)
484484
}
485485

486486
if err := m.Create(ctx, cm); err != nil {
487-
return fmt.Errorf("error while creating the new Pod Environment ConfigMap: %w", err)
487+
return nil, fmt.Errorf("error while creating the new Pod Environment ConfigMap: %w", err)
488488
}
489489
m.log.Info("new Pod Environment ConfigMap created")
490490

491-
return nil
491+
return cm, nil
492492
}
493493

494494
func (m *OperatorManager) createOrUpdateSidecarsConfig(ctx context.Context, namespace string) error {

0 commit comments

Comments
 (0)