Skip to content

Commit

Permalink
print the kurl pods, and list the unhealthy ones, when failing the ns…
Browse files Browse the repository at this point in the history
… preflight (#4845)
  • Loading branch information
laverya authored Sep 26, 2023
1 parent 4702545 commit 853e6ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions scripts/common/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,17 @@ function canonical_image_name() {

# check_for_running_pods scans for pod(s) in a namespace and checks whether their status is running/completed
# note: Evicted pods are exempt from this check
# exports a variable UNHEALTHY_PODS containing the names of pods that are not running/completed
UNHEALTHY_PODS=
function check_for_running_pods() {
local namespace=$1
local is_job_controller=0
local ns_pods=
local status=
local containers=

local unhealthy_podnames=

ns_pods=$(kubectl get pods -n "$namespace" -o jsonpath='{.items[*].metadata.name}')

if [ -z "$ns_pods" ]; then
Expand All @@ -1166,7 +1170,8 @@ function check_for_running_pods() {
fi

if [ "$status" != "Running" ] && [ "$status" != "Succeeded" ]; then
return 1
unhealthy_podnames="$unhealthy_podnames $pod"
continue
fi

containers=$(kubectl get pod "$pod" -n "$namespace" -o jsonpath="{.spec.containers[*].name}")
Expand All @@ -1175,11 +1180,18 @@ function check_for_running_pods() {

# ignore container ready status for pods managed by the Job controller
if [ "$container_status" != "true" ] && [ "$is_job_controller" = "0" ]; then
return 1
unhealthy_podnames="$unhealthy_podnames $pod"
continue
fi
done
done

# if there are unhealthy pods, return 1
if [ -n "$unhealthy_podnames" ]; then
export UNHEALTHY_PODS="$unhealthy_podnames"
return 1
fi

return 0
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/common/preflights.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function bail_if_kurl_pods_are_unhealthy() {
fi
log "Awaiting 2 minutes to check kURL Pod(s) are Running"
if ! spinner_until 120 check_for_running_pods kurl; then
bail "Kurl has unhealthy Pod(s). Check the namespace kurl. Restarting the pod may fix the issue."
kubectl get pods -n kurl
bail "Kurl has unhealthy Pod(s) $UNHEALTHY_PODS. Restarting the pod may fix the issue."
fi
fi
}
Expand Down

0 comments on commit 853e6ed

Please sign in to comment.