From 5e682d1a43873a985437a6eb499429376c79646e Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Sat, 6 Mar 2021 10:49:13 -0800 Subject: [PATCH 1/4] fix shellcheck success / failure messages --- hack/verify-shellcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index 654ba88047c..6a2ace06309 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -113,7 +113,7 @@ fi # print a message based on the result if [ $res -eq 0 ]; then - echo 'Congratulations! All shell files are passing lint (excluding those in hack/.shellcheck_failures).' + echo 'Congratulations! All shell files are passing lint :-)' else { echo @@ -121,7 +121,7 @@ else echo 'If the above warnings do not make sense, you can exempt this warning with a comment' echo ' (if your reviewer is okay with it).' echo 'In general please prefer to fix the error, we have already disabled specific lints' - echo ' that the project chooses to ignire.' + echo ' that the project chooses to ignore.' echo 'See: https://github.com/koalaman/shellcheck/wiki/Ignore#ignoring-one-specific-instance-in-a-file' echo } >&2 From 7705d8c3de25c1dcd9a20768c6821cb81e64d3ce Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Sat, 6 Mar 2021 13:14:28 -0800 Subject: [PATCH 2/4] upgrade shellcheck to v0.7.1, use multi-arch digest --- hack/verify-shellcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index 6a2ace06309..f97158f7b57 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -27,9 +27,9 @@ source "${KUBE_ROOT}/hack/lib/util.sh" # required version for this script, if not installed on the host we will # use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE -SHELLCHECK_VERSION="0.7.0" +SHELLCHECK_VERSION="0.7.1" # upstream shellcheck latest stable image as of October 23rd, 2019 -SHELLCHECK_IMAGE="koalaman/shellcheck-alpine:v0.7.0@sha256:24bbf52aae6eaa27accc9f61de32d30a1498555e6ef452966d0702ff06f38ecb" +SHELLCHECK_IMAGE="docker.io/koalaman/shellcheck-alpine:v0.7.1@sha256:d6147f30864ddb7c9cf983fc277d345bc315e798e309ddf70062b194843ee252" # disabled lints disabled=( From a0cd54a7f161449e239e89e63aff6ebd3c8dd97c Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Sat, 6 Mar 2021 13:19:17 -0800 Subject: [PATCH 3/4] fix trivial shell quoting issues surfaced by shellcheck v0.7.1 --- hack/lib/golang.sh | 2 +- test/cmd/core.sh | 2 +- test/images/pets/zookeeper-installer/on-start.sh | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 5fd81f02349..746c600dffb 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -874,7 +874,7 @@ kube::golang::build_binaries() { cat "/tmp//${platform//\//_}.build" done - exit ${fails} + exit "${fails}" else for platform in "${platforms[@]}"; do kube::log::status "Building go targets for ${platform}:" "${targets[@]}" diff --git a/test/cmd/core.sh b/test/cmd/core.sh index a2ffc056dbf..cbc87de7ad3 100755 --- a/test/cmd/core.sh +++ b/test/cmd/core.sh @@ -560,7 +560,7 @@ run_pod_tests() { resourceVersion=$(kubectl get "${kube_flags[@]}" pod valid-pod -o go-template='{{ .metadata.resourceVersion }}') ((resourceVersion+=100)) # Command - kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]},"metadata":{"resourceVersion":"'$resourceVersion'"}}' 2> "${ERROR_FILE}" || true + kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]},"metadata":{"resourceVersion":"'"$resourceVersion"'"}}' 2> "${ERROR_FILE}" || true # Post-condition: should get an error reporting the conflict if grep -q "please apply your changes to the latest version and try again" "${ERROR_FILE}"; then kube::log::status "\"kubectl patch with resourceVersion $resourceVersion\" returns error as expected: $(cat "${ERROR_FILE}")" diff --git a/test/images/pets/zookeeper-installer/on-start.sh b/test/images/pets/zookeeper-installer/on-start.sh index b478a5a1f5e..66e5bd2faf3 100755 --- a/test/images/pets/zookeeper-installer/on-start.sh +++ b/test/images/pets/zookeeper-installer/on-start.sh @@ -60,7 +60,7 @@ for peer in "${PEERS[@]}"; do if [[ "${peer}" == *"${HOSTNAME}"* ]]; then MY_ID=$i MY_NAME=${peer} - echo $i > "${MY_ID_FILE}" + echo "$i" > "${MY_ID_FILE}" echo "server.${i}=${peer}:2888:3888:observer;2181" >> "${CFG_BAK}" else if [[ $(echo srvr | /opt/nc "${peer}" 2181 | grep Mode) = "Mode: leader" ]]; then @@ -95,10 +95,10 @@ ADD_SERVER="server.$MY_ID=$MY_NAME:2888:3888:participant;0.0.0.0:2181" # Prove that we've actually joined the running cluster ITERATION=0 until echo config | /opt/nc localhost 2181 | grep "${ADD_SERVER}" > /dev/null; do - echo $ITERATION] waiting for updated config to sync back to localhost + echo "$ITERATION"] waiting for updated config to sync back to localhost sleep 1 (( ITERATION=ITERATION+1 )) - if [ $ITERATION -eq 20 ]; then + if [ "$ITERATION" -eq 20 ]; then exit 1 fi done From f643388cb40c45dfe644e77e1f7a3cc5c395aaba Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Sat, 6 Mar 2021 13:28:58 -0800 Subject: [PATCH 4/4] allo overriding docker in shellcheck --- hack/verify-shellcheck.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index f97158f7b57..165522d8e5b 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -25,6 +25,9 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/util.sh" +# allow overriding docker cli, which should work fine for this script +DOCKER="${DOCKER:-docker}" + # required version for this script, if not installed on the host we will # use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE SHELLCHECK_VERSION="0.7.1" @@ -105,7 +108,7 @@ if ${HAVE_SHELLCHECK}; then shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" || res=$? else echo "Using shellcheck ${SHELLCHECK_VERSION} docker image." - docker run \ + "${DOCKER}" run \ --rm -v "${KUBE_ROOT}:${KUBE_ROOT}" -w "${KUBE_ROOT}" \ "${SHELLCHECK_IMAGE}" \ shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" || res=$?