Skip to content

Commit 1127c61

Browse files
authored
K8SPSMDB-903: Add bucket/container to destination (#1307)
* Add s3 bucket to destination in status. * Update tests. * Add Azure container to destination. * Prefix .state.destination with protocol schema. * Fix incomplete destination. * Fix destination * Fix destination. * Fix tests. * Fix upgrade and upgrade-sharded tests.
1 parent 4b49361 commit 1127c61

File tree

10 files changed

+52
-39
lines changed

10 files changed

+52
-39
lines changed

e2e-tests/data-at-rest-encryption/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ desc "check backup and restore -- minio"
5959
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
6060
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
6161
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
62-
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://operator-testing/${backup_dest_minio}/rs0/ \
62+
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://${backup_dest_minio}/rs0/ \
6363
| grep myApp.test.gz
6464
run_mongos 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster-mongos.$namespace"
6565
compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace" "-2nd"
@@ -70,7 +70,7 @@ compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace"
7070
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
7171
desc 'check backup and restore -- gcp-cs'
7272
backup_dest_gcp=$(get_backup_dest "$backup_name_gcp")
73-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
73+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
7474
run_mongos 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster-mongos.$namespace"
7575
compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace" "-2nd"
7676
run_restore "$backup_name_gcp"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sleep 5
5757

5858
desc 'check backup and restore -- aws-s3'
5959
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
60-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
60+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
6161
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
6262
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
6363
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"

e2e-tests/demand-backup-sharded/run

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ sleep 5
114114
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
115115
desc 'check backup and restore -- aws-s3'
116116
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
117-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
118-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs1/myApp1.test.gz" | gunzip >/dev/null
119-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs2/myApp2.test.gz" | gunzip >/dev/null
117+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
118+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs1/myApp1.test.gz" | gunzip >/dev/null
119+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs2/myApp2.test.gz" | gunzip >/dev/null
120120
insert_data "100501"
121121
check_data "-2nd"
122122
run_restore "$backup_name_aws"
@@ -125,9 +125,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
125125

126126
desc 'check backup and restore -- gcp-cs'
127127
backup_dest_gcp=$(get_backup_dest "$backup_name_gcp")
128-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
129-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs1/myApp1.test.gz" | gunzip >/dev/null
130-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs2/myApp2.test.gz" | gunzip >/dev/null
128+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
129+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs1/myApp1.test.gz" | gunzip >/dev/null
130+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs2/myApp2.test.gz" | gunzip >/dev/null
131131
insert_data "100501"
132132
check_data "-2nd"
133133
run_restore "$backup_name_gcp"
@@ -136,9 +136,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
136136

137137
desc 'check backup and restore -- azure-blob'
138138
backup_dest_azure=$(get_backup_dest "$backup_name_azure")
139-
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
140-
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs1/myApp1.test.gz" | gunzip >/dev/null
141-
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs2/myApp2.test.gz" | gunzip >/dev/null
139+
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
140+
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs1/myApp1.test.gz" | gunzip >/dev/null
141+
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs2/myApp2.test.gz" | gunzip >/dev/null
142142
insert_data "100501"
143143
check_data "-2nd"
144144
run_restore "$backup_name_azure"
@@ -150,7 +150,7 @@ desc 'check backup and restore -- minio'
150150
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
151151
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
152152
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
153-
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls "s3://operator-testing/${backup_dest_minio}/rs0/" \
153+
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls "s3://${backup_dest_minio}/rs0/" \
154154
| grep "myApp.test.gz"
155155
insert_data "100501"
156156
check_data "-2nd"
@@ -171,9 +171,9 @@ if [[ $backup_exists -eq 1 ]]; then
171171
fi
172172

173173
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
174-
check_backup_deletion "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}" "aws-s3"
175-
check_backup_deletion "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}" "gcp-cs"
176-
check_backup_deletion "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}" "azure-blob"
174+
check_backup_deletion "https://s3.amazonaws.com/${backup_dest_aws}" "aws-s3"
175+
check_backup_deletion "https://storage.googleapis.com/${backup_dest_gcp}" "gcp-cs"
176+
check_backup_deletion "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}" "azure-blob"
177177
fi
178178

179179
desc 'check for passwords leak'

e2e-tests/demand-backup/conf/restore-backupsource.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
clusterName: some-name
77
storageName:
88
backupSource:
9-
destination: s3://operator-testing/BACKUP-NAME
9+
destination: s3://BACKUP-NAME
1010
s3:
1111
credentialsSecret: minio-secret
1212
region: us-east-1

e2e-tests/demand-backup/run

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,25 @@ sleep 5
9898
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
9999
desc 'check backup and restore -- aws-s3'
100100
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
101-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
101+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
102102
run_recovery_check "$backup_name_aws" "$cluster"
103103

104104
desc 'check backup and restore -- gcp-cs'
105105
backup_dest_gcp=$(get_backup_dest "$backup_name_gcp")
106-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
106+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
107107
run_recovery_check "$backup_name_gcp" "$cluster"
108108

109109
desc 'check backup and restore -- azure-blob'
110110
backup_dest_azure=$(get_backup_dest "$backup_name_azure")
111-
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
111+
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
112112
run_recovery_check "$backup_name_azure" "$cluster"
113113
fi
114114

115115
desc 'check backup and restore -- minio'
116116
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
117117
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
118118
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
119-
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://operator-testing/${backup_dest_minio}/rs0/ \
119+
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://${backup_dest_minio}/rs0/ \
120120
| grep myApp.test.gz
121121
run_recovery_check "$backup_name_minio" "$cluster"
122122

@@ -140,9 +140,9 @@ if [[ $backup_exists -eq 1 ]]; then
140140
fi
141141

142142
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
143-
check_backup_deletion "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}" "aws-s3"
144-
check_backup_deletion "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}" "gcp-cs"
145-
check_backup_deletion "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}" "azure-blob"
143+
check_backup_deletion "https://s3.amazonaws.com/${backup_dest_aws}" "aws-s3"
144+
check_backup_deletion "https://storage.googleapis.com/${backup_dest_gcp}" "gcp-cs"
145+
check_backup_deletion "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}" "azure-blob"
146146
fi
147147

148148
desc 'checking backup deletion without cr'
@@ -175,9 +175,9 @@ if [[ $backup_exists -eq 1 ]]; then
175175
fi
176176

177177
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
178-
check_backup_deletion "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}" "aws-s3"
179-
check_backup_deletion "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}" "gcp-cs"
180-
check_backup_deletion "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}" "azure-blob"
178+
check_backup_deletion "https://s3.amazonaws.com/${backup_dest_aws}" "aws-s3"
179+
check_backup_deletion "https://storage.googleapis.com/${backup_dest_gcp}" "gcp-cs"
180+
check_backup_deletion "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}" "azure-blob"
181181
fi
182182

183183
desc 'check for passwords leak'

e2e-tests/functions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ run_restore_backupsource() {
257257
if [ -z "$storageName" ]; then
258258
cat $test_dir/conf/restore-backupsource.yml \
259259
| $sed -e "s/name:/name: restore-$backupName/" \
260-
| $sed -e "s/BACKUP-NAME/$backupDest/" \
260+
| $sed -e "s|BACKUP-NAME|$backupDest|" \
261261
| $sed -e "/storageName/d" \
262262
| kubectl_bin apply -f -
263263

@@ -266,7 +266,7 @@ run_restore_backupsource() {
266266

267267
cat $test_dir/conf/restore-backupsource.yml \
268268
| $sed -e "s/name:/name: restore-$backupName/" \
269-
| $sed -e "s/BACKUP-NAME/$backupDest/" \
269+
| $sed -e "s|BACKUP-NAME|$backupDest|" \
270270
| $sed -e "s/storageName:/storageName: $storageName/" \
271271
| kubectl_bin apply -f -
272272
}
@@ -935,7 +935,7 @@ get_backup_dest() {
935935
local backup_name=$1
936936

937937
kubectl_bin get psmdb-backup $backup_name -o jsonpath='{.status.destination}' \
938-
| sed -e 's/.json$//'
938+
| sed -e 's/.json$//' | sed "s|s3://||" | sed "s|azure://||"
939939
}
940940

941941
get_service_endpoint() {

e2e-tests/pitr/conf/restore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ spec:
1010
type:
1111
date:
1212
backupSource:
13-
destination: s3://operator-testing/BACKUP-NAME
13+
destination: s3://BACKUP-NAME

e2e-tests/pitr/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ check_recovery() {
8181
| $sed -e "/backupName/d" \
8282
| $sed -e "s/type:/type: $restore_type/" \
8383
| if [ -z "$restore_date" ]; then $sed -e "/date:/d"; else $sed -e "s/date:/date: $restore_date/"; fi \
84-
| $sed -e "s/BACKUP-NAME/$backup_dest/" \
84+
| $sed -e "s|BACKUP-NAME|$backup_dest|" \
8585
| kubectl_bin apply -f -
8686
fi
8787
wait_restore "$backup_name" "$cluster_name"

e2e-tests/scheduled-backup/run

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ desc 'check backup and restore -- minio'
9292
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
9393
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
9494
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
95-
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://operator-testing/${backup_dest_minio}/rs0/ \
95+
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://${backup_dest_minio}/rs0/ \
9696
| grep "myApp.test.gz"
9797
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
9898
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
@@ -107,7 +107,7 @@ compare_mongo_cmd "find" "myApp:myPass@$cluster-2.$cluster.$namespace"
107107
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
108108
desc 'check backup and restore -- aws-s3'
109109
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
110-
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
110+
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
111111
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
112112
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
113113
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
@@ -120,7 +120,7 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
120120

121121
desc 'check backup and restore -- gcp-cs'
122122
backup_dest_gcp=$(get_backup_dest "$backup_name_gcp")
123-
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
123+
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
124124
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
125125
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
126126
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
@@ -133,7 +133,7 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
133133

134134
desc 'check backup and restore -- azure-blob'
135135
backup_dest_azure=$(get_backup_dest "$backup_name_azure")
136-
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
136+
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
137137
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
138138
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
139139
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"

pkg/controller/perconaservermongodbbackup/backup.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package perconaservermongodbbackup
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
"github.com/percona/percona-backup-mongodb/pbm"
@@ -90,16 +91,28 @@ func (b *Backup) Start(ctx context.Context, k8sclient client.Client, cluster *ap
9091
switch stg.Type {
9192
case api.BackupStorageS3:
9293
status.S3 = &stg.S3
94+
95+
status.Destination = stg.S3.Bucket
96+
9397
if stg.S3.Prefix != "" {
94-
status.Destination = stg.S3.Prefix + "/"
98+
status.Destination = stg.S3.Bucket + "/" + stg.S3.Prefix
99+
}
100+
if !strings.HasPrefix(stg.S3.Bucket, "s3://") {
101+
status.Destination = "s3://" + status.Destination
95102
}
96103
case api.BackupStorageAzure:
97104
status.Azure = &stg.Azure
105+
106+
status.Destination = stg.Azure.Container
107+
98108
if stg.Azure.Prefix != "" {
99-
status.Destination = stg.Azure.Prefix + "/"
109+
status.Destination = stg.Azure.Container + "/" + stg.Azure.Prefix
110+
}
111+
if !strings.HasPrefix(stg.Azure.Container, "azure://") {
112+
status.Destination = "azure://" + status.Destination
100113
}
101114
}
102-
status.Destination += status.PBMname
115+
status.Destination += "/" + status.PBMname
103116

104117
return status, nil
105118
}

0 commit comments

Comments
 (0)