Skip to content

Commit cd0968e

Browse files
authored
K8SPSMDB-1056: S3 storage delete-backup finalizer without secrets (#1524)
* Check for secret only if CredentialSecret filed is persent. * Update demand-backup-eks-credentials to delete the backup with finalizer.
1 parent 1e74f86 commit cd0968e

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

e2e-tests/demand-backup-eks-credentials/conf/backup-aws-s3.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
apiVersion: psmdb.percona.com/v1
22
kind: PerconaServerMongoDBBackup
33
metadata:
4+
finalizers:
5+
- delete-backup
46
name: backup-aws-s3
57
spec:
68
clusterName: some-name

e2e-tests/demand-backup-eks-credentials/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace"
6868
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace"
6969
compare_mongo_cmd "find" "myApp:myPass@$cluster-2.$cluster.$namespace"
7070

71+
desc 'delete backup and check if it is removed from bucket -- aws-s3'
72+
kubectl_bin delete psmdb-backup --all
73+
check_backup_deletion "https://s3.amazonaws.com/${backup_dest_aws}" "aws-s3"
74+
7175
destroy $namespace
7276

7377
desc 'test passed'

pkg/controller/perconaservermongodbbackup/perconaservermongodbbackup_controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ func (r *ReconcilePerconaServerMongoDBBackup) getPBMStorage(ctx context.Context,
258258
}
259259
return azure.New(azureConf, nil)
260260
case cr.Status.S3 != nil:
261-
if cr.Status.S3.CredentialsSecret == "" {
262-
return nil, errors.New("no s3 credentials specified for the secret name")
263-
}
264261
s3Conf := s3.Conf{
265262
Region: cr.Status.S3.Region,
266263
EndpointURL: cr.Status.S3.EndpointURL,
@@ -271,9 +268,16 @@ func (r *ReconcilePerconaServerMongoDBBackup) getPBMStorage(ctx context.Context,
271268
StorageClass: cr.Status.S3.StorageClass,
272269
InsecureSkipTLSVerify: cr.Status.S3.InsecureSkipTLSVerify,
273270
}
274-
s3secret, err := secret(ctx, r.client, cr.Namespace, cr.Status.S3.CredentialsSecret)
275-
if err != nil {
276-
return nil, errors.Wrap(err, "getting s3 credentials secret name")
271+
272+
if cr.Status.S3.CredentialsSecret != "" {
273+
s3secret, err := secret(ctx, r.client, cr.Namespace, cr.Status.S3.CredentialsSecret)
274+
if err != nil {
275+
return nil, errors.Wrap(err, "getting s3 credentials secret name")
276+
}
277+
s3Conf.Credentials = s3.Credentials{
278+
AccessKeyID: string(s3secret.Data[backup.AWSAccessKeySecretKey]),
279+
SecretAccessKey: string(s3secret.Data[backup.AWSSecretAccessKeySecretKey]),
280+
}
277281
}
278282

279283
if len(cr.Status.S3.ServerSideEncryption.SSECustomerAlgorithm) != 0 {
@@ -319,10 +323,6 @@ func (r *ReconcilePerconaServerMongoDBBackup) getPBMStorage(ctx context.Context,
319323
}
320324
}
321325

322-
s3Conf.Credentials = s3.Credentials{
323-
AccessKeyID: string(s3secret.Data[backup.AWSAccessKeySecretKey]),
324-
SecretAccessKey: string(s3secret.Data[backup.AWSSecretAccessKeySecretKey]),
325-
}
326326
return s3.New(s3Conf, nil)
327327
default:
328328
return nil, errors.New("no storage info in backup status")

0 commit comments

Comments
 (0)