Skip to content

Commit f2670f2

Browse files
author
Kasturi Narra
committed
Update script to wait for ready pods too
1 parent 815edd3 commit f2670f2

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scripts/lvms-helpers/checkWorkloadExists.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ KUBECONFIG=${KUBECONFIG:-/var/lib/microshift/resources/kubeadmin/kubeconfig}
88
ns="test-lvms"
99
appLabel="app-lvms"
1010

11-
echo "INFO:" "Check if deployment Pod is 'Running'......."
12-
iter=24
11+
echo "INFO:" "Check if deployment Pod exists......."
1312
period=5
1413
podName=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod -n ${ns} -l app=${appLabel} --no-headers | awk '{print $1}')
1514
if [ "${podName}" == "" ]; then
1615
echo "ERROR:" "Deployment Pod not found."
1716
exit 1
1817
fi
1918

20-
echo "INFO:" "Waiting for Pod to become ready(max 2-minutes)....."
21-
result=""
22-
while [[ "${result}" != "Running" && ${iter} -gt 0 ]]; do
19+
# Wait for pod to be Running AND containers to be ready (combined check)
20+
echo "INFO:" "Waiting for Pod and containers to be ready (max 2-minutes)....."
21+
iter=24
22+
phase=""
23+
ready="false"
24+
while [[ ("${phase}" != "Running" || "${ready}" != "true") && ${iter} -gt 0 ]]; do
2325
#shellcheck disable=SC1083
24-
result=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod "${podName}" -n "${ns}" -o=jsonpath={.status.phase})
26+
phase=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod "${podName}" -n "${ns}" -o=jsonpath={.status.phase} 2>/dev/null || echo "")
27+
ready=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod "${podName}" -n "${ns}" -o=jsonpath={.status.containerStatuses[0].ready} 2>/dev/null || echo "false")
2528
(( iter -- ))
2629
sleep ${period}
2730
done
28-
if [ "${result}" == "Running" ]; then
29-
echo "INFO:" "Deployment Pod is Running."
31+
32+
if [ "${phase}" == "Running" ] && [ "${ready}" == "true" ]; then
33+
echo "INFO:" "Deployment Pod is Running and containers are ready."
3034
else
31-
echo "ERROR:" "Deployment Pod is not in 'Running' state."
35+
echo "ERROR:" "Pod phase: ${phase}, Container ready: ${ready}"
3236
sudo oc --kubeconfig "${KUBECONFIG}" -n "${ns}" describe pod "${podName}"
3337
exit 1
3438
fi

0 commit comments

Comments
 (0)