forked from rancher/terraform-rancher2-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunningPods.sh
More file actions
executable file
·67 lines (56 loc) · 1.38 KB
/
runningPods.sh
File metadata and controls
executable file
·67 lines (56 loc) · 1.38 KB
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
#!/bin/bash
set -x
JSONPATH="'{range .items[*]}
{.metadata.name}{\"\\t\"} \
{.metadata.namespace}{\"\\t\"} \
{.status.phase}{\"\\n\"} \
{end}'"
notReady() {
PODS=$(kubectl get pods -A -o jsonpath="$JSONPATH")
# shellcheck disable=SC2060,SC2140
NOT_READY=$(echo "$PODS" | grep -v "Running" | grep -v "Succeeded" | tr -d ["\t","\n"," ","'"] || true)
if [ -n "$NOT_READY" ]; then
# Some pods aren't running
return 0
else
# All pods are running
return 1
fi
}
readyWait() {
TIMEOUT=10 # 10 minutes
TIMEOUT_MINUTES=$((TIMEOUT * 60))
INTERVAL=30 # 30 seconds
MAX=$((TIMEOUT_MINUTES / INTERVAL))
ATTEMPTS=0
while notReady; do
if [ "$ATTEMPTS" -lt "$MAX" ]; then
ATTEMPTS=$((ATTEMPTS + 1))
sleep "$INTERVAL";
else
return 1
fi
done
return 0
}
SUCCESSES=0
SUCCESSES_NEEDED=3 # require three successes to make sure everything is settled
while readyWait && [ "$SUCCESSES" -lt "$SUCCESSES_NEEDED" ]; do
SUCCESSES=$((SUCCESSES + 1))
echo "succeeeded $SUCCESSES times..."
sleep 30
done
if [ "$SUCCESSES" -eq "$SUCCESSES_NEEDED" ]; then
echo "$SUCCESSES_NEEDED successes reached, passed..."
EXITCODE=0
else
echo "$SUCCESSES_NEEDED successes not reached, failed..."
EXITCODE=1
fi
echo "nodes..."
kubectl get nodes || true
echo "all..."
kubectl get all -A || true
echo "pods..."
kubectl get pods -A || true
exit $EXITCODE