Skip to content

Commit 74508f2

Browse files
authored
Merge pull request #1318 from percona/fix_test
K8SPG-844 fix backup-enable-disable test
2 parents d77f34b + 98d4b33 commit 74508f2

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void createCluster(String CLUSTER_SUFFIX) {
1616
--preemptible \
1717
--zone=${region} \
1818
--machine-type='n1-standard-4' \
19-
--cluster-version='1.30' \
19+
--cluster-version='1.31' \
2020
--num-nodes=3 \
2121
--labels='delete-cluster-after-hours=6' \
2222
--disk-size=30 \

e2e-tests/functions

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,64 @@ remove_all_finalizers() {
115115
done
116116
}
117117

118+
wait_for_ready_containers() {
119+
local pod_prefix="$1"
120+
local target_count="$2"
121+
local namespace="${NAMESPACE}"
122+
local max_wait_seconds=300
123+
local check_interval=5
124+
local elapsed_time=0
125+
126+
if [[ -z "$pod_prefix" || -z "$target_count" || -z "$namespace" ]]; then
127+
echo "Error: Missing arguments." >&2
128+
echo "Usage: wait_for_ready_containers <pod_name_prefix> <target_ready_count> <namespace>" >&2
129+
return 1
130+
fi
131+
132+
echo "Waiting for pods starting with '$pod_prefix' in namespace '$namespace' to have $target_count ready containers (Max ${max_wait_seconds}s)..."
133+
134+
while [[ "$elapsed_time" -lt "$max_wait_seconds" ]]; do
135+
local target_pods
136+
# Get pods that match the prefix AND are running
137+
target_pods=$(kubectl get pods -n "$namespace" --field-selector=status.phase=Running --output=json | \
138+
jq -r ".items[] | select(.metadata.name | startswith(\"$pod_prefix\")) | .metadata.name")
139+
# If no running pods match the prefix, something might be wrong, but we'll keep waiting.
140+
if [[ -z "$target_pods" ]]; then
141+
echo "No running pods found with prefix '$pod_prefix'. Waiting..."
142+
sleep "$check_interval"
143+
elapsed_time=$((elapsed_time + check_interval))
144+
continue
145+
fi
146+
147+
local ready_count=0
148+
local total_matches=0
149+
150+
# Check each pod individually
151+
for pod_name in $target_pods; do
152+
total_matches=$((total_matches + 1))
153+
current_ready=$(kubectl get pod "$pod_name" -n "$namespace" -o json 2>/dev/null | \
154+
jq '.status.containerStatuses | map(select(.ready == true)) | length')
155+
156+
if [[ "$current_ready" -eq "$target_count" ]]; then
157+
ready_count=$((ready_count + 1))
158+
fi
159+
done
160+
161+
if [[ "$ready_count" -eq "$total_matches" ]]; then
162+
echo "Success: All $total_matches pods now have $target_count ready containers."
163+
return 0
164+
fi
165+
166+
echo "Current status: $ready_count of $total_matches pods have $target_count ready containers. Waiting ${check_interval}s..."
167+
168+
sleep "$check_interval"
169+
elapsed_time=$((elapsed_time + check_interval))
170+
done
171+
172+
echo "Error: Timeout reached! After ${max_wait_seconds} seconds, not all pods reached $target_count ready containers." >&2
173+
return 1
174+
}
175+
118176
destroy_operator() {
119177
kubectl -n "${OPERATOR_NS:-$NAMESPACE}" delete deployment percona-postgresql-operator --force --grace-period=0 || true
120178
if [[ $OPERATOR_NS ]]; then

e2e-tests/kuttl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ apiVersion: kuttl.dev/v1beta1
22
kind: TestSuite
33
testDirs:
44
- e2e-tests/tests
5-
timeout: 180
5+
timeout: 600

e2e-tests/tests/backup-enable-disable/03-disable-backups.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ commands:
1111
| yq '.metadata.annotations."pgv2.percona.com/authorizeBackupRemoval"="true"' \
1212
| yq '.spec.backups.enabled=false' \
1313
| kubectl -n "${NAMESPACE}" apply -f -
14+
15+
wait_for_ready_containers "some-name-instance1" 2

0 commit comments

Comments
 (0)