@@ -249,8 +249,14 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
249
249
log .V (debugLogLevel ).Info ("finalizer added" )
250
250
}
251
251
252
+ backupConfig , err := r .getBackupConfig (ctx , instance .Namespace , instance .Spec .BackupSecretRef )
253
+ if err != nil {
254
+ r .recorder .Eventf (instance , "Warning" , "Self-Reconciliation" , "failed to fetch backupConfig: %v" , err )
255
+ return ctrl.Result {}, fmt .Errorf ("failed to fetch backupConfig: %w" , err )
256
+ }
257
+
252
258
// Check if zalando dependencies are installed. If not, install them.
253
- if err := r .ensureZalandoDependencies (log , ctx , instance ); err != nil {
259
+ if err := r .ensureZalandoDependencies (log , ctx , instance , backupConfig ); err != nil {
254
260
r .recorder .Eventf (instance , "Warning" , "Error" , "failed to install operator: %v" , err )
255
261
return ctrl.Result {}, fmt .Errorf ("error while ensuring Zalando dependencies: %w" , err )
256
262
}
@@ -306,7 +312,7 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
306
312
}
307
313
308
314
// Add service monitor for our exporter sidecar
309
- err : = r .createOrUpdateExporterSidecarServiceMonitor (log , ctx , namespace , instance )
315
+ err = r .createOrUpdateExporterSidecarServiceMonitor (log , ctx , namespace , instance )
310
316
if err != nil {
311
317
return ctrl.Result {}, fmt .Errorf ("error while creating sidecars servicemonitor %v: %w" , namespace , err )
312
318
}
@@ -339,7 +345,7 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
339
345
}
340
346
341
347
if r .EnableWalGExporter {
342
- if err := r .createOrUpdateWalGExporterDeployment (log , ctx , namespace , instance ); err != nil {
348
+ if err := r .createOrUpdateWalGExporterDeployment (log , ctx , namespace , instance , backupConfig ); err != nil {
343
349
r .recorder .Eventf (instance , "Warning" , "Error" , "failed to deploy wal-g-exporter: %v" , err )
344
350
return ctrl.Result {}, fmt .Errorf ("error while deploying wal-g-exporter %v: %w" , namespace , err )
345
351
}
@@ -477,7 +483,7 @@ func (r *PostgresReconciler) deleteUserPasswordsSecret(ctx context.Context, inst
477
483
}
478
484
479
485
// ensureZalandoDependencies makes sure Zalando resources are installed in the service-cluster.
480
- func (r * PostgresReconciler ) ensureZalandoDependencies (log logr.Logger , ctx context.Context , p * pg.Postgres ) error {
486
+ func (r * PostgresReconciler ) ensureZalandoDependencies (log logr.Logger , ctx context.Context , p * pg.Postgres , b * pg. BackupConfig ) error {
481
487
namespace := p .ToPeripheralResourceNamespace ()
482
488
isInstalled , err := r .OperatorManager .IsOperatorInstalled (ctx , namespace )
483
489
if err != nil {
@@ -490,7 +496,7 @@ func (r *PostgresReconciler) ensureZalandoDependencies(log logr.Logger, ctx cont
490
496
}
491
497
}
492
498
493
- if err := r .updatePodEnvironmentConfigMap (log , ctx , p ); err != nil {
499
+ if err := r .updatePodEnvironmentConfigMap (log , ctx , p , b ); err != nil {
494
500
return fmt .Errorf ("error while updating backup config: %w" , err )
495
501
}
496
502
@@ -501,18 +507,13 @@ func (r *PostgresReconciler) ensureZalandoDependencies(log logr.Logger, ctx cont
501
507
return nil
502
508
}
503
509
504
- func (r * PostgresReconciler ) updatePodEnvironmentConfigMap (log logr.Logger , ctx context.Context , p * pg.Postgres ) error {
505
- if p . Spec . BackupSecretRef == "" {
506
- log .Info ("No configured backupSecretRef found, skipping configuration of postgres backup" )
510
+ func (r * PostgresReconciler ) updatePodEnvironmentConfigMap (log logr.Logger , ctx context.Context , p * pg.Postgres , b * pg. BackupConfig ) error {
511
+ if b == nil {
512
+ log .Info ("No backupConfig found, skipping configuration of postgres backup" )
507
513
return nil
508
514
}
509
515
510
- backupConfig , err := r .getBackupConfig (ctx , p .Namespace , p .Spec .BackupSecretRef )
511
- if err != nil {
512
- return err
513
- }
514
-
515
- s3url , err := url .Parse (backupConfig .S3Endpoint )
516
+ s3url , err := url .Parse (b .S3Endpoint )
516
517
if err != nil {
517
518
return fmt .Errorf ("error while parsing the s3 endpoint url in the backup secret: %w" , err )
518
519
}
@@ -523,7 +524,7 @@ func (r *PostgresReconciler) updatePodEnvironmentConfigMap(log logr.Logger, ctx
523
524
// use the modified s3 endpoint
524
525
walES3Endpoint := s3url .String ()
525
526
// region
526
- region := backupConfig .S3Region
527
+ region := b .S3Region
527
528
528
529
// set the WALG_UPLOAD_DISK_CONCURRENCY based on the configured cpu limits
529
530
q , err := resource .ParseQuantity (p .Spec .Size .CPU )
@@ -540,9 +541,9 @@ func (r *PostgresReconciler) updatePodEnvironmentConfigMap(log logr.Logger, ctx
540
541
downloadConcurrency := "32"
541
542
542
543
// use the rest as provided in the secret
543
- bucketName := backupConfig .S3BucketName
544
- backupSchedule := backupConfig .Schedule
545
- backupNumToRetain := backupConfig .Retention
544
+ bucketName := b .S3BucketName
545
+ backupSchedule := b .Schedule
546
+ backupNumToRetain := b .Retention
546
547
547
548
// s3 server side encryption SSE is disabled
548
549
// we use client side encryption
@@ -2029,7 +2030,12 @@ func (r *PostgresReconciler) createOrUpdateCertificate(log logr.Logger, ctx cont
2029
2030
}
2030
2031
2031
2032
// createOrUpdateWalGExporterDeployment ensures the deployment for the wal-g-exporter
2032
- func (r * PostgresReconciler ) createOrUpdateWalGExporterDeployment (log logr.Logger , ctx context.Context , namespace string , instance * pg.Postgres ) error {
2033
+ func (r * PostgresReconciler ) createOrUpdateWalGExporterDeployment (log logr.Logger , ctx context.Context , namespace string , instance * pg.Postgres , b * pg.BackupConfig ) error {
2034
+ if b == nil {
2035
+ log .Info ("No backupConfig found, skipping configuration of wa-l-exporter" )
2036
+ return nil
2037
+ }
2038
+
2033
2039
labels := map [string ]string {
2034
2040
"app.kubernetes.io/name" : walGExporterName ,
2035
2041
pg .UIDLabelName : string (instance .UID ),
@@ -2044,8 +2050,9 @@ func (r *PostgresReconciler) createOrUpdateWalGExporterDeployment(log logr.Logge
2044
2050
matchLabels := labels
2045
2051
2046
2052
var replicas int32 = 1
2047
- var uid int64 = 101
2048
- var gid int64 = 101
2053
+
2054
+ var uid int64 = 65534
2055
+ var gid int64 = 65534
2049
2056
2050
2057
deploy := & appsv1.Deployment {
2051
2058
ObjectMeta : metav1.ObjectMeta {
@@ -2143,15 +2150,8 @@ func (r *PostgresReconciler) createOrUpdateWalGExporterDeployment(log logr.Logge
2143
2150
},
2144
2151
},
2145
2152
{
2146
- Name : "WALG_S3_PREFIX" ,
2147
- ValueFrom : & corev1.EnvVarSource {
2148
- ConfigMapKeyRef : & corev1.ConfigMapKeySelector {
2149
- Key : "WALG_S3_PREFIX" ,
2150
- LocalObjectReference : corev1.LocalObjectReference {
2151
- Name : operatormanager .PodEnvCMName ,
2152
- },
2153
- },
2154
- },
2153
+ Name : "WALG_S3_PREFIX" ,
2154
+ Value : "s3://" + b .S3BucketName + "/" + instance .ToPeripheralResourceName (),
2155
2155
},
2156
2156
},
2157
2157
Image : r .WalGExporterImage ,
0 commit comments