Skip to content

Commit 0d7e6f8

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

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

scripts/lvms-helpers/checkWorkloadExists.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@ 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:" "Waiting for deployment Pod to be created (max 1-minute)....."
12+
iter=12
1313
period=5
14-
podName=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod -n ${ns} -l app=${appLabel} --no-headers | awk '{print $1}')
14+
podName=""
15+
while [[ "${podName}" == "" && ${iter} -gt 0 ]]; do
16+
podName=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod -n ${ns} -l app=${appLabel} --no-headers 2>/dev/null | awk '{print $1}')
17+
if [ "${podName}" == "" ]; then
18+
(( iter -- ))
19+
sleep ${period}
20+
fi
21+
done
22+
1523
if [ "${podName}" == "" ]; then
16-
echo "ERROR:" "Deployment Pod not found."
24+
echo "ERROR:" "Deployment Pod not found after waiting."
1725
exit 1
1826
fi
27+
echo "INFO:" "Pod ${podName} found."
1928

20-
echo "INFO:" "Waiting for Pod to become ready(max 2-minutes)....."
21-
result=""
22-
while [[ "${result}" != "Running" && ${iter} -gt 0 ]]; do
23-
#shellcheck disable=SC1083
24-
result=$(sudo oc --kubeconfig "${KUBECONFIG}" get pod "${podName}" -n "${ns}" -o=jsonpath={.status.phase})
25-
(( iter -- ))
26-
sleep ${period}
27-
done
28-
if [ "${result}" == "Running" ]; then
29-
echo "INFO:" "Deployment Pod is Running."
29+
# Now wait for the pod to be ready (all containers initialized and ready)
30+
echo "INFO:" "Waiting for Pod and all containers to be ready (max 2-minutes)....."
31+
if sudo oc --kubeconfig "${KUBECONFIG}" wait --for=condition=Ready pod/"${podName}" -n "${ns}" --timeout=120s; then
32+
echo "INFO:" "Deployment Pod is Ready."
3033
else
31-
echo "ERROR:" "Deployment Pod is not in 'Running' state."
34+
echo "ERROR:" "Pod did not become ready within timeout."
3235
sudo oc --kubeconfig "${KUBECONFIG}" -n "${ns}" describe pod "${podName}"
3336
exit 1
3437
fi

0 commit comments

Comments
 (0)