From c58f6f9e3b327ac49e31701038b79f4a167e751d Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Thu, 18 Apr 2019 21:34:27 -0700 Subject: [PATCH] make E2E_CLUSTER_PROJECT globally available (#692) * make E2E_CLUSTER_PROJECT globally available * add comment * export E2E_CLUSTER_PROJECT * fix CR issues * remove readonly for two KO vars --- scripts/README.md | 5 +++-- scripts/e2e-tests.sh | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index b33543080e..06cff45e00 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -155,8 +155,9 @@ This is a helper script for Knative E2E test scripts. To use it: 1. Write logic for the end-to-end tests. Run all go tests using `go_test_e2e()` (or `report_go_test()` if you need a more fine-grained control) and call `fail_test()` or `success()` if any of them failed. The environment variable - `KO_DOCKER_REPO` will be set according to the test cluster. You can also use - the following boolean (0 is false, 1 is true) environment variables for the logic: + `KO_DOCKER_REPO` and `E2E_PROJECT_ID` will be set according to the test cluster. + You can also use the following boolean (0 is false, 1 is true) environment + variables for the logic: - `EMIT_METRICS`: true if `--emit-metrics` was passed. diff --git a/scripts/e2e-tests.sh b/scripts/e2e-tests.sh index e0c949cc43..2741d7ffc1 100755 --- a/scripts/e2e-tests.sh +++ b/scripts/e2e-tests.sh @@ -113,8 +113,7 @@ function save_metadata() { geo_key="Zone" geo_value="${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}" fi - local gcloud_project="$(gcloud config get-value project)" - local cluster_version="$(gcloud container clusters list --project=${gcloud_project} --format='value(currentMasterVersion)')" + local cluster_version="$(gcloud container clusters list --project=${E2E_PROJECT_ID} --format='value(currentMasterVersion)')" cat << EOF > ${ARTIFACTS}/metadata.json { "E2E:${geo_key}": "${geo_value}", @@ -269,6 +268,11 @@ function setup_test_cluster() { header "Setting up test cluster" + # Set the actual project the test cluster resides in + # It will be a project assigned by Boskos if test is running on Prow, + # otherwise will be ${GCP_PROJECT} set up by user. + readonly export E2E_PROJECT_ID="$(gcloud config get-value project)" + # Save some metadata about cluster creation for using in prow and testgrid save_metadata @@ -280,9 +284,10 @@ function setup_test_cluster() { if [[ -z "$(kubectl get clusterrolebinding cluster-admin-binding 2> /dev/null)" ]]; then acquire_cluster_admin_role ${k8s_user} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION} ${E2E_CLUSTER_ZONE} kubectl config set-context ${k8s_cluster} --namespace=default - export KO_DOCKER_REPO=gcr.io/$(gcloud config get-value project)/${E2E_BASE_NAME}-e2e-img + export KO_DOCKER_REPO=gcr.io/${E2E_PROJECT_ID}/${E2E_BASE_NAME}-e2e-img fi + echo "- Project is ${E2E_PROJECT_ID}" echo "- Cluster is ${k8s_cluster}" echo "- User is ${k8s_user}" echo "- Docker is ${KO_DOCKER_REPO}"