-
Notifications
You must be signed in to change notification settings - Fork 66
K8SPG-844 fix backup-enable-disable test #1318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comment on lines
+119
to
+173
local pod_prefix="$1" | ||
local target_count="$2" | ||
local namespace="${NAMESPACE}" | ||
local max_wait_seconds=300 | ||
local check_interval=5 | ||
local elapsed_time=0 | ||
|
||
if [[ -z "$pod_prefix" || -z "$target_count" || -z "$namespace" ]]; then | ||
echo "Error: Missing arguments." >&2 | ||
echo "Usage: wait_for_ready_containers <pod_name_prefix> <target_ready_count> <namespace>" >&2 | ||
return 1 | ||
fi | ||
|
||
echo "Waiting for pods starting with '$pod_prefix' in namespace '$namespace' to have $target_count ready containers (Max ${max_wait_seconds}s)..." | ||
|
||
while [[ "$elapsed_time" -lt "$max_wait_seconds" ]]; do | ||
local target_pods | ||
# Get pods that match the prefix AND are running | ||
target_pods=$(kubectl get pods -n "$namespace" --field-selector=status.phase=Running --output=json | \ | ||
jq -r ".items[] | select(.metadata.name | startswith(\"$pod_prefix\")) | .metadata.name") | ||
# If no running pods match the prefix, something might be wrong, but we'll keep waiting. | ||
if [[ -z "$target_pods" ]]; then | ||
echo "No running pods found with prefix '$pod_prefix'. Waiting..." | ||
sleep "$check_interval" | ||
elapsed_time=$((elapsed_time + check_interval)) | ||
continue | ||
fi | ||
|
||
local ready_count=0 | ||
local total_matches=0 | ||
|
||
# Check each pod individually | ||
for pod_name in $target_pods; do | ||
total_matches=$((total_matches + 1)) | ||
current_ready=$(kubectl get pod "$pod_name" -n "$namespace" -o json 2>/dev/null | \ | ||
jq '.status.containerStatuses | map(select(.ready == true)) | length') | ||
|
||
if [[ "$current_ready" -eq "$target_count" ]]; then | ||
ready_count=$((ready_count + 1)) | ||
fi | ||
done | ||
|
||
if [[ "$ready_count" -eq "$total_matches" ]]; then | ||
echo "Success: All $total_matches pods now have $target_count ready containers." | ||
return 0 | ||
fi | ||
|
||
echo "Current status: $ready_count of $total_matches pods have $target_count ready containers. Waiting ${check_interval}s..." | ||
|
||
sleep "$check_interval" | ||
elapsed_time=$((elapsed_time + check_interval)) | ||
done | ||
|
||
echo "Error: Timeout reached! After ${max_wait_seconds} seconds, not all pods reached $target_count ready containers." >&2 | ||
return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shfmt] reported by reviewdog 🐶
Suggested change
local pod_prefix="$1" | |
local target_count="$2" | |
local namespace="${NAMESPACE}" | |
local max_wait_seconds=300 | |
local check_interval=5 | |
local elapsed_time=0 | |
if [[ -z "$pod_prefix" || -z "$target_count" || -z "$namespace" ]]; then | |
echo "Error: Missing arguments." >&2 | |
echo "Usage: wait_for_ready_containers <pod_name_prefix> <target_ready_count> <namespace>" >&2 | |
return 1 | |
fi | |
echo "Waiting for pods starting with '$pod_prefix' in namespace '$namespace' to have $target_count ready containers (Max ${max_wait_seconds}s)..." | |
while [[ "$elapsed_time" -lt "$max_wait_seconds" ]]; do | |
local target_pods | |
# Get pods that match the prefix AND are running | |
target_pods=$(kubectl get pods -n "$namespace" --field-selector=status.phase=Running --output=json | \ | |
jq -r ".items[] | select(.metadata.name | startswith(\"$pod_prefix\")) | .metadata.name") | |
# If no running pods match the prefix, something might be wrong, but we'll keep waiting. | |
if [[ -z "$target_pods" ]]; then | |
echo "No running pods found with prefix '$pod_prefix'. Waiting..." | |
sleep "$check_interval" | |
elapsed_time=$((elapsed_time + check_interval)) | |
continue | |
fi | |
local ready_count=0 | |
local total_matches=0 | |
# Check each pod individually | |
for pod_name in $target_pods; do | |
total_matches=$((total_matches + 1)) | |
current_ready=$(kubectl get pod "$pod_name" -n "$namespace" -o json 2>/dev/null | \ | |
jq '.status.containerStatuses | map(select(.ready == true)) | length') | |
if [[ "$current_ready" -eq "$target_count" ]]; then | |
ready_count=$((ready_count + 1)) | |
fi | |
done | |
if [[ "$ready_count" -eq "$total_matches" ]]; then | |
echo "Success: All $total_matches pods now have $target_count ready containers." | |
return 0 | |
fi | |
echo "Current status: $ready_count of $total_matches pods have $target_count ready containers. Waiting ${check_interval}s..." | |
sleep "$check_interval" | |
elapsed_time=$((elapsed_time + check_interval)) | |
done | |
echo "Error: Timeout reached! After ${max_wait_seconds} seconds, not all pods reached $target_count ready containers." >&2 | |
return 1 | |
local pod_prefix="$1" | |
local target_count="$2" | |
local namespace="${NAMESPACE}" | |
local max_wait_seconds=300 | |
local check_interval=5 | |
local elapsed_time=0 | |
if [[ -z $pod_prefix || -z $target_count || -z $namespace ]]; then | |
echo "Error: Missing arguments." >&2 | |
echo "Usage: wait_for_ready_containers <pod_name_prefix> <target_ready_count> <namespace>" >&2 | |
return 1 | |
fi | |
echo "Waiting for pods starting with '$pod_prefix' in namespace '$namespace' to have $target_count ready containers (Max ${max_wait_seconds}s)..." | |
while [[ $elapsed_time -lt $max_wait_seconds ]]; do | |
local target_pods | |
# Get pods that match the prefix AND are running | |
target_pods=$(kubectl get pods -n "$namespace" --field-selector=status.phase=Running --output=json \ | |
| jq -r ".items[] | select(.metadata.name | startswith(\"$pod_prefix\")) | .metadata.name") | |
# If no running pods match the prefix, something might be wrong, but we'll keep waiting. | |
if [[ -z $target_pods ]]; then | |
echo "No running pods found with prefix '$pod_prefix'. Waiting..." | |
sleep "$check_interval" | |
elapsed_time=$((elapsed_time + check_interval)) | |
continue | |
fi | |
local ready_count=0 | |
local total_matches=0 | |
# Check each pod individually | |
for pod_name in $target_pods; do | |
total_matches=$((total_matches + 1)) | |
current_ready=$(kubectl get pod "$pod_name" -n "$namespace" -o json 2>/dev/null \ | |
| jq '.status.containerStatuses | map(select(.ready == true)) | length') | |
if [[ $current_ready -eq $target_count ]]; then | |
ready_count=$((ready_count + 1)) | |
fi | |
done | |
if [[ $ready_count -eq $total_matches ]]; then | |
echo "Success: All $total_matches pods now have $target_count ready containers." | |
return 0 | |
fi | |
echo "Current status: $ready_count of $total_matches pods have $target_count ready containers. Waiting ${check_interval}s..." | |
sleep "$check_interval" | |
elapsed_time=$((elapsed_time + check_interval)) | |
done | |
echo "Error: Timeout reached! After ${max_wait_seconds} seconds, not all pods reached $target_count ready containers." >&2 | |
return 1 |
commit: 98d4b33 |
eleo007
approved these changes
Oct 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CHANGE DESCRIPTION
Problem:
The test disables backups but doesn’t wait for the cluster to become ready. We should wait for readiness to confirm that all pgBackRest containers have been removed and backups are fully disabled.
CHECKLIST
Jira
Needs Doc
) and QA (Needs QA
)?Tests
Config/Logging/Testability