Skip to content

Resolve most shellcheck warnings. #588

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

Merged
merged 1 commit into from
Aug 21, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readonly KUBECTL="${GCE_PD_KUBECTL:-kubectl}"
# Common functions

function ensure_var(){
if [[ -z "${!1}" ]];
if [[ -z "${!1:-}" ]];
then
echo "${1} is unset"
exit 1
Expand All @@ -26,5 +26,5 @@ function get_needed_roles()
function ensure_kustomize()
{
ensure_var PKGDIR
${PKGDIR}/deploy/kubernetes/install-kustomize.sh
"${PKGDIR}/deploy/kubernetes/install-kustomize.sh"
}
8 changes: 4 additions & 4 deletions deploy/kubernetes/delete-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ source "${PKGDIR}/deploy/common.sh"

ensure_kustomize

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

if [[ ${NAMESPACE} != "" && ${NAMESPACE} != "default" ]] && \
${KUBECTL} get namespace ${NAMESPACE} -v="${VERBOSITY}";
if [[ "${NAMESPACE}" != "" && "${NAMESPACE}" != "default" ]] && \
${KUBECTL} get namespace "${NAMESPACE}" -v="${VERBOSITY}";
then
${KUBECTL} delete namespace ${NAMESPACE} -v="${VERBOSITY}"
${KUBECTL} delete namespace "${NAMESPACE}" -v="${VERBOSITY}"
fi
28 changes: 14 additions & 14 deletions deploy/kubernetes/deploy-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ source "${PKGDIR}/deploy/common.sh"

print_usage()
{
echo "deploy-driver.sh [--skip-sa-check]\n"
echo "\t--skip-sa-check: don't check the service account for required roles"
printf "deploy-driver.sh [--skip-sa-check]\n"
printf "\t--skip-sa-check: don't check the service account for required roles"
echo
}

skip_sa_check=
while [ ! -z "${1-}" ]; do
while [ -n "${1-}" ]; do
case $1 in
--skip-sa-check ) shift
skip_sa_check=true
Expand All @@ -49,20 +49,20 @@ function check_service_account()
{
# Using bash magic to parse JSON for IAM
# Grepping for a line with client email returning anything quoted after the colon
readonly IAM_NAME=$(grep -Po '"client_email": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
readonly PROJECT=$(grep -Po '"project_id": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
readonly GOTTEN_BIND_ROLES=$(gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:${IAM_NAME}")
readonly IAM_NAME=$(grep -Po '"client_email": *\K"[^"]*"' "${GCE_PD_SA_DIR}/cloud-sa.json" | tr -d '"')
readonly PROJECT=$(grep -Po '"project_id": *\K"[^"]*"' "${GCE_PD_SA_DIR}/cloud-sa.json" | tr -d '"')
readonly GOTTEN_BIND_ROLES=$(gcloud projects get-iam-policy "${PROJECT}" --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:${IAM_NAME}")
readonly BIND_ROLES=$(get_needed_roles)
MISSING_ROLES=false
for role in ${BIND_ROLES}
do
if ! grep -q $role <<<${GOTTEN_BIND_ROLES} ;
if ! grep -q "$role" <<<"${GOTTEN_BIND_ROLES}" ;
then
echo "Missing role: $role"
MISSING_ROLES=true
fi
done
if [ "${MISSING_ROLES}" = true ];
if [ "${MISSING_ROLES}" = true ];
then
echo "Cannot deploy with missing roles in service account, please run setup-project.sh to setup Service Account"
exit 1
Expand All @@ -75,25 +75,25 @@ if [ "$skip_sa_check" != true ]; then
check_service_account
fi

if ! ${KUBECTL} get namespace ${NAMESPACE} -v="${VERBOSITY}";
if ! ${KUBECTL} get namespace "${NAMESPACE}" -v="${VERBOSITY}";
then
${KUBECTL} create namespace ${NAMESPACE} -v="${VERBOSITY}"
${KUBECTL} create namespace "${NAMESPACE}" -v="${VERBOSITY}"
fi

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

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

# Debug log: print ${KUBECTL} version
${KUBECTL} version

readonly tmp_spec=/tmp/gcp-compute-persistent-disk-csi-driver-specs-generated.yaml
${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | tee $tmp_spec
${KUSTOMIZE_PATH} build "${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION}" | tee $tmp_spec
${KUBECTL} apply -v="${VERBOSITY}" -f $tmp_spec
4 changes: 2 additions & 2 deletions deploy/kubernetes/install-kustomize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ readonly INSTALL_DIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-
readonly KUSTOMIZE_PATH="${INSTALL_DIR}/kustomize"

if [ ! -f "${INSTALL_DIR}" ]; then
mkdir -p ${INSTALL_DIR}
mkdir -p "${INSTALL_DIR}"
fi
if [ -f "kustomize" ]; then
rm kustomize
fi
echo "installing latest version of kustomize"
curl -s "https://github.com/raw/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
mv kustomize ${INSTALL_DIR}
mv kustomize "${INSTALL_DIR}"
6 changes: 3 additions & 3 deletions deploy/setup-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ readonly IAM_NAME="${GCE_PD_SA_NAME}@${IAM_PROJECT}.iam.gserviceaccount.com"
# Check if SA exists
CREATE_SA=true
SA_JSON=$(gcloud iam service-accounts list --filter="name:${IAM_NAME}" --format="json")
if [ "[]" != "${SA_JSON}" ];
if [ "[]" != "${SA_JSON}" ];
then
CREATE_SA=false
echo "Service account ${IAM_NAME} exists. Would you like to create a new one (y) or reuse the existing one (n)"
Expand All @@ -54,7 +54,7 @@ then
fi
fi

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

# Export key if needed
Expand Down
6 changes: 3 additions & 3 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set -o pipefail

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

${PKG_ROOT}/hack/verify-gofmt.sh
${PKG_ROOT}/hack/verify-govet.sh
"${PKG_ROOT}/hack/verify-gofmt.sh"
"${PKG_ROOT}/hack/verify-govet.sh"

make -C "${PKG_ROOT}" all
make -C "${PKG_ROOT}" all
2 changes: 1 addition & 1 deletion test/run-e2e-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -o errexit

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

ginkgo --v "test/e2e/tests" -- --project ${PROJECT} --service-account ${IAM_NAME} --v=4 --logtostderr
ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" --v=4 --logtostderr
6 changes: 3 additions & 3 deletions test/run-k8s-integration-ci.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}

export GCE_PD_VERBOSITY=9

make -C ${PKGDIR} test-k8s-integration
make -C "${PKGDIR}" test-k8s-integration

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

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

eval $base_cmd
eval "$base_cmd"
12 changes: 6 additions & 6 deletions test/run-k8s-integration-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ source "${PKGDIR}/deploy/common.sh"

ensure_var GCE_PD_SA_DIR

make -C ${PKGDIR} test-k8s-integration
make -C "${PKGDIR}" test-k8s-integration

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

${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
--deploy-overlay-name=dev --bringup-cluster=false --teardown-cluster=false --local-k8s-dir=$KTOP \
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --do-driver-build=false --test-focus="External.Storage" \
--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3}
"${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
--staging-image="${GCE_PD_CSI_STAGING_IMAGE}" --service-account-file="${GCE_PD_SA_DIR}/cloud-sa.json" \
--deploy-overlay-name=dev --bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" \
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --do-driver-build=false --test-focus='External.Storage' \
--gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"
12 changes: 6 additions & 6 deletions test/run-k8s-integration-migration-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readonly test_version=${TEST_VERSION:-master}
ensure_var GCE_PD_CSI_STAGING_IMAGE
ensure_var GCE_PD_SA_DIR

make -C ${PKGDIR} test-k8s-integration
make -C "${PKGDIR}" test-k8s-integration

# ${PKGDIR}/bin/k8s-integration-test --kube-version=master --run-in-prow=false \
# --staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
Expand All @@ -25,8 +25,8 @@ make -C ${PKGDIR} test-k8s-integration
# This version of the command does not build the driver or K8s, points to a
# local K8s repo to get the e2e.test binary, and does not bring up or down the cluster
#
${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
--deploy-overlay-name=dev --test-focus=${GCE_PD_TEST_FOCUS} \
--bringup-cluster=false --teardown-cluster=false --local-k8s-dir=$KTOP --migration-test=true \
--do-driver-build=false --gce-zone=${GCE_PD_ZONE} --num-nodes=${NUM_NODES:-3}
"${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
--staging-image="${GCE_PD_CSI_STAGING_IMAGE}" --service-account-file="${GCE_PD_SA_DIR}/cloud-sa.json" \
--deploy-overlay-name=dev --test-focus="${GCE_PD_TEST_FOCUS}" \
--bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" --migration-test=true \
--do-driver-build=false --gce-zone="${GCE_PD_ZONE}" --num-nodes="${NUM_NODES:-3}"
12 changes: 6 additions & 6 deletions test/run-k8s-integration-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ readonly GCE_PD_TEST_FOCUS="PersistentVolumes\sGCEPD|[V|v]olume\sexpand|\[sig-st

# TODO(#167): Enable reconstructions tests

make -C ${PKGDIR} test-k8s-integration
${PKGDIR}/bin/k8s-integration-test --kube-version=${kube_version} \
make -C "${PKGDIR}" test-k8s-integration
"${PKGDIR}/bin/k8s-integration-test" --kube-version="${kube_version}" \
--kube-feature-gates="CSIMigration=true,CSIMigrationGCE=true,ExpandCSIVolumes=true" --run-in-prow=true \
--deploy-overlay-name=${overlay_name} --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
--do-driver-build=${do_driver_build} --boskos-resource-type=${boskos_resource_type} \
--migration-test=true --test-focus=${GCE_PD_TEST_FOCUS} \
--gce-zone="us-central1-b" --deployment-strategy=${deployment_strategy} --test-version=${test_version} \
--deploy-overlay-name="${overlay_name}" --service-account-file="${E2E_GOOGLE_APPLICATION_CREDENTIALS}" \
--do-driver-build="${do_driver_build}" --boskos-resource-type="${boskos_resource_type}" \
--migration-test=true --test-focus="${GCE_PD_TEST_FOCUS}" \
--gce-zone="us-central1-b" --deployment-strategy="${deployment_strategy}" --test-version="${test_version}" \
--num-nodes=3
6 changes: 3 additions & 3 deletions test/run-k8s-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}

export GCE_PD_VERBOSITY=9

make -C ${PKGDIR} test-k8s-integration
make -C "${PKGDIR}" test-k8s-integration

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

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

eval $base_cmd
eval "$base_cmd"
6 changes: 3 additions & 3 deletions test/run-windows-k8s-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ readonly test_version=${TEST_VERSION:-master}
readonly gce_zone=${GCE_CLUSTER_ZONE:-us-central1-b}
readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}

make -C ${PKGDIR} test-k8s-integration
make -C "${PKGDIR}" test-k8s-integration

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

eval $base_cmd
eval "$base_cmd"