Skip to content

Commit 0ff7e46

Browse files
authored
Merge pull request kubernetes#73746 from mrbobbytables/kubemark-shellcheck
Fix shellcheck lint errors in Kubemark scripts
2 parents d532d50 + e137f47 commit 0ff7e46

File tree

15 files changed

+184
-122
lines changed

15 files changed

+184
-122
lines changed

cluster/kubemark/gce/config-default.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# gce/util.sh script which assumes config filename), but if some things that
2020
# are enabled by default should not run in hollow clusters, they should be disabled here.
2121

22+
# shellcheck disable=SC2034 # Variables sourced in other scripts.
23+
2224
source "${KUBE_ROOT}/cluster/gce/config-common.sh"
2325

2426
GCLOUD=gcloud
@@ -115,7 +117,7 @@ ENABLE_KUBEMARK_CLUSTER_AUTOSCALER="${ENABLE_KUBEMARK_CLUSTER_AUTOSCALER:-false}
115117
# (e.g. kubemark master, Heapster) enough resources to handle maximum cluster size.
116118
if [[ "${ENABLE_KUBEMARK_CLUSTER_AUTOSCALER}" == "true" ]]; then
117119
NUM_REPLICAS=1
118-
if [[ ! -z "$NUM_NODES" ]]; then
120+
if [[ -n "$NUM_NODES" ]]; then
119121
echo "WARNING: Using Cluster Autoscaler, ignoring NUM_NODES parameter. Set KUBEMARK_AUTOSCALER_MAX_NODES to specify maximum size of the cluster."
120122
fi
121123
fi

cluster/kubemark/iks/config-default.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# Cloud information
1818
RANDGEN=$(dd if=/dev/urandom bs=64 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=16 count=1 2>/dev/null | sed 's/[A-Z]//g')
19+
# shellcheck disable=2034 # Variable sourced in other scripts.
1920
KUBE_NAMESPACE="kubemark_${RANDGEN}"
2021
KUBEMARK_IMAGE_TAG="${KUBEMARK_IMAGE_TAG:-2}"
2122
KUBEMARK_IMAGE_LOCATION="${KUBEMARK_IMAGE_LOCATION:-${KUBE_ROOT}/cluster/images/kubemark}"

cluster/kubemark/util.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
18-
source ${KUBE_ROOT}/test/kubemark/cloud-provider-config.sh
19-
source ${KUBE_ROOT}/cluster/${CLOUD_PROVIDER}/util.sh
20-
source ${KUBE_ROOT}/cluster/kubemark/${CLOUD_PROVIDER}/config-default.sh
17+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
18+
source "${KUBE_ROOT}/test/kubemark/cloud-provider-config.sh"
19+
source "${KUBE_ROOT}/cluster/${CLOUD_PROVIDER}/util.sh"
20+
source "${KUBE_ROOT}/cluster/kubemark/${CLOUD_PROVIDER}/config-default.sh"

hack/.shellcheck_failures

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
./cluster/gce/upgrade.sh
1919
./cluster/gce/util.sh
2020
./cluster/images/conformance/run_e2e.sh
21-
./cluster/kubemark/gce/config-default.sh
22-
./cluster/kubemark/iks/config-default.sh
23-
./cluster/kubemark/util.sh
2421
./cluster/log-dump/log-dump.sh
2522
./cluster/pre-existing/util.sh
2623
./cluster/restore-from-backup.sh
@@ -133,16 +130,6 @@
133130
./test/images/volume/rbd/create_block.sh
134131
./test/images/volume/rbd/mon.sh
135132
./test/images/volume/rbd/osd.sh
136-
./test/kubemark/common/util.sh
137-
./test/kubemark/gce/util.sh
138-
./test/kubemark/iks/shutdown.sh
139-
./test/kubemark/iks/startup.sh
140-
./test/kubemark/iks/util.sh
141-
./test/kubemark/master-log-dump.sh
142-
./test/kubemark/resources/start-kubemark-master.sh
143-
./test/kubemark/run-e2e-tests.sh
144-
./test/kubemark/start-kubemark.sh
145-
./test/kubemark/stop-kubemark.sh
146133
./third_party/forked/shell2junit/sh2ju.sh
147134
./third_party/intemp/intemp.sh
148135
./third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh

