From 116ba7bfbf434e303fa2b3a21fd0104b9d4e1f20 Mon Sep 17 00:00:00 2001 From: Adriano Cunha <35786489+adrcunha@users.noreply.github.com> Date: Thu, 5 Apr 2018 14:50:50 -0700 Subject: [PATCH] Run the end-to-end tests in presubmit (#106) The end-to-end tests are run only if the build and unit tests pass. Bonus: * assorted minor cleanups in the script * partially addresses issue https://github.com/elafros/elafros/issues/503 * updates to e2e-tests.sh: - reset to the default namespace after creating the cluster - create test cluster in us-central-1a, as us-east-1d is reaching its resource limit - dump info about the project used, for test diagnostic purposes --- tests/e2e-tests.sh | 6 +++++- tests/presubmit-tests.sh | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/e2e-tests.sh b/tests/e2e-tests.sh index ac3c395e..22a76522 100755 --- a/tests/e2e-tests.sh +++ b/tests/e2e-tests.sh @@ -30,7 +30,7 @@ # Test cluster parameters and location of generated test images readonly E2E_CLUSTER_NAME=ela-e2e-cluster -readonly E2E_CLUSTER_ZONE=us-east1-d +readonly E2E_CLUSTER_ZONE=us-central1-a readonly E2E_CLUSTER_NODES=2 readonly E2E_CLUSTER_MACHINE=n1-standard-2 readonly GKE_VERSION=v1.9.4-gke.1 @@ -160,6 +160,8 @@ if [[ -z ${K8S_CLUSTER_OVERRIDE} ]]; then kubectl --username=admin --password=$passwd create clusterrolebinding cluster-admin-binding \ --clusterrole=cluster-admin \ --user=${K8S_USER_OVERRIDE} + # Make sure we're in the default namespace + kubectl config set-context $K8S_CLUSTER_OVERRIDE --namespace=default fi readonly USING_EXISTING_CLUSTER @@ -172,6 +174,8 @@ fi echo "=================================================" echo "* Cluster is ${K8S_CLUSTER_OVERRIDE}" echo "* Docker is ${DOCKER_REPO_OVERRIDE}" +echo "*** Project info ***" +gcloud compute project-info describe header "Building and starting the controller" trap teardown EXIT diff --git a/tests/presubmit-tests.sh b/tests/presubmit-tests.sh index 1190d5c7..ffb51848 100755 --- a/tests/presubmit-tests.sh +++ b/tests/presubmit-tests.sh @@ -21,14 +21,21 @@ set -o errexit set -o pipefail -SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. -OG_DOCKER_REPO="${DOCKER_REPO_OVERRIDE}" +# Useful environment variables +readonly BUILDCRD_ROOT=$(dirname ${BASH_SOURCE})/.. +[[ $USER == "prow" ]] && IS_PROW=1 || IS_PROW=0 +readonly IS_PROW -set -o nounset +# Save *_OVERRIDE variables in case a cleanup is required. +readonly OG_DOCKER_REPO="${DOCKER_REPO_OVERRIDE}" + +function restore_env() { + export DOCKER_REPO_OVERRIDE="${OG_DOCKER_REPO}" +} function cleanup() { header "Cleanup (teardown)" - export DOCKER_REPO_OVERRIDE="${OG_DOCKER_REPO}" + restore_env # --expunge is a workaround for https://github.com/elafros/elafros/issues/366 bazel clean --expunge || true } @@ -39,13 +46,13 @@ function header() { echo "=================================================" } -cd ${SCRIPT_ROOT} +cd ${BUILDCRD_ROOT} # Set the required env vars to dummy values to satisfy bazel. export DOCKER_REPO_OVERRIDE=REPO_NOT_SET # For local runs, cleanup before and after the tests. -if [[ ! $USER == "prow" ]]; then +if (( ! IS_PROW )); then trap cleanup EXIT header "Cleanup (setup)" # --expunge is a workaround for https://github.com/elafros/elafros/issues/366 @@ -58,7 +65,11 @@ fi header "Building phase" bazel build //cmd/... //pkg/... -# Step 2: Run tests. +# Step 2: Run unit tests. header "Testing phase" bazel test //cmd/... //pkg/... +# Step 3: Run end-to-end tests. +# Restore environment variables, let e2e-tests.sh handle them. +restore_env +./tests/e2e-tests.sh