From 4454ce6f373c6687f803ab7822ba37a4750604c3 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Fri, 14 Feb 2020 16:12:18 -0800 Subject: [PATCH] fix shellcheck failures in health-monitor.sh --- cluster/gce/gci/health-monitor.sh | 16 ++++++++-------- hack/.shellcheck_failures | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cluster/gce/gci/health-monitor.sh b/cluster/gce/gci/health-monitor.sh index b89de05cdc0..722a856941d 100644 --- a/cluster/gce/gci/health-monitor.sh +++ b/cluster/gce/gci/health-monitor.sh @@ -33,22 +33,22 @@ function container_runtime_monitoring { # dockershim is still part of kubelet today. When kubelet is down, crictl pods # will also fail, and docker will be killed. This is undesirable especially when # docker live restore is disabled. - local healthcheck_command="docker ps" + local healthcheck_command=(docker ps) if [[ "${CONTAINER_RUNTIME:-docker}" != "docker" ]]; then - healthcheck_command="${crictl} pods" + healthcheck_command=("${crictl}" pods) fi # Container runtime startup takes time. Make initial attempts before starting # killing the container runtime. - until timeout 60 ${healthcheck_command} > /dev/null; do + until timeout 60 "${healthcheck_command[@]}" > /dev/null; do if (( attempt == max_attempts )); then echo "Max attempt ${max_attempts} reached! Proceeding to monitor container runtime healthiness." break fi - echo "$attempt initial attempt \"${healthcheck_command}\"! Trying again in $attempt seconds..." + echo "$attempt initial attempt \"${healthcheck_command[*]}\"! Trying again in $attempt seconds..." sleep "$(( 2 ** attempt++ ))" done while true; do - if ! timeout 60 ${healthcheck_command} > /dev/null; then + if ! timeout 60 "${healthcheck_command[@]}" > /dev/null; then echo "Container runtime ${container_runtime_name} failed!" if [[ "$container_runtime_name" == "docker" ]]; then # Dump stack of docker daemon for investigation. @@ -71,10 +71,10 @@ function kubelet_monitoring { sleep 120 local -r max_seconds=10 local output="" - while [ 1 ]; do + while true; do if ! output=$(curl -m "${max_seconds}" -f -s -S http://127.0.0.1:10248/healthz 2>&1); then # Print the response and/or errors. - echo $output + echo "${output}" echo "Kubelet is unhealthy!" systemctl kill kubelet # Wait for a while, as we don't want to kill it again before it is really up. @@ -108,5 +108,5 @@ if [[ "${component}" == "container-runtime" ]]; then elif [[ "${component}" == "kubelet" ]]; then kubelet_monitoring else - echo "Health monitoring for component "${component}" is not supported!" + echo "Health monitoring for component \"${component}\" is not supported!" fi diff --git a/hack/.shellcheck_failures b/hack/.shellcheck_failures index 6b6aaf67bed..9245235f2d6 100644 --- a/hack/.shellcheck_failures +++ b/hack/.shellcheck_failures @@ -2,7 +2,6 @@ ./cluster/gce/config-test.sh ./cluster/gce/gci/configure-helper.sh ./cluster/gce/gci/configure.sh -./cluster/gce/gci/health-monitor.sh ./cluster/gce/gci/master-helper.sh ./cluster/gce/upgrade.sh ./cluster/gce/util.sh