Skip to content

Commit 59bffb0

Browse files
committed
Add a script to simplify verification of deployments
1 parent ca80143 commit 59bffb0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/wait-deployment.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# $1 is object name, $2 is namespace name, $3 is timeout
3+
4+
printError() {
5+
echo "Failed to verify deployment $1. Current replicas is '${CUNNRENT_COUNT}'"
6+
echo "Pods in $2 namespace:"
7+
kubectl get pods -n $2
8+
echo "Events in $2 namespace:"
9+
kubectl get events -n $2
10+
}
11+
12+
if [ -z $1 ] || [ -z $2 ]; then
13+
echo "Deployment name and namespace are mandarory arguments. Rerun the script with deployment name and namespace as args"
14+
exit 1
15+
fi
16+
DEPLOYMENT=$1
17+
NAMESPACE=$2
18+
DEFAULT_TIMEOUT=300
19+
TIMEOUT=${3:-${DEFAULT_TIMEOUT}}
20+
echo "Waiting for deployment $DEPLOYMENT. Timeout in $TIMEOUT seconds"
21+
REQUIRED_COUNT=1
22+
CUNNRENT_COUNT=$(kubectl get deployment/$DEPLOYMENT -n $NAMESPACE -o=jsonpath='{.status.availableReplicas}')
23+
if [ $? -ne 0 ]; then
24+
echo "An error occurred. Exiting"
25+
exit 1
26+
fi
27+
SLEEP=5
28+
exit=$((SECONDS+TIMEOUT))
29+
while [ "${CUNNRENT_COUNT}" -ne "${REQUIRED_COUNT}" ] && [ ${SECONDS} -lt ${exit} ]; do
30+
CUNNRENT_COUNT=$(kubectl get deployment/$DEPLOYMENT -n $NAMESPACE -o=jsonpath='{.status.availableReplicas}')
31+
timeout_in=$((exit-SECONDS))
32+
sleep ${SLEEP}
33+
done
34+
35+
if [ "${CUNNRENT_COUNT}" -ne "${REQUIRED_COUNT}" ]; then
36+
printError $DEPLOYMENT $NAMESPACE
37+
exit 1
38+
elif [ ${SECONDS} -ge ${exit} ]; then
39+
echo "Deployment $DEPLOYMENT timed out. Current replicas is ${CUNNRENT_COUNT}"
40+
printError $DEPLOYMENT $NAMESPACE
41+
exit 1
42+
fi
43+
echo "Deployment $1 successfully scaled"

0 commit comments

Comments
 (0)