Skip to content

Commit 2d60725

Browse files
authored
Revert "Use Secret instead of ConfigMap for pod env" (#382)
This reverts commit d5176b0.
1 parent 364ed9a commit 2d60725

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

controllers/postgres_controller.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,14 @@ func (r *PostgresReconciler) ensureZalandoDependencies(ctx context.Context, p *p
376376
}
377377
}
378378

379-
if err := r.updatePodEnvironmentSecret(ctx, p); err != nil {
379+
if err := r.updatePodEnvironmentConfigMap(ctx, p); err != nil {
380380
return fmt.Errorf("error while updating backup config: %w", err)
381381
}
382382

383383
return nil
384384
}
385385

386-
func (r *PostgresReconciler) updatePodEnvironmentSecret(ctx context.Context, p *pg.Postgres) error {
386+
func (r *PostgresReconciler) updatePodEnvironmentConfigMap(ctx context.Context, p *pg.Postgres) error {
387387
log := r.Log.WithValues("postgres", p.UID)
388388
if p.Spec.BackupSecretRef == "" {
389389
log.Info("No configured backupSecretRef found, skipping configuration of postgres backup")
@@ -424,37 +424,37 @@ func (r *PostgresReconciler) updatePodEnvironmentSecret(ctx context.Context, p *
424424
walgSSE = *backupConfig.S3EncryptionKey
425425
}
426426

427-
// create updated content for pod environment secret
428-
data := map[string][]byte{
429-
"USE_WALG_BACKUP": []byte("true"),
430-
"USE_WALG_RESTORE": []byte("true"),
431-
"WALE_S3_PREFIX": []byte("s3://" + bucketName + "/$(SCOPE)"),
432-
"WALG_S3_PREFIX": []byte("s3://" + bucketName + "/$(SCOPE)"),
433-
"CLONE_WALG_S3_PREFIX": []byte("s3://" + bucketName + "/$(CLONE_SCOPE)"),
434-
"WALE_BACKUP_THRESHOLD_PERCENTAGE": []byte("100"),
435-
"AWS_ENDPOINT": []byte(awsEndpoint),
436-
"WALE_S3_ENDPOINT": []byte(walES3Endpoint), // same as above, but slightly modified
437-
"AWS_ACCESS_KEY_ID": []byte(awsAccessKeyID),
438-
"AWS_SECRET_ACCESS_KEY": []byte(awsSecretAccessKey),
439-
"AWS_S3_FORCE_PATH_STYLE": []byte("true"),
440-
"AWS_REGION": []byte(region), // now we can use AWS S3
441-
"WALG_DISABLE_S3_SSE": []byte(walgDisableSSE), // disable server side encryption if key is nil
442-
"WALG_S3_SSE": []byte(walgSSE), // server side encryption key
443-
"BACKUP_SCHEDULE": []byte(backupSchedule),
444-
"BACKUP_NUM_TO_RETAIN": []byte(backupNumToRetain),
445-
}
446-
447-
s := &corev1.Secret{}
427+
// create updated content for pod environment configmap
428+
data := map[string]string{
429+
"USE_WALG_BACKUP": "true",
430+
"USE_WALG_RESTORE": "true",
431+
"WALE_S3_PREFIX": "s3://" + bucketName + "/$(SCOPE)",
432+
"WALG_S3_PREFIX": "s3://" + bucketName + "/$(SCOPE)",
433+
"CLONE_WALG_S3_PREFIX": "s3://" + bucketName + "/$(CLONE_SCOPE)",
434+
"WALE_BACKUP_THRESHOLD_PERCENTAGE": "100",
435+
"AWS_ENDPOINT": awsEndpoint,
436+
"WALE_S3_ENDPOINT": walES3Endpoint, // same as above, but slightly modified
437+
"AWS_ACCESS_KEY_ID": awsAccessKeyID,
438+
"AWS_SECRET_ACCESS_KEY": awsSecretAccessKey,
439+
"AWS_S3_FORCE_PATH_STYLE": "true",
440+
"AWS_REGION": region, // now we can use AWS S3
441+
"WALG_DISABLE_S3_SSE": walgDisableSSE, // disable server side encryption if key is nil
442+
"WALG_S3_SSE": walgSSE, // server side encryption key
443+
"BACKUP_SCHEDULE": backupSchedule,
444+
"BACKUP_NUM_TO_RETAIN": backupNumToRetain,
445+
}
446+
447+
cm := &corev1.ConfigMap{}
448448
ns := types.NamespacedName{
449-
Name: operatormanager.PodEnvSecretName,
449+
Name: operatormanager.PodEnvCMName,
450450
Namespace: p.ToPeripheralResourceNamespace(),
451451
}
452-
if err := r.SvcClient.Get(ctx, ns, s); err != nil {
453-
return fmt.Errorf("error while getting the pod environment secret from service cluster: %w", err)
452+
if err := r.SvcClient.Get(ctx, ns, cm); err != nil {
453+
return fmt.Errorf("error while getting the pod environment configmap from service cluster: %w", err)
454454
}
455-
s.Data = data
456-
if err := r.SvcClient.Update(ctx, s); err != nil {
457-
return fmt.Errorf("error while updating the pod environment secret in service cluster: %w", err)
455+
cm.Data = data
456+
if err := r.SvcClient.Update(ctx, cm); err != nil {
457+
return fmt.Errorf("error while updating the pod environment configmap in service cluster: %w", err)
458458
}
459459

460460
return nil

pkg/operatormanager/operatormanager.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const (
3535
// TODO: use different account for operator and database
3636
serviceAccountName string = "postgres-operator"
3737

38-
// PodEnvSecretName Name of the pod environment secret to create and use
39-
PodEnvSecretName string = "postgres-pod-config" //nolint:gosec
38+
// PodEnvCMName Name of the pod environment configmap to create and use
39+
PodEnvCMName string = "postgres-pod-config"
4040

4141
operatorPodLabelName string = "name"
4242
operatorPodLabelValue string = "postgres-operator"
@@ -117,9 +117,9 @@ func (m *OperatorManager) InstallOrUpdateOperator(ctx context.Context, namespace
117117
return fmt.Errorf("error while ensuring the existence of namespace %v: %w", namespace, err)
118118
}
119119

120-
// Add our (initially empty) custom pod environment secret
121-
if err := m.createPodEnvironmentSecret(ctx, namespace); err != nil {
122-
return fmt.Errorf("error while creating pod environment secret %v: %w", namespace, err)
120+
// Add our (initially empty) custom pod environment configmap
121+
if err := m.createPodEnvironmentConfigMap(ctx, namespace); err != nil {
122+
return fmt.Errorf("error while creating pod environment configmap %v: %w", namespace, err)
123123
}
124124

125125
// Add our sidecars configmap
@@ -239,7 +239,7 @@ func (m *OperatorManager) UninstallOperator(ctx context.Context, namespace strin
239239
}
240240

241241
// delete the pod environment configmap
242-
if err := m.deletePodEnvironmentSecret(ctx, namespace); client.IgnoreNotFound(err) != nil {
242+
if err := m.deletePodEnvironmentConfigMap(ctx, namespace); client.IgnoreNotFound(err) != nil {
243243
return fmt.Errorf("error while deleting pod environment configmap: %w", err)
244244
}
245245

@@ -392,8 +392,8 @@ func (m *OperatorManager) editConfigMap(cm *corev1.ConfigMap, namespace string,
392392
cm.Data["watched_namespace"] = namespace
393393
// TODO don't use the same serviceaccount for operator and databases, see #88
394394
cm.Data["pod_service_account_name"] = serviceAccountName
395-
// set the reference to our custom pod environment secret
396-
cm.Data["pod_environment_secret"] = PodEnvSecretName
395+
// set the reference to our custom pod environment configmap
396+
cm.Data["pod_environment_configmap"] = PodEnvCMName
397397
// set the list of inherited labels that will be passed on to the pods
398398
s := []string{pg.TenantLabelName, pg.ProjectIDLabelName, pg.UIDLabelName, pg.NameLabelName}
399399
// TODO maybe use a precompiled string here
@@ -460,31 +460,31 @@ func (m *OperatorManager) createNamespace(ctx context.Context, namespace string)
460460
return nil
461461
}
462462

463-
// createPodEnvironmentSecret creates a new Secret with additional environment variables for the pods
464-
func (m *OperatorManager) createPodEnvironmentSecret(ctx context.Context, namespace string) error {
463+
// createPodEnvironmentConfigMap creates a new ConfigMap with additional environment variables for the pods
464+
func (m *OperatorManager) createPodEnvironmentConfigMap(ctx context.Context, namespace string) error {
465465
ns := types.NamespacedName{
466466
Namespace: namespace,
467-
Name: PodEnvSecretName,
467+
Name: PodEnvCMName,
468468
}
469-
if err := m.Get(ctx, ns, &corev1.Secret{}); err == nil {
470-
// secret already exists, nothing to do here
471-
// we will update the secret with the correct S3 config in the postgres controller
472-
m.log.Info("Pod Environment Secret already exists")
469+
if err := m.Get(ctx, ns, &corev1.ConfigMap{}); err == nil {
470+
// configmap already exists, nothing to do here
471+
// we will update the configmap with the correct S3 config in the postgres controller
472+
m.log.Info("Pod Environment ConfigMap already exists")
473473
return nil
474474
}
475475

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

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

489489
return nil
490490
}
@@ -560,18 +560,18 @@ func (m *OperatorManager) createOrUpdateSidecarsConfigMap(ctx context.Context, n
560560
return nil
561561
}
562562

563-
func (m *OperatorManager) deletePodEnvironmentSecret(ctx context.Context, namespace string) error {
564-
s := &corev1.Secret{}
565-
if err := m.SetName(s, PodEnvSecretName); err != nil {
566-
return fmt.Errorf("error while setting the name of the Pod Environment Secret to delete to %v: %w", PodEnvSecretName, err)
563+
func (m *OperatorManager) deletePodEnvironmentConfigMap(ctx context.Context, namespace string) error {
564+
cm := &corev1.ConfigMap{}
565+
if err := m.SetName(cm, PodEnvCMName); err != nil {
566+
return fmt.Errorf("error while setting the name of the Pod Environment ConfigMap to delete to %v: %w", PodEnvCMName, err)
567567
}
568-
if err := m.SetNamespace(s, namespace); err != nil {
569-
return fmt.Errorf("error while setting the namespace of the Pod Environment Secret to delete to %v: %w", namespace, err)
568+
if err := m.SetNamespace(cm, namespace); err != nil {
569+
return fmt.Errorf("error while setting the namespace of the Pod Environment ConfigMap to delete to %v: %w", namespace, err)
570570
}
571-
if err := m.Delete(ctx, s); err != nil {
572-
return fmt.Errorf("error while deleting the Pod Environment Secret: %w", err)
571+
if err := m.Delete(ctx, cm); err != nil {
572+
return fmt.Errorf("error while deleting the Pod Environment ConfigMap: %w", err)
573573
}
574-
m.log.Info("Pod Environment Secret deleted")
574+
m.log.Info("Pod Environment ConfigMap deleted")
575575

576576
return nil
577577
}

0 commit comments

Comments
 (0)