@@ -8,9 +8,7 @@ package controllers
8
8
9
9
import (
10
10
"context"
11
- "encoding/json"
12
11
"fmt"
13
- "net/url"
14
12
15
13
"github.com/go-logr/logr"
16
14
zalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@@ -74,6 +72,8 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
74
72
return ctrl.Result {}, nil
75
73
}
76
74
75
+ namespace := instance .ToPeripheralResourceNamespace ()
76
+
77
77
// Delete
78
78
if instance .IsBeingDeleted () {
79
79
instance .Status .Description = "Terminating"
@@ -84,7 +84,6 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
84
84
log .Info ("instance being deleted" )
85
85
86
86
matchingLabels := instance .ToZalandoPostgresqlMatchingLabels ()
87
- namespace := instance .ToPeripheralResourceNamespace ()
88
87
89
88
if err := r .deleteCWNP (ctx , instance ); client .IgnoreNotFound (err ) != nil { // todo: remove ignorenotfound
90
89
r .recorder .Event (instance , "Warning" , "Error" , "failed to delete ClusterwideNetworkPolicy" )
@@ -234,112 +233,8 @@ func (r *PostgresReconciler) createOrUpdateZalandoPostgresql(ctx context.Context
234
233
235
234
// ensureZalandoDependencies makes sure Zalando resources are installed in the service-cluster.
236
235
func (r * PostgresReconciler ) ensureZalandoDependencies (ctx context.Context , p * pg.Postgres ) error {
237
- namespace := p .ToPeripheralResourceNamespace ()
238
- isInstalled , err := r .IsOperatorInstalled (ctx , namespace )
239
- if err != nil {
240
- return fmt .Errorf ("error while querying if zalando dependencies are installed: %w" , err )
241
- }
242
-
243
- if ! isInstalled {
244
- if err := r .InstallOrUpdateOperator (ctx , namespace ); err != nil {
245
- return fmt .Errorf ("error while installing zalando dependencies: %w" , err )
246
- }
247
- }
248
-
249
- if err := r .updatePodEnvironmentConfigMap (ctx , p ); err != nil {
250
- return fmt .Errorf ("error while updating backup config: %w" , err )
251
- }
252
-
253
- return nil
254
- }
255
-
256
- func (r * PostgresReconciler ) updatePodEnvironmentConfigMap (ctx context.Context , p * pg.Postgres ) error {
257
- log := r .Log .WithValues ("postgres" , p .UID )
258
- if p .Spec .BackupSecretRef == "" {
259
- log .Info ("No configured backupSecretRef found, skipping configuration of postgres backup" )
260
- return nil
261
- }
262
-
263
- // fetch secret
264
- backupSecret := & v1.Secret {}
265
- backupNamespace := types.NamespacedName {
266
- Name : p .Spec .BackupSecretRef ,
267
- Namespace : p .Namespace ,
268
- }
269
- if err := r .CtrlClient .Get (ctx , backupNamespace , backupSecret ); err != nil {
270
- return fmt .Errorf ("error while getting the backup secret from control plane cluster: %w" , err )
271
- }
272
-
273
- backupConfigJSON , ok := backupSecret .Data [pg .BackupConfigKey ]
274
- if ! ok {
275
- return fmt .Errorf ("no backupConfig stored in the secret" )
276
- }
277
- var backupConfig pg.BackupConfig
278
- err := json .Unmarshal (backupConfigJSON , & backupConfig )
279
- if err != nil {
280
- return fmt .Errorf ("unable to unmarshal backupconfig:%w" , err )
281
- }
282
-
283
- s3url , err := url .Parse (backupConfig .S3Endpoint )
284
- if err != nil {
285
- return fmt .Errorf ("error while parsing the s3 endpoint url in the backup secret: %w" , err )
286
- }
287
- // use the s3 endpoint as provided
288
- awsEndpoint := s3url .String ()
289
- // modify the scheme to 'https+path'
290
- s3url .Scheme = "https+path"
291
- // use the modified s3 endpoint
292
- walES3Endpoint := s3url .String ()
293
- // region
294
- region := backupConfig .S3Region
295
-
296
- // use the rest as provided in the secret
297
- bucketName := backupConfig .S3BucketName
298
- awsAccessKeyID := backupConfig .S3AccessKey
299
- awsSecretAccessKey := backupConfig .S3SecretKey
300
- backupSchedule := backupConfig .Schedule
301
- backupNumToRetain := backupConfig .Retention
302
-
303
- // s3 server side encryption SSE is enabled if the key is given
304
- // TODO our s3 needs a small change to make this work
305
- walgDisableSSE := "true"
306
- walgSSE := ""
307
- if backupConfig .S3EncryptionKey != nil {
308
- walgDisableSSE = "false"
309
- walgSSE = * backupConfig .S3EncryptionKey
310
- }
311
-
312
- // create updated content for pod environment configmap
313
- data := map [string ]string {
314
- "USE_WALG_BACKUP" : "true" ,
315
- "USE_WALG_RESTORE" : "true" ,
316
- "WALE_S3_PREFIX" : "s3://" + bucketName + "/$(SCOPE)" ,
317
- "WALG_S3_PREFIX" : "s3://" + bucketName + "/$(SCOPE)" ,
318
- "CLONE_WALG_S3_PREFIX" : "s3://" + bucketName + "/$(CLONE_SCOPE)" ,
319
- "WALE_BACKUP_THRESHOLD_PERCENTAGE" : "100" ,
320
- "AWS_ENDPOINT" : awsEndpoint ,
321
- "WALE_S3_ENDPOINT" : walES3Endpoint , // same as above, but slightly modified
322
- "AWS_ACCESS_KEY_ID" : awsAccessKeyID ,
323
- "AWS_SECRET_ACCESS_KEY" : awsSecretAccessKey ,
324
- "AWS_S3_FORCE_PATH_STYLE" : "true" ,
325
- "AWS_REGION" : region , // now we can use AWS S3
326
- "WALG_DISABLE_S3_SSE" : walgDisableSSE , // disable server side encryption if key is nil
327
- "WALG_S3_SSE" : walgSSE , // server side encryption key
328
- "BACKUP_SCHEDULE" : backupSchedule ,
329
- "BACKUP_NUM_TO_RETAIN" : backupNumToRetain ,
330
- }
331
-
332
- cm := & v1.ConfigMap {}
333
- ns := types.NamespacedName {
334
- Name : operatormanager .PodEnvCMName ,
335
- Namespace : p .ToPeripheralResourceNamespace (),
336
- }
337
- if err := r .SvcClient .Get (ctx , ns , cm ); err != nil {
338
- return fmt .Errorf ("error while getting the pod environment configmap from service cluster: %w" , err )
339
- }
340
- cm .Data = data
341
- if err := r .SvcClient .Update (ctx , cm ); err != nil {
342
- return fmt .Errorf ("error while updating the pod environment configmap in service cluster: %w" , err )
236
+ if err := r .InstallOrUpdateOperator (ctx , p ); err != nil {
237
+ return fmt .Errorf ("error while installing zalando dependencies: %w" , err )
343
238
}
344
239
345
240
return nil
0 commit comments