Skip to content

Commit fb06b87

Browse files
Merge pull request #8429 from tkashem/bootstrap
OCPBUGS-30860: Use infrastructure API to detect cluster topology
2 parents d48a31f + 38951e2 commit fb06b87

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

data/data/bootstrap/files/usr/local/bin/wait-for-ha-api.sh

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
11
#!/usr/bin/env bash
22

33
wait_for_ha_api() {
4-
if [ "$BOOTSTRAP_INPLACE" = true ]
5-
then
6-
return 0
7-
fi
4+
while :
5+
do
6+
is_topology_ha
7+
retcode=$?
8+
if [[ $retcode -eq 2 ]]
9+
then
10+
echo "topology is not HighlyAvailable, no need to wait for API availability"
11+
return 0
12+
fi
13+
if [[ $retcode -eq 0 ]]
14+
then
15+
## HA topology, we can start the wait loop for API availability
16+
break
17+
fi
18+
19+
## error happened, so let's retry after 5s
20+
sleep 5
21+
done
822

923
echo "Waiting for at least 2 available IP addresses for the default/kubernetes service"
1024
while ! is_api_available
1125
do
12-
sleep 5
26+
sleep 5
1327
done
1428
}
1529

30+
## 0 - HA control plane 'HighlyAvailable'
31+
## 1 - error condition
32+
## 2 - other topology
33+
is_topology_ha() {
34+
output=$(oc --kubeconfig="$KUBECONFIG" get infrastructures cluster -o jsonpath='{.status.controlPlaneTopology}' 2>&1 )
35+
# shellcheck disable=SC2124
36+
status=$?
37+
if [[ $status -ne 0 ]]
38+
then
39+
echo "The following error happened while retrieving infrastructures/cluster object"
40+
echo "$output"
41+
return 1 # unexpected error condition
42+
fi
43+
44+
if [[ -z $output ]]
45+
then
46+
echo "status.infrastructureTopology of the infrastructures/cluster object is empty"
47+
return 1 # unexpected error condition
48+
fi
49+
50+
if [[ $output == "HighlyAvailable" ]]
51+
then
52+
return 0 ## HA control plane
53+
fi
54+
55+
return 2 ## non HA control plane
56+
}
57+
1658
##
1759
## for HA cluster, we mark the bootstrap process as complete when there
1860
## are at least two IP addresses available to the endpoints

0 commit comments

Comments
 (0)