@@ -8,6 +8,7 @@ e2e_test_extra_hash() {
88}
99
1010e2e_test_install () {
11+ OLD_BACKUP_NAME=" $( get_sgbackup_name " ${SPEC_NAME} -old" ) "
1112 BACKUP_NAME=" $( get_sgbackup_name " ${SPEC_NAME} " ) "
1213
1314 install_minio
@@ -19,6 +20,18 @@ e2e_test_install() {
1920
2021 wait_pods_running " $CLUSTER_NAMESPACE " " 4"
2122 wait_cluster " $CLUSTER_NAME " " $CLUSTER_NAMESPACE "
23+
24+ cat << EOF | kubectl create -f -
25+ apiVersion: stackgres.io/v1
26+ kind: SGBackup
27+ metadata:
28+ namespace: $CLUSTER_NAMESPACE
29+ name: $OLD_BACKUP_NAME
30+ spec:
31+ sgCluster: $CLUSTER_NAME
32+ EOF
33+ wait_until eval ' kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$OLD_BACKUP_NAME" -o json \
34+ | jq ".status.process.status" -r | grep -qxF Completed'
2235}
2336
2437e2e_test () {
142155
143156 create_or_replace_cluster " $CLUSTER_NAME " " $CLUSTER_NAMESPACE " " 2" \
144157 --set-string cluster.replication.initialization.mode=FromExistingBackup
145- wait_pods_terminated " $CLUSTER_NAMESPACE " " 5 "
158+ wait_pods_terminated " $CLUSTER_NAMESPACE " " 2 " " $CLUSTER_NAME -[0-9] "
146159 wait_until kubectl get configmap -n " $CLUSTER_NAMESPACE " " $CLUSTER_NAME -replication-init" -o json \
147160 | jq ' .data.REPLICATION_INITIALIZATION_BACKUP' -r \
148161 | grep -q .
@@ -170,13 +183,31 @@ EOF
170183 echo
171184 fail " replication has not bootstrapped from backup"
172185 fi
186+
187+ LATEST_BACKUP=" $( kubectl get sgbackup -n " $CLUSTER_NAMESPACE " --sort-by=' {.metadata.creationTimestamp}' -o name \
188+ | tail -n 1 | cut -d / -f 2) "
189+ if [ " x$LATEST_BACKUP " != x ] \
190+ && kubectl get configmap -n " $CLUSTER_NAMESPACE " " $CLUSTER_NAME -replication-init" -o json \
191+ | jq ' .data.REPLICATION_INITIALIZATION_BACKUP' -r \
192+ | grep -qxF " $LATEST_BACKUP "
193+ then
194+ success " replication has bootstrapped from latest backup"
195+ else
196+ fail " replication has not bootstrapped from latest backup"
197+ fi
173198}
174199
175200check_replication_is_working_from_newly_created_backup () {
176201 BACKUP_END_TIMESTAMP=" $( kubectl get sgbackup -n " $CLUSTER_NAMESPACE " " $BACKUP_NAME " -o json \
177202 | jq ' .status.process.timing.end' -r \
178203 | date -d " $( cat) " +%s) "
179204 NOW=" $( date +%s) "
205+ if [ " $(( NOW - BACKUP_END_TIMESTAMP )) " -lt 120 ]
206+ then
207+ echo " Waiting $(( 120 - NOW + BACKUP_END_TIMESTAMP )) seconds for the existing backups to be enough old"
208+ sleep " $(( 120 - NOW + BACKUP_END_TIMESTAMP )) "
209+ NOW=" $( date +%s) "
210+ fi
180211 create_or_replace_cluster " $CLUSTER_NAME " " $CLUSTER_NAMESPACE " " 2" \
181212 --set-string cluster.replication.initialization.mode=FromNewlyCreatedBackup \
182213 --set-string cluster.replication.initialization.backupNewerThan=" PT$(( NOW - BACKUP_END_TIMESTAMP )) S"
@@ -205,12 +236,15 @@ check_replication_is_working_from_newly_created_backup() {
205236 fail " replication has not bootstrapped from backup"
206237 fi
207238
208- if kubectl get configmap -n " $CLUSTER_NAMESPACE " " $CLUSTER_NAME -replication-init" -o json \
239+ NEWLY_CREATED_BACKUP=" $( kubectl get sgbackup -n " $CLUSTER_NAMESPACE " -l " app=StackGresCluster,stackgres.io/cluster-name=$CLUSTER_NAME " -o name \
240+ | cut -d ' /' -f 2) "
241+ if [ " x$NEWLY_CREATED_BACKUP " != x ] \
242+ && kubectl get configmap -n " $CLUSTER_NAMESPACE " " $CLUSTER_NAME -replication-init" -o json \
209243 | jq ' .data.REPLICATION_INITIALIZATION_BACKUP' -r \
210- | grep -qxF " $CLUSTER_NAME "
244+ | grep -qxF " $NEWLY_CREATED_BACKUP "
211245 then
212- fail " replication has not bootstrapped from newly created backup"
213- else
214246 success " replication has bootstrapped from newly created backup"
247+ else
248+ fail " replication has not bootstrapped from newly created backup"
215249 fi
216250}
0 commit comments