-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait-for-resource.sh
executable file
·46 lines (42 loc) · 1.21 KB
/
wait-for-resource.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
ACTION=$1
RESOURCE=$2
RESOURCE_NAME=$3
CMD="kubectl"
RETRIES=60
if [ "${RESOURCE}" = "pod" ] && [ "${ACTION}" = "create" ]; then
for r in $(seq $RETRIES); do
pod=$($CMD get pods | grep "Running" | grep ${RESOURCE_NAME} | grep -v deploy | awk $'{ print $3 }')
$CMD get pods -n default | grep ${RESOURCE_NAME}
if [ "${pod}" = 'Running' ]; then
echo "${RESOURCE_NAME} ${RESOURCE} is running"
break
fi
echo "Waiting for ${RESOURCE_NAME} ${RESOURCE} to be running"
sleep 3
done
elif [ "${ACTION}" = "create" ]; then
for r in $(seq $RETRIES); do
$CMD get ${RESOURCE} | grep ${RESOURCE_NAME}
if [ $? -eq 0 ]; then
echo "${RESOURCE_NAME} ${RESOURCE} has been created"
break
fi
echo "Waiting for ${RESOURCE_NAME} ${RESOURCE} to be created"
sleep 3
done
elif [ "${ACTION}" = "delete" ]; then
for r in $(seq $RETRIES); do
$CMD get ${RESOURCE} | grep ${RESOURCE_NAME}
if [ $? -eq 1 ]; then
echo "${RESOURCE_NAME} ${RESOURCE} has been deleted"
break
fi
echo "Waiting for ${RESOURCE_NAME} ${RESOURCE} to be deleted"
sleep 3
done
fi
if [ "${r}" == "${RETRIES}" ]; then
echo "Error: Timeout waiting for ${RESOURCE_NAME} ${RESOURCE} to be ${ACTION}d"
exit 1
fi