forked from rancher/terraform-rancher2-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadyNodes.sh
More file actions
executable file
·59 lines (52 loc) · 1.33 KB
/
readyNodes.sh
File metadata and controls
executable file
·59 lines (52 loc) · 1.33 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
#!/bin/bash
set -x
JSONPATH="'{range .items[*]}
{.metadata.name}{\"\\t\"} \
{.status.nodeInfo.kubeletVersion}{\"\\t\"} \
{.status.nodeInfo.osImage}{\"\\t\"} \
{.status.nodeInfo.architecture}{\"\\t\"} \
{.status.conditions[?(@.status==\"True\")].type}{\"\\n\"} \
{end}'"
notReady() {
# Get the list of nodes and their statuses
NODES="$(kubectl get nodes -o jsonpath="$JSONPATH")"
# Example output:
# master-node Ready
# worker-node Ready MemoryPressure
# worker-node2 EtcVoter Ready
# worker-node3
# shellcheck disable=SC2060,SC2140
NOT_READY="$(echo "$NODES" | grep -v "Ready" | tr -d ["\t","\n"," ","'"] || true)"
if [ -n "$NOT_READY" ]; then
# Some nodes are not ready
return 0
else
# All nodes are ready
return 1
fi
}
TIMEOUT=5 # 5 minutes
TIMEOUT_MINUTES=$((TIMEOUT * 60))
INTERVAL=10 # 10 seconds
MAX=$((TIMEOUT_MINUTES / INTERVAL))
ATTEMPTS=0
while notReady; do
if [[ $ATTEMPTS -lt $MAX ]]; then
echo "Waiting for nodes to be ready..."
ATTEMPTS=$((ATTEMPTS + 1))
sleep $INTERVAL;
else
echo "Timeout reached. Nodes are not ready..."
kubectl get nodes || true
kubectl get all -A
exit 1
fi
done
echo "Nodes are ready..."
echo "nodes..."
kubectl get nodes || true
echo "all..."
kubectl get all -A || true
echo "pods..."
kubectl get pods -A || true
exit 0