-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait.sh
More file actions
executable file
·85 lines (76 loc) · 2.4 KB
/
wait.sh
File metadata and controls
executable file
·85 lines (76 loc) · 2.4 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# Configuration
RETRY=3
# Set KUBECONFIG
export KUBECONFIG=/home/lab/ocp4/auth/kubeconfig
echo "Waiting for OpenShift cluster start..."
for i in $(seq 1 ${RETRY})
do
# Wait for API to come online
until [ $(curl -k -s https://api.ocp4.example.com:6443/version?timeout=10s | jq -r '.major' | grep -v null | wc -l) -eq 1 ]
do
echo "Waiting for API..."
sleep 10
done
echo "API is up"
echo "Cluster version is $(oc get clusterversion version -o json | jq -r '.status.history[0].version')"
# Wait for router come online
until [ not $(curl -k -s https://console-openshift-console.apps.ocp4.example.com >/dev/null) ]
do
echo "Waiting for router..."
sleep 10
done
echo "Router is up"
# Wait for authentication come online
while true
do
code=$(curl -k -s https://oauth-openshift.apps.ocp4.example.com)
if [[ ! -z ${code} ]] && [[ "${code:0:1}" == "{" ]] && [[ $(echo $code | jq -r '.code') -eq 403 ]]
then
break
fi
echo "Waiting for authentication..."
sleep 10
done
echo "Authentication is ready"
# Wait for critical operators come online
for oper in ingress kube-apiserver
do
while true
do
RETURN=0
JSON=$(oc get clusteroperators ${oper} -o json) || RETURN=1
[ ${RETURN} -eq 1 ] && echo "Could not reach Openshift API, trying again..."
FILTER=$(echo ${JSON} | jq -r '.status.conditions[]|select((.status=="True") and (.type=="Progressing"))') || RETURN=1
if [ ${RETURN} -eq 0 ] && [ "x${FILTER}" == "x" ]
then
RETURN=0
break
fi
echo "Waiting for the ${oper} operator to be ready..."
sleep 10
done
echo "The ${oper} operator is ready"
done
# Wait for MCP finish applying changes
while true
do
RETURN=0
JSON=$(oc get mcp -o json) || RETURN=1
[ ${RETURN} -eq 1 ] && echo "Could not reach Openshift API, trying again..."
FILTER=$(echo ${JSON} | jq -r '.items[].status.conditions[]|select((.status=="True") and (.type=="Updating"))') || RETURN=1
if [ ${RETURN} -eq 0 ] && [ "x${FILTER}" == "x" ]
then
RETURN=0
break
fi
echo "Waiting for Machine Config Operator to finish applying changes..."
sleep 10
done
echo "Machine Config Operator changes applied"
# Wait between retries
[ ${RETRY} -gt ${i} ] && sleep $(( 90*${i} ))
done
ENDCOLOR="\e[0m"
GREEN="\e[32m"
echo -e "${GREEN}[OK]${ENDCOLOR} OpenShift cluster ready."