From bf68fc4a4b4ee0ae06339e6880a26ac892ea84f7 Mon Sep 17 00:00:00 2001 From: David Zhu Date: Thu, 14 Mar 2019 14:31:44 -0700 Subject: [PATCH] Use bundled tar kubectl for integration tests. Add log verbosity args. --- deploy/common.sh | 2 ++ deploy/kubernetes/delete-driver.sh | 4 ++-- deploy/kubernetes/deploy-driver.sh | 15 ++++++++------- test/k8s-integration/main.go | 12 ++++++++++++ test/run-k8s-integration.sh | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/deploy/common.sh b/deploy/common.sh index 3d4e56175..da0475341 100644 --- a/deploy/common.sh +++ b/deploy/common.sh @@ -2,6 +2,8 @@ # Common variables readonly KUSTOMIZE_PATH="${PKGDIR}/bin/kustomize" +readonly VERBOSITY="${GCE_PD_VERBOSITY:-2}" +readonly KUBECTL="${GCE_PD_KUBECTL:-kubectl}" # Common functions diff --git a/deploy/kubernetes/delete-driver.sh b/deploy/kubernetes/delete-driver.sh index dea43e8df..c46fa3a88 100755 --- a/deploy/kubernetes/delete-driver.sh +++ b/deploy/kubernetes/delete-driver.sh @@ -16,5 +16,5 @@ source "${PKGDIR}/deploy/common.sh" ensure_kustomize -${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | kubectl delete --ignore-not-found -f - -kubectl delete secret cloud-sa --ignore-not-found +${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 diff --git a/deploy/kubernetes/deploy-driver.sh b/deploy/kubernetes/deploy-driver.sh index 121a976ff..bdd3f3de3 100755 --- a/deploy/kubernetes/deploy-driver.sh +++ b/deploy/kubernetes/deploy-driver.sh @@ -76,20 +76,21 @@ if [ "$skip_sa_check" != true ]; then check_service_account fi -if ! kubectl get secret cloud-sa -n ${NAMESPACE}; +if ! ${KUBECTL} get secret cloud-sa -v="${VERBOSITY}" -n ${NAMESPACE}; then - kubectl create secret generic cloud-sa --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 cluster-admin-binding; +if ! ${KUBECTL} get clusterrolebinding -v="${VERBOSITY}" cluster-admin-binding; then - kubectl create clusterrolebinding cluster-admin-binding --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 +# 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 -kubectl apply -v=9 -f $tmp_spec +${KUBECTL} apply -v="${VERBOSITY}" -f $tmp_spec + diff --git a/test/k8s-integration/main.go b/test/k8s-integration/main.go index b1ec64154..d05f6780a 100644 --- a/test/k8s-integration/main.go +++ b/test/k8s-integration/main.go @@ -148,6 +148,18 @@ func handle() error { return fmt.Errorf("failed to build Kubernetes: %v", err) } + kshPath := filepath.Join(k8sDir, "cluster", "kubectl.sh") + _, err = os.Stat(kshPath) + if err == nil { + // Set kubectl to the one bundled in the k8s tar for versioning + err = os.Setenv("GCE_PD_KUBECTL", kshPath) + if err != nil { + return fmt.Errorf("failed to set cluster specific kubectl: %v", err) + } + } else { + glog.Errorf("could not find cluster kubectl at %s, falling back to default kubectl", kshPath) + } + err = clusterUp(k8sDir) if err != nil { return fmt.Errorf("failed to cluster up: %v", err) diff --git a/test/run-k8s-integration.sh b/test/run-k8s-integration.sh index e0f4ba7c3..b74de0439 100755 --- a/test/run-k8s-integration.sh +++ b/test/run-k8s-integration.sh @@ -13,6 +13,7 @@ readonly PKGDIR=${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver readonly overlay_name="${GCE_PD_OVERLAY_NAME:-prow-head-template}" readonly boskos_resource_type="${GCE_PD_BOSKOS_RESOURCE_TYPE:-gce-project}" readonly do_driver_build="${GCE_PD_DO_DRIVER_BUILD:-true}" +export GCE_PD_VERBOSITY=9 make -C ${PKGDIR} test-k8s-integration ${PKGDIR}/bin/k8s-integration-test --kube-version=master --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}