Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shellcheck failures in cluster/validate-cluster.sh #81345

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions cluster/validate-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function kubectl_retry() {
while ! "${KUBE_ROOT}/cluster/kubectl.sh" "$@"; do
tries=$((tries-1))
if [[ ${tries} -le 0 ]]; then
echo "('kubectl $@' failed, giving up)" >&2
echo "('kubectl $*' failed, giving up)" >&2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the following failure.

In ./cluster/validate-cluster.sh line 42:
      echo "('kubectl $@' failed, giving up)" >&2
                      ^-- SC2145: Argument mixes string and array. Use * or separate argument.

return 1
fi
echo "(kubectl failed, will retry ${tries} times)" >&2
Expand All @@ -59,8 +59,8 @@ if [[ "${KUBERNETES_PROVIDER:-}" == "gce" ]]; then
echo "Validating gce cluster, MULTIZONE=${MULTIZONE:-}"
# In multizone mode we need to add instances for all nodes in the region.
if [[ "${MULTIZONE:-}" == "true" ]]; then
EXPECTED_NUM_NODES=$(gcloud -q compute instances list --project="${PROJECT}" --format=[no-heading] \
--filter="(name ~ '${NODE_INSTANCE_PREFIX}.*' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}.*') AND zone:($(gcloud -q compute zones list --project="${PROJECT}" --filter=region=${REGION} --format=csv[no-heading]\(name\) | tr "\n" "," | sed "s/,$//"))" | wc -l)
EXPECTED_NUM_NODES=$(gcloud -q compute instances list --project="${PROJECT}" --format="[no-heading]" \
--filter="(name ~ '${NODE_INSTANCE_PREFIX}.*' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}.*') AND zone:($(gcloud -q compute zones list --project="${PROJECT}" --filter=region="${REGION}" --format="csv[no-heading](name)" | tr "\n" "," | sed "s/,$//"))" | wc -l)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix SC2102 and SC2086.

In ./cluster/validate-cluster.sh line 62:
    EXPECTED_NUM_NODES=$(gcloud -q compute instances list --project="${PROJECT}" --format=[no-heading] \
                                                                                          ^----------^ SC2102: Ranges can only match single chars (mentioned due to duplicates).
In ./cluster/validate-cluster.sh line 63:
      --filter="(name ~ '${NODE_INSTANCE_PREFIX}.*' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}.*') AND zone:($(gcloud -q compute zones list --project="${PROJECT}" --filter=region=${REGION} --format=csv[no-heading]\(name\) | tr "\n" "," | sed  "s/,$//"))" | wc -l)
                                                                                                                                                                                   ^-------^ SC2086: Double quote to prevent globbing and word splitting.
                                                                                                                                                                                                         ^----------^ SC2102: Ranges can only match single chars (mentioned due to duplicates).

I have not run validate-cluster.sh because I have no kubernetes on GCP.
But I tested gcloud command with these changes in my environment, and no failure appeared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nested quoting changes LGTM

echo "Computing number of nodes, NODE_INSTANCE_PREFIX=${NODE_INSTANCE_PREFIX}, REGION=${REGION}, EXPECTED_NUM_NODES=${EXPECTED_NUM_NODES}"
fi
else
Expand Down Expand Up @@ -112,7 +112,7 @@ while true; do
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}"
echo -e "${color_red:-} Failed to get nodes.${color_norm:-}"
exit 1
else
continue
Expand All @@ -134,11 +134,11 @@ while true; do
break
else
if [[ "${REQUIRED_NUM_NODES}" -le "${ready}" ]]; then
echo -e "${color_green}Found ${REQUIRED_NUM_NODES} Nodes, allowing additional ${ADDITIONAL_ITERATIONS} iterations for other Nodes to join.${color_norm}"
echo -e "${color_green:-}Found ${REQUIRED_NUM_NODES} Nodes, allowing additional ${ADDITIONAL_ITERATIONS} iterations for other Nodes to join.${color_norm}"
last_run="${last_run:-$((attempt + ADDITIONAL_ITERATIONS - 1))}"
fi
if [[ "${attempt}" -gt "${last_run:-$MAX_ATTEMPTS}" ]]; then
echo -e "${color_yellow}Detected ${ready} ready nodes, found ${found} nodes out of expected ${EXPECTED_NUM_NODES}. Your cluster may not be fully functional.${color_norm}"
echo -e "${color_yellow:-}Detected ${ready} ready nodes, found ${found} nodes out of expected ${EXPECTED_NUM_NODES}. Your cluster may not be fully functional.${color_norm}"
kubectl_retry get nodes
if [[ "${REQUIRED_NUM_NODES}" -gt "${ready}" ]]; then
exit 1
Expand Down
1 change: 0 additions & 1 deletion hack/.shellcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
./cluster/gce/util.sh
./cluster/log-dump/log-dump.sh
./cluster/pre-existing/util.sh
./cluster/validate-cluster.sh