@@ -7,6 +7,8 @@ set -o errtrace
77set -x
88
99export KUBECONFIG=/opt/kubeconfig
10+ MAXIMUM_LOGIN_RETRY=10
11+ RETRY_DELAY=5
1012
1113if [ ! -f /opt/crc/pass_kubeadmin ]; then
1214 echo " kubeadmin password file not found"
2123
2224
2325echo " Logging into OpenShift with kubeadmin user to update $KUBECONFIG "
24- COUNTER=1
25- MAXIMUM_LOGIN_RETRY=10
2626
27- # use a `(set +x)` subshell to avoid leaking the password
28- until (set +x ; oc login --insecure-skip-tls-verify=true -u kubeadmin -p " $( cat /opt/crc/pass_kubeadmin) " https://api.crc.testing:6443 > /dev/null 2>&1 ); do
29- if [ " $COUNTER " -ge " $MAXIMUM_LOGIN_RETRY " ]; then
30- echo " Unable to login to the cluster..., authentication failed."
27+ try_login () {
28+ ( # use a `(set +x)` subshell to avoid leaking the password
29+ set +x
30+ set +e # don't abort on error in this subshell
31+ oc login --insecure-skip-tls-verify=true \
32+ -u kubeadmin \
33+ -p " $( cat /opt/crc/pass_kubeadmin) " \
34+ https://api.crc.testing:6443 > /dev/null 2>&1
35+ )
36+ success=" $? "
37+ if [[ " $success " == 0 ]]; then
38+ echo " Login successed"
39+ else
40+ echo " Login didn't complete ..."
41+ fi
42+
43+ return " $success "
44+ }
45+
46+ for (( counter= 1 ; counter<= MAXIMUM_LOGIN_RETRY; counter++ )) ; do
47+ echo " Login attempt $counter /$MAXIMUM_LOGIN_RETRY …"
48+ if try_login; then
49+ break
50+ fi
51+ if (( counter == MAXIMUM_LOGIN_RETRY )) ; then
52+ echo " Unable to login to the cluster after $counter attempts; authentication failed."
3153 exit 1
3254 fi
33- echo " Logging into OpenShift with updated credentials try $COUNTER , hang on...."
34- sleep 5
35- (( COUNTER++ ))
55+ sleep " $RETRY_DELAY "
3656done
3757
3858# need to set a marker to let `crc` know the cluster is ready
3959touch /tmp/.crc-cluster-ready
60+
61+ echo " All done"
62+
63+ exit 0
0 commit comments