Skip to content

Commit 92f1a50

Browse files
authored
K8SPG-227: add azure storage to backup tests (#905)
* Add Azure to scheduled and demand backup tests
1 parent 9b4cc28 commit 92f1a50

File tree

79 files changed

+889
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+889
-174
lines changed

e2e-tests/functions

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ deploy_s3_secrets() {
9696
"$(yq eval 'select(.metadata.name=="*s3*").data.AWS_SECRET_ACCESS_KEY' "${TESTS_CONFIG_DIR}/cloud-secret.yml" | base64 -d)" \
9797
>"${TEMP_DIR}/pgbackrest-secret.ini"
9898

99+
if [[ $test_name == "demand-backup" || $test_name == "scheduled-backup" ]]; then
100+
printf "repo3-azure-account=%s\nrepo3-azure-key=%s\n" \
101+
"$(yq eval 'select(.metadata.name=="azure*").data.AZURE_STORAGE_ACCOUNT_NAME' "${TESTS_CONFIG_DIR}/cloud-secret.yml" | base64 -d)" \
102+
"$(yq eval 'select(.metadata.name=="azure*").data.AZURE_STORAGE_ACCOUNT_KEY' "${TESTS_CONFIG_DIR}/cloud-secret.yml" | base64 -d)" \
103+
>>"${TEMP_DIR}/pgbackrest-secret.ini"
104+
fi
105+
99106
case ${test_name} in
100107
"scheduled-backup")
101108
printf 'repo2-gcs-key=/etc/pgbackrest/conf.d/gcs-key.json\n' >>"${TEMP_DIR}/pgbackrest-secret.ini"
@@ -154,7 +161,12 @@ get_cr() {
154161
.spec.backups.pgbackrest.global.repo1-path = "/backrestrepo/postgres-operator/'${repo_path}'/repo1" |
155162
.spec.backups.pgbackrest.repos = [{"name":"repo1","s3":{"bucket":"'$BUCKET'","endpoint":"s3.amazonaws.com","region":"us-east-1"}}]
156163
' $TEMP_DIR/cr.yaml
157-
164+
if [[ $test_name == "demand-backup" ]]; then
165+
yq eval -i '
166+
.spec.backups.pgbackrest.global.repo3-path = "/backrestrepo/postgres-operator/'${repo_path}'/repo3" |
167+
.spec.backups.pgbackrest.repos += [{"name":"repo3","azure":{"container":"'$BUCKET'"}}]
168+
' $TEMP_DIR/cr.yaml
169+
fi
158170
if [[ $test_name == "start-from-backup" ]]; then
159171
yq eval -i '
160172
.spec.dataSource.pgbackrest.configuration = [{"secret":{"name":"'${cr_name}'-pgbackrest-secrets"}}] |
@@ -171,8 +183,10 @@ get_cr() {
171183
.spec.backups.pgbackrest.manual.options = ["--type=full"] |
172184
.spec.backups.pgbackrest.global.repo1-path = "/backrestrepo/postgres-operator/'${repo_path}'/repo1" |
173185
.spec.backups.pgbackrest.global.repo2-path = "/backrestrepo/postgres-operator/'${repo_path}'/repo2" |
186+
.spec.backups.pgbackrest.global.repo3-path = "/backrestrepo/postgres-operator/'${repo_path}'/repo3" |
174187
.spec.backups.pgbackrest.repos = [{"name":"repo1","s3":{"bucket":"'$BUCKET'","endpoint":"s3.amazonaws.com","region":"us-east-1"}}] |
175-
.spec.backups.pgbackrest.repos += [{"name":"repo2","gcs":{"bucket":"'$BUCKET'"}}]
188+
.spec.backups.pgbackrest.repos += [{"name":"repo2","gcs":{"bucket":"'$BUCKET'"}}] |
189+
.spec.backups.pgbackrest.repos += [{"name":"repo3","azure":{"container":"'$BUCKET'"}}]
176190
' $TEMP_DIR/cr.yaml
177191
;;
178192
"custom-extensions" | "major-upgrade")
@@ -332,7 +346,7 @@ get_metric_values() {
332346
local metric=$1
333347
local instance=$2
334348
local api_key=$3
335-
local start=$($date -u "+%s" -d "-1 minute")
349+
local start=$($date -u "+%s" -d "-5 minute")
336350
local end=$($date -u "+%s")
337351
local endpoint=$(get_service_ip monitoring-service)
338352

e2e-tests/tests/demand-backup/01-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ status:
8383
repos:
8484
- name: repo1
8585
stanzaCreated: true
86+
- name: repo3
87+
stanzaCreated: true
8688
proxy:
8789
pgBouncer:
8890
readyReplicas: 3

e2e-tests/tests/demand-backup/01-create-cluster.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestStep
3-
timeout: 10
3+
timeout: 20
44
commands:
55
- script: |-
66
set -o errexit
@@ -11,4 +11,6 @@ commands:
1111
get_cr "demand-backup" ${RANDOM} \
1212
| yq '.spec.backups.pgbackrest.global.repo1-retention-full="2"' \
1313
| yq '.spec.backups.pgbackrest.global.repo1-retention-full-type="count"' \
14+
| yq '.spec.backups.pgbackrest.global.repo3-retention-full="2"' \
15+
| yq '.spec.backups.pgbackrest.global.repo3-retention-full-type="count"' \
1416
| kubectl -n "${NAMESPACE}" apply -f -

e2e-tests/tests/demand-backup/04-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kind: Job
66
apiVersion: batch/v1
77
metadata:
88
annotations:
9-
postgres-operator.crunchydata.com/pgbackrest-backup: demand-backup-full
9+
postgres-operator.crunchydata.com/pgbackrest-backup: demand-backup-full-s3
1010
labels:
1111
postgres-operator.crunchydata.com/pgbackrest-backup: manual
1212
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
@@ -21,7 +21,7 @@ status:
2121
apiVersion: pgv2.percona.com/v2
2222
kind: PerconaPGBackup
2323
metadata:
24-
name: demand-backup-full
24+
name: demand-backup-full-s3
2525
spec:
2626
pgCluster: demand-backup
2727
repoName: repo1

e2e-tests/tests/demand-backup/04-create-backup.yaml renamed to e2e-tests/tests/demand-backup/04-create-backup-s3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: pgv2.percona.com/v2
22
kind: PerconaPGBackup
33
metadata:
4-
name: demand-backup-full
4+
name: demand-backup-full-s3
55
spec:
66
pgCluster: demand-backup
77
repoName: repo1

e2e-tests/tests/demand-backup/05-check-pgbackrest-info.yaml renamed to e2e-tests/tests/demand-backup/05-check-pgbackrest-info-s3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ commands:
3636
fi
3737
}
3838
39-
manual_backup_name="demand-backup-full"
39+
manual_backup_name="demand-backup-full-s3"
4040
check_backup "$manual_backup_name" "percona.com/backup-name" "$manual_backup_name"
4141
4242
replica_backup_name=$(kubectl get -n "${NAMESPACE}" pg-backup -o jsonpath='{.items[?(@.metadata.annotations.pgv2\.percona\.com/pgbackrest-backup-job-type=="replica-create")].metadata.name}')

e2e-tests/tests/demand-backup/06-assert.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
3-
timeout: 560
3+
timeout: 660
44
---
55
kind: Job
66
apiVersion: batch/v1
77
metadata:
88
annotations:
9-
postgres-operator.crunchydata.com/pgbackrest-backup: demand-backup-full-2
9+
postgres-operator.crunchydata.com/pgbackrest-backup: demand-backup-full-azure
1010
labels:
1111
postgres-operator.crunchydata.com/pgbackrest-backup: manual
12-
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
12+
postgres-operator.crunchydata.com/pgbackrest-repo: repo3
1313
ownerReferences:
1414
- apiVersion: pgv2.percona.com/v2
1515
kind: PerconaPGBackup
@@ -21,10 +21,10 @@ status:
2121
apiVersion: pgv2.percona.com/v2
2222
kind: PerconaPGBackup
2323
metadata:
24-
name: demand-backup-full-2
24+
name: demand-backup-full-azure
2525
spec:
2626
pgCluster: demand-backup
27-
repoName: repo1
27+
repoName: repo3
2828
options:
2929
- --type=full
3030
status:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: pgv2.percona.com/v2
2+
kind: PerconaPGBackup
3+
metadata:
4+
name: demand-backup-full-azure
5+
spec:
6+
pgCluster: demand-backup
7+
repoName: repo3
8+
options:
9+
- --type=full
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
instance=$(kubectl get -n "${NAMESPACE}" pod -l postgres-operator.crunchydata.com/instance-set=instance1 -o 'jsonpath={.items[].metadata.name}')
11+
12+
pgbackrest_info_backups=$(kubectl exec -n "${NAMESPACE}" "$instance" -c database -- pgbackrest info --output json | jq '.[0].backup[]')
13+
14+
check_backup() {
15+
local backup_name=$1
16+
local pgbackrest_annotation=$2
17+
local pgbackrest_annotation_value=$3
18+
19+
status_backup_name=$(kubectl get -n "${NAMESPACE}" pg-backup "$backup_name" -o jsonpath='{.status.backupName}')
20+
if [[ -z $status_backup_name ]]; then
21+
echo ".status.backupName is empty in $backup_name"
22+
exit 1
23+
fi
24+
25+
backup_info=$(echo "$pgbackrest_info_backups" | jq "select(.annotation.\"$pgbackrest_annotation\" == \"$pgbackrest_annotation_value\")")
26+
if [[ $status_backup_name != $(echo "$backup_info" | jq ".label" --raw-output) ]]; then
27+
echo ".status.backupName doesn't equal to label in pgbackrest info"
28+
exit 1
29+
fi
30+
31+
backup_job_name=$(kubectl get -n "${NAMESPACE}" pg-backup "$backup_name" -o jsonpath='{.status.jobName}')
32+
backup_job_annotation=$(echo "$backup_info" | jq '.annotation."percona.com/backup-job-name"' --raw-output)
33+
if [[ $backup_job_name != "$backup_job_annotation" ]]; then
34+
echo "Failed to get job name annotation from pgbackrest"
35+
exit 1
36+
fi
37+
}
38+
39+
manual_backup_name="demand-backup-full-azure"
40+
check_backup "$manual_backup_name" "percona.com/backup-name" "$manual_backup_name"
41+
42+
replica_backup_name=$(kubectl get -n "${NAMESPACE}" pg-backup -o jsonpath='{.items[?(@.metadata.annotations.pgv2\.percona\.com/pgbackrest-backup-job-type=="replica-create")].metadata.name}')
43+
check_backup "$replica_backup_name" "percona.com/backup-job-type" "replica-create"
44+
45+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 560
4+
---
5+
kind: Job
6+
apiVersion: batch/v1
7+
metadata:
8+
annotations:
9+
postgres-operator.crunchydata.com/pgbackrest-backup: demand-backup-full-s3-2
10+
labels:
11+
postgres-operator.crunchydata.com/pgbackrest-backup: manual
12+
postgres-operator.crunchydata.com/pgbackrest-repo: repo1
13+
ownerReferences:
14+
- apiVersion: pgv2.percona.com/v2
15+
kind: PerconaPGBackup
16+
controller: true
17+
blockOwnerDeletion: true
18+
status:
19+
succeeded: 1
20+
---
21+
apiVersion: pgv2.percona.com/v2
22+
kind: PerconaPGBackup
23+
metadata:
24+
name: demand-backup-full-s3-2
25+
spec:
26+
pgCluster: demand-backup
27+
repoName: repo1
28+
options:
29+
- --type=full
30+
status:
31+
state: Succeeded
32+
---
33+
apiVersion: postgres-operator.crunchydata.com/v1beta1
34+
kind: PostgresCluster
35+
metadata:
36+
name: demand-backup
37+
generation: 4
38+
status:
39+
observedGeneration: 4

0 commit comments

Comments
 (0)