# Make several attempts to deal with slow cluster birth.
# Make several attempts to deal with slow cluster birth.
attempt=0
attempt=0
while true;do
while true;do
# The "kubectl get nodes" output is three columns like this:
# The "kubectl get nodes -o template" exports node information.
#
# NAME LABELS STATUS
# kubernetes-minion-03nb <none> Ready
#
#
# Echo the output, strip the first line, then gather 2 counts:
# Echo the output and gather 2 counts:
# - Total number of nodes.
# - Total number of nodes.
# - Number of "ready" nodes.
# - Number of "ready" nodes.
#
#
# Suppress errors from kubectl output because during cluster bootstrapping
# Suppress errors from kubectl output because during cluster bootstrapping
# for clusters where the master node is registered, the apiserver will become
# for clusters where the master node is registered, the apiserver will become
# available and then get restarted as the kubelet configures the docker bridge.
# available and then get restarted as the kubelet configures the docker bridge.
"${KUBE_ROOT}/cluster/kubectl.sh" get nodes >"${MINIONS_FILE}" 2> /dev/null ||true
nodes_status=$("${KUBE_ROOT}/cluster/kubectl.sh" get nodes -o template --template='{{range .items}}{{with index .status.conditions 0}}{{.type}}:{{.status}},{{end}}{{end}}'--api-version=v1)
# Set the timeout to ~10minutes (40 x 15 second) to avoid timeouts for 100-node clusters.
# Set the timeout to ~10minutes (40 x 15 second) to avoid timeouts for 100-node clusters.
if(( attempt > 40 ));then
if(( attempt > 40 ));then
echo-e"${color_red}Detected ${ready} ready nodes, found ${found} nodes out of expected ${EXPECTED_NUM_NODES}. Your cluster may not be working.${color_norm}"
echo-e"${color_red}Detected ${ready} ready nodes, found ${found} nodes out of expected ${EXPECTED_NUM_NODES}. Your cluster may not be working.${color_norm}"
kubectl_output=$("${KUBE_ROOT}/cluster/kubectl.sh" get cs)||true
# The "kubectl componentstatuses -o template" exports components health information.
# The "kubectl componentstatuses" output is four columns like this:
#
# COMPONENT HEALTH MSG ERR
# controller-manager Healthy ok nil
#
#
# Parse the output to capture the value of the second column("HEALTH"), then use grep to
# Echo the output and gather 2 counts:
# count the number of times it doesn't match "Healthy".
# - Total number of componentstatuses.
non_success_count=$(echo"${kubectl_output}" | \
# - Number of "healthy" components.
sed'1d' |
cs_status=$("${KUBE_ROOT}/cluster/kubectl.sh" get componentstatuses -o template --template='{{range .items}}{{with index .conditions 0}}{{.type}}:{{.status}},{{end}}{{end}}'--api-version=v1)||true