Skip to content

Commit 7540f7f

Browse files
authored
Merge pull request #588 from jeremyje/shelllint
Resolve most shellcheck warnings.
2 parents 5705585 + 03b7a08 commit 7540f7f

13 files changed

+56
-56
lines changed

deploy/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readonly KUBECTL="${GCE_PD_KUBECTL:-kubectl}"
88
# Common functions
99

1010
function ensure_var(){
11-
if [[ -z "${!1}" ]];
11+
if [[ -z "${!1:-}" ]];
1212
then
1313
echo "${1} is unset"
1414
exit 1
@@ -26,5 +26,5 @@ function get_needed_roles()
2626
function ensure_kustomize()
2727
{
2828
ensure_var PKGDIR
29-
${PKGDIR}/deploy/kubernetes/install-kustomize.sh
29+
"${PKGDIR}/deploy/kubernetes/install-kustomize.sh"
3030
}

deploy/kubernetes/delete-driver.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ source "${PKGDIR}/deploy/common.sh"
1717

1818
ensure_kustomize
1919

20-
${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | ${KUBECTL} delete -v="${VERBOSITY}" --ignore-not-found -f -
20+
${KUSTOMIZE_PATH} build "${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION}" | ${KUBECTL} delete -v="${VERBOSITY}" --ignore-not-found -f -
2121
${KUBECTL} delete secret cloud-sa -v="${VERBOSITY}" --ignore-not-found
2222

23-
if [[ ${NAMESPACE} != "" && ${NAMESPACE} != "default" ]] && \
24-
${KUBECTL} get namespace ${NAMESPACE} -v="${VERBOSITY}";
23+
if [[ "${NAMESPACE}" != "" && "${NAMESPACE}" != "default" ]] && \
24+
${KUBECTL} get namespace "${NAMESPACE}" -v="${VERBOSITY}";
2525
then
26-
${KUBECTL} delete namespace ${NAMESPACE} -v="${VERBOSITY}"
26+
${KUBECTL} delete namespace "${NAMESPACE}" -v="${VERBOSITY}"
2727
fi

deploy/kubernetes/deploy-driver.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ source "${PKGDIR}/deploy/common.sh"
2323

2424
print_usage()
2525
{
26-
echo "deploy-driver.sh [--skip-sa-check]\n"
27-
echo "\t--skip-sa-check: don't check the service account for required roles"
26+
printf "deploy-driver.sh [--skip-sa-check]\n"
27+
printf "\t--skip-sa-check: don't check the service account for required roles"
2828
echo
2929
}
3030

3131
skip_sa_check=
32-
while [ ! -z "${1-}" ]; do
32+
while [ -n "${1-}" ]; do
3333
case $1 in
3434
--skip-sa-check ) shift
3535
skip_sa_check=true
@@ -49,20 +49,20 @@ function check_service_account()
4949
{
5050
# Using bash magic to parse JSON for IAM
5151
# Grepping for a line with client email returning anything quoted after the colon
52-
readonly IAM_NAME=$(grep -Po '"client_email": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
53-
readonly PROJECT=$(grep -Po '"project_id": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
54-
readonly GOTTEN_BIND_ROLES=$(gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:${IAM_NAME}")
52+
readonly IAM_NAME=$(grep -Po '"client_email": *\K"[^"]*"' "${GCE_PD_SA_DIR}/cloud-sa.json" | tr -d '"')
53+
readonly PROJECT=$(grep -Po '"project_id": *\K"[^"]*"' "${GCE_PD_SA_DIR}/cloud-sa.json" | tr -d '"')
54+
readonly GOTTEN_BIND_ROLES=$(gcloud projects get-iam-policy "${PROJECT}" --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:${IAM_NAME}")
5555
readonly BIND_ROLES=$(get_needed_roles)
5656
MISSING_ROLES=false
5757
for role in ${BIND_ROLES}
5858
do
59-
if ! grep -q $role <<<${GOTTEN_BIND_ROLES} ;
59+
if ! grep -q "$role" <<<"${GOTTEN_BIND_ROLES}" ;
6060
then
6161
echo "Missing role: $role"
6262
MISSING_ROLES=true
6363
fi
6464
done
65-
if [ "${MISSING_ROLES}" = true ];
65+
if [ "${MISSING_ROLES}" = true ];
6666
then
6767
echo "Cannot deploy with missing roles in service account, please run setup-project.sh to setup Service Account"
6868
exit 1
@@ -75,25 +75,25 @@ if [ "$skip_sa_check" != true ]; then
7575
check_service_account
7676
fi
7777

78-
if ! ${KUBECTL} get namespace ${NAMESPACE} -v="${VERBOSITY}";
78+
if ! ${KUBECTL} get namespace "${NAMESPACE}" -v="${VERBOSITY}";
7979
then
80-
${KUBECTL} create namespace ${NAMESPACE} -v="${VERBOSITY}"
80+
${KUBECTL} create namespace "${NAMESPACE}" -v="${VERBOSITY}"
8181
fi
8282

83-
if ! ${KUBECTL} get secret cloud-sa -v="${VERBOSITY}" -n ${NAMESPACE};
83+
if ! ${KUBECTL} get secret cloud-sa -v="${VERBOSITY}" -n "${NAMESPACE}";
8484
then
85-
${KUBECTL} create secret generic cloud-sa -v="${VERBOSITY}" --from-file="${GCE_PD_SA_DIR}/cloud-sa.json" -n ${NAMESPACE}
85+
${KUBECTL} create secret generic cloud-sa -v="${VERBOSITY}" --from-file="${GCE_PD_SA_DIR}/cloud-sa.json" -n "${NAMESPACE}"
8686
fi
8787

8888
# GKE Required Setup
8989
if ! ${KUBECTL} get clusterrolebinding -v="${VERBOSITY}" cluster-admin-binding;
9090
then
91-
${KUBECTL} create clusterrolebinding cluster-admin-binding -v="${VERBOSITY}" --clusterrole cluster-admin --user $(gcloud config get-value account)
91+
${KUBECTL} create clusterrolebinding cluster-admin-binding -v="${VERBOSITY}" --clusterrole cluster-admin --user "$(gcloud config get-value account)"
9292
fi
9393

9494
# Debug log: print ${KUBECTL} version
9595
${KUBECTL} version
9696

9797
readonly tmp_spec=/tmp/gcp-compute-persistent-disk-csi-driver-specs-generated.yaml
98-
${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | tee $tmp_spec
98+
${KUSTOMIZE_PATH} build "${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION}" | tee $tmp_spec
9999
${KUBECTL} apply -v="${VERBOSITY}" -f $tmp_spec

deploy/kubernetes/install-kustomize.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ readonly INSTALL_DIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-
1111
readonly KUSTOMIZE_PATH="${INSTALL_DIR}/kustomize"
1212

1313
if [ ! -f "${INSTALL_DIR}" ]; then
14-
mkdir -p ${INSTALL_DIR}
14+
mkdir -p "${INSTALL_DIR}"
1515
fi
1616
if [ -f "kustomize" ]; then
1717
rm kustomize
1818
fi
1919
echo "installing latest version of kustomize"
2020
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
21-
mv kustomize ${INSTALL_DIR}
21+
mv kustomize "${INSTALL_DIR}"

deploy/setup-project.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ readonly IAM_NAME="${GCE_PD_SA_NAME}@${IAM_PROJECT}.iam.gserviceaccount.com"
4242
# Check if SA exists
4343
CREATE_SA=true
4444
SA_JSON=$(gcloud iam service-accounts list --filter="name:${IAM_NAME}" --format="json")
45-
if [ "[]" != "${SA_JSON}" ];
45+
if [ "[]" != "${SA_JSON}" ];
4646
then
4747
CREATE_SA=false
4848
echo "Service account ${IAM_NAME} exists. Would you like to create a new one (y) or reuse the existing one (n)"
@@ -54,7 +54,7 @@ then
5454
fi
5555
fi
5656

57-
if [ "${CREATE_SA}" = true ];
57+
if [ "${CREATE_SA}" = true ];
5858
then
5959
# Delete Service Account Key
6060
if [ -f "${GCE_PD_SA_DIR}/cloud-sa.json" ];
@@ -88,7 +88,7 @@ fi
8888
# Bind service account to roles
8989
for role in ${BIND_ROLES}
9090
do
91-
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role ${role}
91+
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role "${role}"
9292
done
9393

9494
# Export key if needed

hack/verify-all.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -o pipefail
2020

2121
PKG_ROOT=$(git rev-parse --show-toplevel)
2222

23-
${PKG_ROOT}/hack/verify-gofmt.sh
24-
${PKG_ROOT}/hack/verify-govet.sh
23+
"${PKG_ROOT}/hack/verify-gofmt.sh"
24+
"${PKG_ROOT}/hack/verify-govet.sh"
2525

26-
make -C "${PKG_ROOT}" all
26+
make -C "${PKG_ROOT}" all

test/run-e2e-local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -o errexit
55

66
readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
77

8-
ginkgo --v "test/e2e/tests" -- --project ${PROJECT} --service-account ${IAM_NAME} --v=4 --logtostderr
8+
ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" --v=4 --logtostderr

test/run-k8s-integration-ci.sh

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}
2626

2727
export GCE_PD_VERBOSITY=9
2828

29-
make -C ${PKGDIR} test-k8s-integration
29+
make -C "${PKGDIR}" test-k8s-integration
3030

3131
base_cmd="${PKGDIR}/bin/k8s-integration-test \
3232
--run-in-prow=true --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
3333
--do-driver-build=${do_driver_build} --teardown-driver=${teardown_driver} --boskos-resource-type=${boskos_resource_type} \
3434
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml \
35-
--test-focus="External.Storage" --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
35+
--test-focus='External.Storage' --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
3636
--num-nodes=3 --image-type=${image_type}"
3737

3838
if [ "$use_gke_managed_driver" = false ]; then
@@ -57,4 +57,4 @@ else
5757
base_cmd="${base_cmd} --gce-region=${gce_region}"
5858
fi
5959

60-
eval $base_cmd
60+
eval "$base_cmd"

test/run-k8s-integration-local.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ source "${PKGDIR}/deploy/common.sh"
1212

1313
ensure_var GCE_PD_SA_DIR
1414

15-
make -C ${PKGDIR} test-k8s-integration
15+
make -C "${PKGDIR}" test-k8s-integration
1616

1717
# This version of the command creates a GKE cluster. It also downloads and builds a k8s release
1818
# so that it can run the test specified
@@ -76,8 +76,8 @@ make -C ${PKGDIR} test-k8s-integration
7676
# This version of the command does not build the driver or K8s, points to a
7777
# local K8s repo to get the e2e.test binary, and does not bring up or down the cluster
7878

79-
${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
80-
--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
81-
--deploy-overlay-name=dev --bringup-cluster=false --teardown-cluster=false --local-k8s-dir=$KTOP \
82-
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --do-driver-build=false --test-focus="External.Storage" \
83-
--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3}
79+
"${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
80+
--staging-image="${GCE_PD_CSI_STAGING_IMAGE}" --service-account-file="${GCE_PD_SA_DIR}/cloud-sa.json" \
81+
--deploy-overlay-name=dev --bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" \
82+
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --do-driver-build=false --test-focus='External.Storage' \
83+
--gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"

test/run-k8s-integration-migration-local.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readonly test_version=${TEST_VERSION:-master}
1313
ensure_var GCE_PD_CSI_STAGING_IMAGE
1414
ensure_var GCE_PD_SA_DIR
1515

16-
make -C ${PKGDIR} test-k8s-integration
16+
make -C "${PKGDIR}" test-k8s-integration
1717

1818
# ${PKGDIR}/bin/k8s-integration-test --kube-version=master --run-in-prow=false \
1919
# --staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
@@ -25,8 +25,8 @@ make -C ${PKGDIR} test-k8s-integration
2525
# This version of the command does not build the driver or K8s, points to a
2626
# local K8s repo to get the e2e.test binary, and does not bring up or down the cluster
2727
#
28-
${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
29-
--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
30-
--deploy-overlay-name=dev --test-focus=${GCE_PD_TEST_FOCUS} \
31-
--bringup-cluster=false --teardown-cluster=false --local-k8s-dir=$KTOP --migration-test=true \
32-
--do-driver-build=false --gce-zone=${GCE_PD_ZONE} --num-nodes=${NUM_NODES:-3}
28+
"${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
29+
--staging-image="${GCE_PD_CSI_STAGING_IMAGE}" --service-account-file="${GCE_PD_SA_DIR}/cloud-sa.json" \
30+
--deploy-overlay-name=dev --test-focus="${GCE_PD_TEST_FOCUS}" \
31+
--bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" --migration-test=true \
32+
--do-driver-build=false --gce-zone="${GCE_PD_ZONE}" --num-nodes="${NUM_NODES:-3}"

test/run-k8s-integration-migration.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ readonly GCE_PD_TEST_FOCUS="PersistentVolumes\sGCEPD|[V|v]olume\sexpand|\[sig-st
2424

2525
# TODO(#167): Enable reconstructions tests
2626

27-
make -C ${PKGDIR} test-k8s-integration
28-
${PKGDIR}/bin/k8s-integration-test --kube-version=${kube_version} \
27+
make -C "${PKGDIR}" test-k8s-integration
28+
"${PKGDIR}/bin/k8s-integration-test" --kube-version="${kube_version}" \
2929
--kube-feature-gates="CSIMigration=true,CSIMigrationGCE=true,ExpandCSIVolumes=true" --run-in-prow=true \
30-
--deploy-overlay-name=${overlay_name} --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
31-
--do-driver-build=${do_driver_build} --boskos-resource-type=${boskos_resource_type} \
32-
--migration-test=true --test-focus=${GCE_PD_TEST_FOCUS} \
33-
--gce-zone="us-central1-b" --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
30+
--deploy-overlay-name="${overlay_name}" --service-account-file="${E2E_GOOGLE_APPLICATION_CREDENTIALS}" \
31+
--do-driver-build="${do_driver_build}" --boskos-resource-type="${boskos_resource_type}" \
32+
--migration-test=true --test-focus="${GCE_PD_TEST_FOCUS}" \
33+
--gce-zone="us-central1-b" --deployment-strategy="${deployment_strategy}" --test-version="${test_version}" \
3434
--num-nodes=3

test/run-k8s-integration.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}
2626

2727
export GCE_PD_VERBOSITY=9
2828

29-
make -C ${PKGDIR} test-k8s-integration
29+
make -C "${PKGDIR}" test-k8s-integration
3030

3131
base_cmd="${PKGDIR}/bin/k8s-integration-test \
3232
--run-in-prow=true --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
3333
--do-driver-build=${do_driver_build} --teardown-driver=${teardown_driver} --boskos-resource-type=${boskos_resource_type} \
3434
--storageclass-files=sc-standard.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml \
35-
--test-focus="External.Storage" --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
35+
--test-focus='External.Storage' --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
3636
--num-nodes=3 --image-type=${image_type}"
3737

3838
if [ "$use_gke_managed_driver" = false ]; then
@@ -57,4 +57,4 @@ else
5757
base_cmd="${base_cmd} --gce-region=${gce_region}"
5858
fi
5959

60-
eval $base_cmd
60+
eval "$base_cmd"

test/run-windows-k8s-integration.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ readonly test_version=${TEST_VERSION:-master}
1717
readonly gce_zone=${GCE_CLUSTER_ZONE:-us-central1-b}
1818
readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}
1919

20-
make -C ${PKGDIR} test-k8s-integration
20+
make -C "${PKGDIR}" test-k8s-integration
2121

2222
base_cmd="${PKGDIR}/bin/k8s-integration-test \
2323
--platform=windows --bringup-cluster=false --teardown-cluster=false --teardown-driver=${teardown_driver}\
2424
--run-in-prow=true --deploy-overlay-name=${overlay_name} --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
2525
--do-driver-build=${do_driver_build} --gce-zone=${gce_zone} --test-version=${test_version}\
26-
--storageclass-files=sc-windows.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --test-focus="External.Storage" \
26+
--storageclass-files=sc-windows.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --test-focus='External.Storage' \
2727
--deployment-strategy=${deployment_strategy}"
2828

29-
eval $base_cmd
29+
eval "$base_cmd"

0 commit comments

Comments
 (0)