Skip to content

Commit 241ec4e

Browse files
committed
improve bootstrap logic to wait for at least 2 apiserver instances
1 parent 3420c22 commit 241ec4e

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

data/data/bootstrap/files/usr/local/bin/report-progress.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# shellcheck disable=SC1091 # using path on bootstrap machine
44
. /usr/local/bin/bootstrap-service-record.sh
55

6+
# shellcheck disable=SC1091 # using path on bootstrap machine
7+
. /usr/local/bin/wait-for-ha-api.sh
8+
69
KUBECONFIG="${1}"
710

811
wait_for_existence() {
@@ -17,6 +20,9 @@ echo "Waiting for bootstrap to complete..."
1720
wait_for_existence /opt/openshift/.bootkube.done
1821
record_service_stage_success
1922

23+
## wait for API to be available
24+
wait_for_ha_api
25+
2026
record_service_stage_start "report-bootstrap-complete"
2127
echo "Reporting install progress..."
2228
while ! oc --kubeconfig="$KUBECONFIG" create -f - <<-EOF
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
wait_for_ha_api() {
4+
if [ "$BOOTSTRAP_INPLACE" = true ]
5+
then
6+
return 0
7+
fi
8+
9+
echo "Waiting for at least 2 available IP addresses for the default/kubernetes service"
10+
while ! is_api_available
11+
do
12+
sleep 5
13+
done
14+
}
15+
16+
##
17+
## for HA cluster, we mark the bootstrap process as complete when there
18+
## are at least two IP addresses available to the endpoints
19+
## of the default/kubernetes service object.
20+
## TODO: move this to kas operator as a subcommand of the render command
21+
is_api_available() {
22+
output=$(oc --kubeconfig="$KUBECONFIG" get endpoints kubernetes --namespace=default -o jsonpath='{range @.subsets[*]}{range @.addresses[*]}{.ip}{" "}' 2>&1 )
23+
# shellcheck disable=SC2124
24+
status=$?
25+
if [[ $status -ne 0 ]]
26+
then
27+
echo "The following error happened while retrieving the default/kubernetes endpoint object"
28+
echo "$output"
29+
return 1
30+
fi
31+
32+
echo "Got the following addresses for the default/kubernetes endpoint object: $output"
33+
count=$(echo "$output" | wc -w)
34+
if [[ ! $count -gt 1 ]]
35+
then
36+
return 1
37+
fi
38+
39+
echo "Got at least 2 available addresses for the default/kubernetes service"
40+
return 0
41+
}

data/data/bootstrap/gcp/files/usr/local/bin/report-progress.sh

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

3+
# shellcheck disable=SC1091 # using path on bootstrap machine
4+
. /usr/local/bin/wait-for-ha-api.sh
5+
36
KUBECONFIG="${1}"
47

58
wait_for_existance() {
@@ -18,6 +21,9 @@ systemctl stop gcp-routes.service
1821
echo "Waiting for bootstrap to complete..."
1922
wait_for_existance /opt/openshift/.bootkube.done
2023

24+
## wait for API to be available
25+
wait_for_ha_api
26+
2127
echo "Reporting install progress..."
2228
while ! oc --kubeconfig="$KUBECONFIG" create -f - <<-EOF
2329
apiVersion: v1

0 commit comments

Comments
 (0)