This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
wait-until-ready.sh
82 lines (71 loc) · 1.99 KB
/
wait-until-ready.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# This script is checking readiness of Kubernetes services and returns 0 if all ready, 1 non recoverable errors and 2 for timeouts
NAMESPACE=$1
function check_deployment {
local name=$1
local namespace=$2
local label=$3
local counts_max=$4
local counts_actual=0
error=0;
printf "\nWaiting for $name"
while kubectl -n $namespace get pods -l=app=$label -o jsonpath="{.items[*].status.containerStatuses[*].ready}" | grep -q false;
do printf ".";
let counts_actual=$counts_actual+1;
if [ $counts_actual -ge $counts_max ];
then exit 2
fi
sleep 5;
done
return 0
}
function check_job {
local name=$1
local namespace=$2
local counts_max=$3
local counts_actual=0
error=0;
printf "\nWaiting for $name"
while ! kubectl -n $namespace get job $name -o jsonpath="{.status.succeeded}" | grep 1 >> /dev/null;
do printf ".";
let counts_actual=$counts_actual+1;
if [ $counts_actual -ge $counts_max ];
then exit 2
fi
sleep 5;
done
}
function check_sts {
local name=$1
local namespace=$2
local counts_max=$3
local counts_actual=0
error=0;
printf "\nWaiting for $name"
while kubectl -n $namespace get pods ${name}-0 -o jsonpath="{.status.containerStatuses[*].ready}" | grep -q false;
do printf ".";
let counts_actual=$counts_actual+1;
if [ $counts_actual -ge $counts_max ];
then exit 2
fi
sleep 5;
done
}
counts_actual=0
counts_max=60
#As long as any pod is pending - do not go forward
printf "\nWaiting for pending or terminating pods";
while kubectl -n $NAMESPACE get pods | grep -q 'Pending\|Terminating'; \
do printf ".";
let counts_actual=$counts_actual+1;
sleep 5;
if [ $counts_actual -ge $counts_max ];
then exit 2;
fi
done;
check_deployment frontend ${NAMESPACE} frontend 120
check_deployment kairosdb ${NAMESPACE} kairosdb 60
check_sts mqtt-gateway ${NAMESPACE} 240
check_sts emqx ${NAMESPACE} 240
printf "\ndone\n"
exit 0;