From c6a852fe74890c9d890e8c35e7e4dcf2d5b84145 Mon Sep 17 00:00:00 2001 From: Maciej Borsz Date: Tue, 21 Aug 2018 09:54:46 +0200 Subject: [PATCH] Fix validate-cluster.sh for clusters with more than 500 nodes. --- cluster/validate-cluster.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cluster/validate-cluster.sh b/cluster/validate-cluster.sh index 3a101193ed..857c1c948a 100755 --- a/cluster/validate-cluster.sh +++ b/cluster/validate-cluster.sh @@ -98,7 +98,13 @@ while true; do # # We are assigning the result of kubectl_retry get nodes operation to the res # variable in that way, to prevent stopping the whole script on an error. - node=$(kubectl_retry get nodes) && res="$?" || res="$?" + # + # Bash command substitution $(kubectl_...) removes all trailing whitespaces + # which are important for line counting. + # Use trick from https://unix.stackexchange.com/a/383411 to avoid + # newline truncation. + node=$(kubectl_retry get nodes --no-headers; ret=$?; echo .; exit "$ret") && res="$?" || res="$?" + node="${node%.}" if [ "${res}" -ne "0" ]; then if [[ "${attempt}" -gt "${last_run:-$MAX_ATTEMPTS}" ]]; then echo -e "${color_red} Failed to get nodes.${color_norm}" @@ -107,8 +113,9 @@ while true; do continue fi fi - found=$(($(echo "${node}" | wc -l) - 1)) - ready=$(($(echo "${node}" | grep -v "NotReady" | wc -l ) - 1)) + found=$(echo -n "${node}" | wc -l) + # Use grep || true so that empty result doesn't return nonzero exit code. + ready=$(echo -n "${node}" | grep -c -v "NotReady" || true) if (( "${found}" == "${EXPECTED_NUM_NODES}" )) && (( "${ready}" == "${EXPECTED_NUM_NODES}")); then break