test/kubemark/common/util.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Running cmd $RETRIES times in case of failures.
1818
function run-cmd-with-retries {
1919
RETRIES="${RETRIES:-3}"
20-
for attempt in $(seq 1 ${RETRIES}); do
20+
for attempt in $(seq 1 "${RETRIES}"); do
2121
local ret_val=0
2222
exec 5>&1 # Duplicate &1 to &5 for use below.
2323
# We don't use 'local' to declare result as then ret_val always gets value 0.
@@ -26,19 +26,24 @@ function run-cmd-with-retries {
2626
if [[ "${ret_val:-0}" -ne "0" ]]; then
2727
if [[ $(echo "${result}" | grep -c "already exists") -gt 0 ]]; then
2828
if [[ "${attempt}" == 1 ]]; then
29+
# shellcheck disable=SC2154 # Color defined in sourced script
2930
echo -e "${color_red}Failed to $1 $2 ${3:-} as the resource hasn't been deleted from a previous run.${color_norm}" >& 2
3031
exit 1
3132
fi
33+
# shellcheck disable=SC2154 # Color defined in sourced script
3234
echo -e "${color_yellow}Succeeded to $1 $2 ${3:-} in the previous attempt, but status response wasn't received.${color_norm}"
3335
return 0
3436
fi
37+
# shellcheck disable=SC2154 # Color defined in sourced script
3538
echo -e "${color_yellow}Attempt $attempt failed to $1 $2 ${3:-}. Retrying.${color_norm}" >& 2
36-
sleep $(($attempt * 5))
39+
sleep $((attempt * 5))
3740
else
41+
# shellcheck disable=SC2154 # Color defined in sourced script
3842
echo -e "${color_green}Succeeded to $1 $2 ${3:-}.${color_norm}"
3943
return 0
4044
fi
4145
done
46+
# shellcheck disable=SC2154 # Color defined in sourced script
4247
echo -e "${color_red}Failed to $1 $2 ${3:-}.${color_norm}" >& 2
4348
exit 1
4449
}

test/kubemark/gce/util.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../../..
17+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../../..
1818

1919
source "${KUBE_ROOT}/test/kubemark/common/util.sh"
2020

@@ -47,7 +47,7 @@ function get-or-create-master-ip {
4747
}
4848

4949
function create-master-instance-with-resources {
50-
GCLOUD_COMMON_ARGS="--project ${PROJECT} --zone ${ZONE}"
50+
GCLOUD_COMMON_ARGS=(--project "${PROJECT}" --zone "${ZONE}")
5151
# Override the master image project to cos-cloud for COS images staring with `cos` string prefix.
5252
DEFAULT_GCI_PROJECT=google-containers
5353
if [[ "${GCI_VERSION}" == "cos"* ]]; then
@@ -56,13 +56,13 @@ function create-master-instance-with-resources {
5656
MASTER_IMAGE_PROJECT=${KUBE_GCE_MASTER_PROJECT:-${DEFAULT_GCI_PROJECT}}
5757

5858
run-gcloud-compute-with-retries disks create "${MASTER_NAME}-pd" \
59-
${GCLOUD_COMMON_ARGS} \
59+
"${GCLOUD_COMMON_ARGS[@]}" \
6060
--type "${MASTER_DISK_TYPE}" \
6161
--size "${MASTER_DISK_SIZE}" &
6262

6363
if [ "${EVENT_PD:-}" == "true" ]; then
6464
run-gcloud-compute-with-retries disks create "${MASTER_NAME}-event-pd" \
65-
${GCLOUD_COMMON_ARGS} \
65+
"${GCLOUD_COMMON_ARGS[@]}" \
6666
--type "${MASTER_DISK_TYPE}" \
6767
--size "${MASTER_DISK_SIZE}" &
6868
fi
@@ -72,7 +72,7 @@ function create-master-instance-with-resources {
7272
wait
7373

7474
run-gcloud-compute-with-retries instances create "${MASTER_NAME}" \
75-
${GCLOUD_COMMON_ARGS} \
75+
"${GCLOUD_COMMON_ARGS[@]}" \
7676
--address "${MASTER_IP}" \
7777
--machine-type "${MASTER_SIZE}" \
7878
--image-project="${MASTER_IMAGE_PROJECT}" \
@@ -84,13 +84,13 @@ function create-master-instance-with-resources {
8484
--disk "name=${MASTER_NAME}-pd,device-name=master-pd,mode=rw,boot=no,auto-delete=no"
8585

8686
run-gcloud-compute-with-retries instances add-metadata "${MASTER_NAME}" \
87-
${GCLOUD_COMMON_ARGS} \
87+
"${GCLOUD_COMMON_ARGS[@]}" \
8888
--metadata-from-file startup-script="${KUBE_ROOT}/test/kubemark/resources/start-kubemark-master.sh" &
8989

9090
if [ "${EVENT_PD:-}" == "true" ]; then
9191
echo "Attaching ${MASTER_NAME}-event-pd to ${MASTER_NAME}"
9292
run-gcloud-compute-with-retries instances attach-disk "${MASTER_NAME}" \
93-
${GCLOUD_COMMON_ARGS} \
93+
"${GCLOUD_COMMON_ARGS[@]}" \
9494
--disk "${MASTER_NAME}-event-pd" \
9595
--device-name="master-event-pd" &
9696
fi
@@ -112,20 +112,20 @@ function execute-cmd-on-master-with-retries() {
112112
}
113113

114114
function copy-files() {
115-
run-gcloud-compute-with-retries scp --recurse --zone="${ZONE}" --project="${PROJECT}" $@
115+
run-gcloud-compute-with-retries scp --recurse --zone="${ZONE}" --project="${PROJECT}" "$@"
116116
}
117117

118118
function delete-master-instance-and-resources {
119-
GCLOUD_COMMON_ARGS="--project ${PROJECT} --zone ${ZONE} --quiet"
119+
GCLOUD_COMMON_ARGS=(--project "${PROJECT}" --zone "${ZONE}" --quiet)
120120

121121
gcloud compute instances delete "${MASTER_NAME}" \
122-
${GCLOUD_COMMON_ARGS} || true
122+
"${GCLOUD_COMMON_ARGS[@]}" || true
123123

124124
gcloud compute disks delete "${MASTER_NAME}-pd" \
125-
${GCLOUD_COMMON_ARGS} || true
125+
"${GCLOUD_COMMON_ARGS[@]}" || true
126126

127127
gcloud compute disks delete "${MASTER_NAME}-event-pd" \
128-
${GCLOUD_COMMON_ARGS} &> /dev/null || true
128+
"${GCLOUD_COMMON_ARGS[@]}" &> /dev/null || true
129129

130130
gcloud compute addresses delete "${MASTER_NAME}-ip" \
131131
--project "${PROJECT}" \
@@ -138,9 +138,9 @@ function delete-master-instance-and-resources {
138138

139139
if [ "${SEPARATE_EVENT_MACHINE:-false}" == "true" ]; then
140140
gcloud compute instances delete "${EVENT_STORE_NAME}" \
141-
${GCLOUD_COMMON_ARGS} || true
141+
"${GCLOUD_COMMON_ARGS[@]}" || true
142142

143143
gcloud compute disks delete "${EVENT_STORE_NAME}-pd" \
144-
${GCLOUD_COMMON_ARGS} || true
144+
"${GCLOUD_COMMON_ARGS[@]}" || true
145145
fi
146146
}

test/kubemark/iks/shutdown.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ RESOURCE_DIRECTORY="${KUBEMARK_DIRECTORY}/resources"
2424
complete-login
2525

2626
# Remove resources created for kubemark
27+
# shellcheck disable=SC2154 # Color defined in sourced script
2728
echo -e "${color_yellow}REMOVING RESOURCES${color_norm}"
2829
spawn-config
2930
"${KUBECTL}" delete -f "${RESOURCE_DIRECTORY}/addons" &> /dev/null || true
@@ -35,8 +36,9 @@ rm -rf "${RESOURCE_DIRECTORY}/addons"
3536
# Remove clusters, namespaces, and deployments
3637
delete-clusters
3738
if [[ -f "${RESOURCE_DIRECTORY}/iks-namespacelist.sh" ]] ; then
38-
bash ${RESOURCE_DIRECTORY}/iks-namespacelist.sh
39-
rm -f ${RESOURCE_DIRECTORY}/iks-namespacelist.sh
39+
bash "${RESOURCE_DIRECTORY}/iks-namespacelist.sh"
40+
rm -f "${RESOURCE_DIRECTORY}/iks-namespacelist.sh"
4041
fi
42+
# shellcheck disable=SC2154 # Color defined in sourced script
4143
echo -e "${color_blue}EXECUTION COMPLETE${color_norm}"
4244
exit 0

0 commit comments

Comments
 (0)