Skip to content

Commit

Permalink
K8SPSMDB-903: Add bucket/container to destination (#1307)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
inelpandzic authored Sep 21, 2023
1 parent 4b49361 commit 1127c61
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 39 deletions.
4 changes: 2 additions & 2 deletions e2e-tests/data-at-rest-encryption/run
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ desc "check backup and restore -- minio"
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://operator-testing/${backup_dest_minio}/rs0/ \
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://${backup_dest_minio}/rs0/ \
| grep myApp.test.gz
run_mongos 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster-mongos.$namespace"
compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace" "-2nd"
Expand All @@ -70,7 +70,7 @@ compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace"
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
desc 'check backup and restore -- gcp-cs'
backup_dest_gcp=$(get_backup_dest "$backup_name_gcp")
curl -s "https://storage.googleapis.com/operator-testing/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
run_mongos 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster-mongos.$namespace"
compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace" "-2nd"
run_restore "$backup_name_gcp"
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/demand-backup-eks-credentials/run
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sleep 5

desc 'check backup and restore -- aws-s3'
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
Expand Down
26 changes: 13 additions & 13 deletions e2e-tests/demand-backup-sharded/run
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ sleep 5
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
desc 'check backup and restore -- aws-s3'
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs1/myApp1.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs2/myApp2.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs1/myApp1.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs2/myApp2.test.gz" | gunzip >/dev/null
insert_data "100501"
check_data "-2nd"
run_restore "$backup_name_aws"
Expand All @@ -125,9 +125,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then

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

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

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

desc 'check for passwords leak'
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/demand-backup/conf/restore-backupsource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec:
clusterName: some-name
storageName:
backupSource:
destination: s3://operator-testing/BACKUP-NAME
destination: s3://BACKUP-NAME
s3:
credentialsSecret: minio-secret
region: us-east-1
Expand Down
20 changes: 10 additions & 10 deletions e2e-tests/demand-backup/run
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ sleep 5
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
desc 'check backup and restore -- aws-s3'
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
run_recovery_check "$backup_name_aws" "$cluster"

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

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

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

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

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

desc 'checking backup deletion without cr'
Expand Down Expand Up @@ -175,9 +175,9 @@ if [[ $backup_exists -eq 1 ]]; then
fi

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

desc 'check for passwords leak'
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ run_restore_backupsource() {
if [ -z "$storageName" ]; then
cat $test_dir/conf/restore-backupsource.yml \
| $sed -e "s/name:/name: restore-$backupName/" \
| $sed -e "s/BACKUP-NAME/$backupDest/" \
| $sed -e "s|BACKUP-NAME|$backupDest|" \
| $sed -e "/storageName/d" \
| kubectl_bin apply -f -

Expand All @@ -266,7 +266,7 @@ run_restore_backupsource() {

cat $test_dir/conf/restore-backupsource.yml \
| $sed -e "s/name:/name: restore-$backupName/" \
| $sed -e "s/BACKUP-NAME/$backupDest/" \
| $sed -e "s|BACKUP-NAME|$backupDest|" \
| $sed -e "s/storageName:/storageName: $storageName/" \
| kubectl_bin apply -f -
}
Expand Down Expand Up @@ -935,7 +935,7 @@ get_backup_dest() {
local backup_name=$1

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

get_service_endpoint() {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/pitr/conf/restore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ spec:
type:
date:
backupSource:
destination: s3://operator-testing/BACKUP-NAME
destination: s3://BACKUP-NAME
2 changes: 1 addition & 1 deletion e2e-tests/pitr/run
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ check_recovery() {
| $sed -e "/backupName/d" \
| $sed -e "s/type:/type: $restore_type/" \
| if [ -z "$restore_date" ]; then $sed -e "/date:/d"; else $sed -e "s/date:/date: $restore_date/"; fi \
| $sed -e "s/BACKUP-NAME/$backup_dest/" \
| $sed -e "s|BACKUP-NAME|$backup_dest|" \
| kubectl_bin apply -f -
fi
wait_restore "$backup_name" "$cluster_name"
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/scheduled-backup/run
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ desc 'check backup and restore -- minio'
backup_dest_minio=$(get_backup_dest "$backup_name_minio")
kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://operator-testing/${backup_dest_minio}/rs0/ \
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls s3://${backup_dest_minio}/rs0/ \
| grep "myApp.test.gz"
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
Expand All @@ -107,7 +107,7 @@ compare_mongo_cmd "find" "myApp:myPass@$cluster-2.$cluster.$namespace"
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
desc 'check backup and restore -- aws-s3'
backup_dest_aws=$(get_backup_dest "$backup_name_aws")
curl -s "https://s3.amazonaws.com/operator-testing/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
Expand All @@ -120,7 +120,7 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then

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

desc 'check backup and restore -- azure-blob'
backup_dest_azure=$(get_backup_dest "$backup_name_azure")
curl -s "https://engk8soperators.blob.core.windows.net/operator-testing/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
run_mongo 'use myApp\n db.test.insert({ x: 100501 })' "myApp:myPass@$cluster.$namespace"
compare_mongo_cmd "find" "myApp:myPass@$cluster-0.$cluster.$namespace" "-2nd"
compare_mongo_cmd "find" "myApp:myPass@$cluster-1.$cluster.$namespace" "-2nd"
Expand Down
19 changes: 16 additions & 3 deletions pkg/controller/perconaservermongodbbackup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package perconaservermongodbbackup
import (
"context"
"fmt"
"strings"
"time"

"github.com/percona/percona-backup-mongodb/pbm"
Expand Down Expand Up @@ -90,16 +91,28 @@ func (b *Backup) Start(ctx context.Context, k8sclient client.Client, cluster *ap
switch stg.Type {
case api.BackupStorageS3:
status.S3 = &stg.S3

status.Destination = stg.S3.Bucket

if stg.S3.Prefix != "" {
status.Destination = stg.S3.Prefix + "/"
status.Destination = stg.S3.Bucket + "/" + stg.S3.Prefix
}
if !strings.HasPrefix(stg.S3.Bucket, "s3://") {
status.Destination = "s3://" + status.Destination
}
case api.BackupStorageAzure:
status.Azure = &stg.Azure

status.Destination = stg.Azure.Container

if stg.Azure.Prefix != "" {
status.Destination = stg.Azure.Prefix + "/"
status.Destination = stg.Azure.Container + "/" + stg.Azure.Prefix
}
if !strings.HasPrefix(stg.Azure.Container, "azure://") {
status.Destination = "azure://" + status.Destination
}
}
status.Destination += status.PBMname
status.Destination += "/" + status.PBMname

return status, nil
}
Expand Down

0 comments on commit 1127c61

Please sign in to comment.