Skip to content

Commit 31f19bf

Browse files
committed
Improve wait script
1 parent 8332f4a commit 31f19bf

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

scripts/wait-deployment.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,26 @@ DEFAULT_TIMEOUT=300
2121
TIMEOUT=${4:-${DEFAULT_TIMEOUT}}
2222
echo "Waiting for deployment $DEPLOYMENT. Expecting $REQUIRED_COUNT replicas. Timeout in $TIMEOUT seconds"
2323
CUNNRENT_COUNT=$(kubectl get deployment/$DEPLOYMENT -n $NAMESPACE -o=jsonpath='{.status.availableReplicas}')
24-
if [ $? -ne 0 ]; then
25-
echo "An error occurred. Exiting"
26-
exit 1
27-
fi
2824
SLEEP=5
2925
exit=$((SECONDS+TIMEOUT))
30-
while [ "${CUNNRENT_COUNT}" -ne "${REQUIRED_COUNT}" ] && [ ${SECONDS} -lt ${exit} ]; do
26+
while [ -z "${CUNNRENT_COUNT}" ] && [ ${SECONDS} -lt ${exit} ]; do
27+
CUNNRENT_COUNT=$(kubectl get deployment/$DEPLOYMENT -n $NAMESPACE -o=jsonpath='{.status.availableReplicas}')
28+
timeout_in=$((exit-SECONDS))
29+
sleep ${SLEEP}
30+
done
31+
32+
if [ -z "${CUNNRENT_COUNT}" ]; then
33+
printError $DEPLOYMENT $NAMESPACE
34+
exit 1
35+
fi
36+
37+
while [ "${CUNNRENT_COUNT}" -lt "${REQUIRED_COUNT}" ] && [ ${SECONDS} -lt ${exit} ]; do
3138
CUNNRENT_COUNT=$(kubectl get deployment/$DEPLOYMENT -n $NAMESPACE -o=jsonpath='{.status.availableReplicas}')
3239
timeout_in=$((exit-SECONDS))
3340
sleep ${SLEEP}
3441
done
3542

36-
if [ "${CUNNRENT_COUNT}" -ne "${REQUIRED_COUNT}" ]; then
43+
if [ "${CUNNRENT_COUNT}" -lt "${REQUIRED_COUNT}" ]; then
3744
printError $DEPLOYMENT $NAMESPACE
3845
exit 1
3946
elif [ ${SECONDS} -ge ${exit} ]; then

0 commit comments

Comments
 (0)