From 1a785ea8cef6f86c68a5ccd4e171de0c4d58e72f Mon Sep 17 00:00:00 2001 From: Adriano Cunha <35786489+adrcunha@users.noreply.github.com> Date: Wed, 10 Oct 2018 12:28:25 -0700 Subject: [PATCH 1/4] Fix SSH keys workaround for kubetest Create the ~/.ssh dir if it doesn't exist, don't assume it always exist. Backported from https://github.com/knative/test-infra/pull/151 --- test/e2e-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 27c51c88ae67..92d6ff3c0e25 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -192,6 +192,7 @@ if (( ! RUN_TESTS )); then fi # SSH keys are not used, but kubetest checks for their existence. # Touch them so if they don't exist, empty files are create to satisfy the check. + mkdir -p $HOME/.ssh touch $HOME/.ssh/google_compute_engine.pub touch $HOME/.ssh/google_compute_engine # Clear user and cluster variables, so they'll be set to the test cluster. From d49b51e2e7fdf0b5088fe6ec8dc90f92bea958bf Mon Sep 17 00:00:00 2001 From: Adriano Cunha Date: Wed, 10 Oct 2018 13:28:15 -0700 Subject: [PATCH 2/4] Fix authentication for test clusters Instead of relying on default options, use basic authentication for test cluster. Also make acquire_cluster_admin_role() handle auth through certificates, since it's used also on deployment. Backport of https://github.com/knative/test-infra/pull/115 --- test/e2e-tests.sh | 2 +- test/library.sh | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 92d6ff3c0e25..a62a8ffce06b 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -178,7 +178,7 @@ if (( ! RUN_TESTS )); then header "Creating test cluster" # Smallest cluster required to run the end-to-end-tests CLUSTER_CREATION_ARGS=( - --gke-create-args="--enable-autoscaling --min-nodes=1 --max-nodes=${E2E_CLUSTER_NODES} --scopes=cloud-platform" + --gke-create-args="--enable-autoscaling --min-nodes=1 --max-nodes=${E2E_CLUSTER_NODES} --scopes=cloud-platform --enable-basic-auth --no-issue-client-certificate" --gke-shape={\"default\":{\"Nodes\":${E2E_CLUSTER_NODES}\,\"MachineType\":\"${E2E_CLUSTER_MACHINE}\"}} --provider=gke --deployment=gke diff --git a/test/library.sh b/test/library.sh index 2cda0002670b..907a1240439f 100755 --- a/test/library.sh +++ b/test/library.sh @@ -113,10 +113,29 @@ function acquire_cluster_admin_role() { # might not have the necessary permission. local password=$(gcloud --format="value(masterAuth.password)" \ container clusters describe $2 --zone=$3) - kubectl --username=admin --password=$password \ - create clusterrolebinding cluster-admin-binding \ + if [[ -n "${password}" ]]; then + # Cluster created with basic authentication + kubectl config set-credentials cluster-admin \ + --username=admin --password=${password} + else + local cert=$(mktemp) + local key=$(mktemp) + echo "Certificate in ${cert}, key in ${key}" + gcloud --format="value(masterAuth.clientCertificate)" \ + container clusters describe $2 --zone=$3 | base64 -d > ${cert} + gcloud --format="value(masterAuth.clientKey)" \ + container clusters describe $2 --zone=$3 | base64 -d > ${key} + kubectl config set-credentials cluster-admin \ + --client-certificate=${cert} --client-key=${key} + fi + kubectl config set-context $(kubectl config current-context) \ + --user=cluster-admin + kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole=cluster-admin \ --user=$1 + # Reset back to the default account + gcloud container clusters get-credentials \ + $2 --zone=$3 --project $(gcloud config get-value project) } # Runs a go test and generate a junit summary through bazel. From ba291f4fd4a22d112fbdee0404525a64841e3103 Mon Sep 17 00:00:00 2001 From: Adriano Cunha Date: Wed, 10 Oct 2018 17:11:29 -0700 Subject: [PATCH 3/4] Increase E2E tests timeout to 20 minutes Currently 10 minutes may not be enough, for example as in #1701. Backport of #1702. --- test/e2e-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index a62a8ffce06b..7cd5694eaad9 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -139,7 +139,7 @@ function run_e2e_tests() { kubectl label namespace $2 istio-injection=enabled --overwrite local options="" (( EMIT_METRICS )) && options="-emitmetrics" - report_go_test -v -tags=e2e -count=1 ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$3 ${options} + report_go_test -v -tags=e2e -count=1 -timeout=20m ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$3 ${options} local result=$? [[ ${result} -ne 0 ]] && dump_stack_info From 9eefc776070e6d11645c42777c545419c98a682f Mon Sep 17 00:00:00 2001 From: Adriano Cunha Date: Thu, 11 Oct 2018 09:20:12 -0700 Subject: [PATCH 4/4] Drop Dockerfile in test images * removed dockerfiles * moved test images to the same location * adjust repo * fix command and docs * update upload-test-images.sh * preserve import paths * fix appYaml path * preserve path in upload-test-images.sh Backport of #1792. --- test/README.md | 11 +++----- .../test_images/pizzaplanetv1/Dockerfile | 27 ------------------- .../test_images/pizzaplanetv2/Dockerfile | 27 ------------------- test/e2e-tests.sh | 14 +++++++--- test/e2e/helloworld_shell_test.go | 2 +- test/e2e/test_images/README.md | 7 ----- test/e2e/test_images/autoscale/Dockerfile | 6 ----- test/e2e/test_images/helloworld/Dockerfile | 6 ----- test/e2e_flags.go | 2 +- test/{conformance => }/test_images/README.md | 2 +- .../{e2e => }/test_images/autoscale/README.md | 0 .../test_images/autoscale/autoscale.go | 0 .../test_images/helloworld/README.md | 0 .../test_images/helloworld/helloworld.go | 0 .../test_images/helloworld/helloworld.yaml | 0 .../test_images/pizzaplanetv1/README.md | 0 .../test_images/pizzaplanetv1/main.go | 0 .../test_images/pizzaplanetv2/README.md | 0 .../test_images/pizzaplanetv2/main.go | 0 test/upload-test-images.sh | 12 +++------ 20 files changed, 22 insertions(+), 94 deletions(-) delete mode 100644 test/conformance/test_images/pizzaplanetv1/Dockerfile delete mode 100644 test/conformance/test_images/pizzaplanetv2/Dockerfile delete mode 100644 test/e2e/test_images/README.md delete mode 100644 test/e2e/test_images/autoscale/Dockerfile delete mode 100644 test/e2e/test_images/helloworld/Dockerfile rename test/{conformance => }/test_images/README.md (91%) rename test/{e2e => }/test_images/autoscale/README.md (100%) rename test/{e2e => }/test_images/autoscale/autoscale.go (100%) rename test/{e2e => }/test_images/helloworld/README.md (100%) rename test/{e2e => }/test_images/helloworld/helloworld.go (100%) rename test/{e2e => }/test_images/helloworld/helloworld.yaml (100%) rename test/{conformance => }/test_images/pizzaplanetv1/README.md (100%) rename test/{conformance => }/test_images/pizzaplanetv1/main.go (100%) rename test/{conformance => }/test_images/pizzaplanetv2/README.md (100%) rename test/{conformance => }/test_images/pizzaplanetv2/main.go (100%) diff --git a/test/README.md b/test/README.md index 7c95b6ca9890..896786df6b52 100644 --- a/test/README.md +++ b/test/README.md @@ -98,6 +98,8 @@ go test -v -tags=e2e -count=1 ./test/e2e --resolvabledomain ### Building the test images +Note: this is only required when you run conformance/e2e tests locally with `go test` commands. + The [`upload-test-images.sh`](./upload-test-images.sh) script can be used to build and push the test images used by the conformance and e2e tests. It requires: @@ -109,17 +111,12 @@ test images used by the conformance and e2e tests. It requires: To run the script for all end to end test images: ```bash -./test/upload-test-images.sh ./test/e2e/test_images -./test/upload-test-images.sh ./test/conformance/test_images +./test/upload-test-images.sh ``` ### Adding new test images -New test images should be placed in their own subdirectories. Be sure to to include a `Dockerfile` -for building and running the test image. - -The new test images will also need to be uploaded to the e2e tests Docker repo. You will need one -of the owners found in [`/test/OWNERS`](OWNERS) to do this. +New test images should be placed in `./test/test_images`. ## Flags diff --git a/test/conformance/test_images/pizzaplanetv1/Dockerfile b/test/conformance/test_images/pizzaplanetv1/Dockerfile deleted file mode 100644 index 5de3f532e178..000000000000 --- a/test/conformance/test_images/pizzaplanetv1/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2018 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM golang AS builder - -WORKDIR /go/src/pizzaplanetv1 -ADD . /go/src/pizzaplanetv1 - -RUN CGO_ENABLED=0 go build . - - -FROM gcr.io/distroless/base - -COPY --from=builder /go/src/pizzaplanetv1/pizzaplanetv1 /entrypoint - -ENTRYPOINT ["/entrypoint"] diff --git a/test/conformance/test_images/pizzaplanetv2/Dockerfile b/test/conformance/test_images/pizzaplanetv2/Dockerfile deleted file mode 100644 index f314e658226b..000000000000 --- a/test/conformance/test_images/pizzaplanetv2/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2018 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM golang AS builder - -WORKDIR /go/src/pizzaplanetv2 -ADD . /go/src/pizzaplanetv2 - -RUN CGO_ENABLED=0 go build . - - -FROM gcr.io/distroless/base - -COPY --from=builder /go/src/pizzaplanetv2/pizzaplanetv2 /entrypoint - -ENTRYPOINT ["/entrypoint"] diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 7cd5694eaad9..0439ec0a4f31 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -133,13 +133,20 @@ function dump_stack_info() { echo "***************************************" } +function publish_test_images() { + local image_dirs="$(find ${SERVING_ROOT_DIR}/test/test_images -mindepth 1 -maxdepth 1 -type d)" + for image_dir in ${image_dirs}; do + ko publish -P "github.com/knative/serving/test/test_images/$(basename ${image_dir})" + done +} + function run_e2e_tests() { header "Running tests in $1" kubectl create namespace $2 kubectl label namespace $2 istio-injection=enabled --overwrite local options="" (( EMIT_METRICS )) && options="-emitmetrics" - report_go_test -v -tags=e2e -count=1 -timeout=20m ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$3 ${options} + report_go_test -v -tags=e2e -count=1 -timeout=20m ./test/$1 ${options} local result=$? [[ ${result} -ne 0 ]] && dump_stack_info @@ -280,6 +287,7 @@ if (( USING_EXISTING_CLUSTER )); then fi create_everything +publish_test_images # Handle failures ourselves, so we can dump useful info. set +o errexit @@ -292,9 +300,9 @@ abort_if_failed # Run the tests -run_e2e_tests conformance pizzaplanet conformance +run_e2e_tests conformance pizzaplanet result=$? -run_e2e_tests e2e noodleburg e2e +run_e2e_tests e2e noodleburg [[ $? -ne 0 || ${result} -ne 0 ]] && exit 1 # kubetest teardown might fail and thus incorrectly report failure of the diff --git a/test/e2e/helloworld_shell_test.go b/test/e2e/helloworld_shell_test.go index 1e9bc6176883..4384b6efd916 100644 --- a/test/e2e/helloworld_shell_test.go +++ b/test/e2e/helloworld_shell_test.go @@ -31,7 +31,7 @@ import ( ) const ( - appYaml = "test_images/helloworld/helloworld.yaml" + appYaml = "../test_images/helloworld/helloworld.yaml" yamlImagePlaceholder = "github.com/knative/serving/test_images/helloworld" ingressTimeout = 5 * time.Minute servingTimeout = 2 * time.Minute diff --git a/test/e2e/test_images/README.md b/test/e2e/test_images/README.md deleted file mode 100644 index e6df9295fa79..000000000000 --- a/test/e2e/test_images/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Test images node - -The subdirectories contain the test images used in the conformance tests. - -For details about building and adding new images, see the [section about test -images](/test/README.md#test-images). - diff --git a/test/e2e/test_images/autoscale/Dockerfile b/test/e2e/test_images/autoscale/Dockerfile deleted file mode 100644 index a0c5121ee5ff..000000000000 --- a/test/e2e/test_images/autoscale/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM golang:latest -RUN mkdir /app -ADD . /app/ -WORKDIR /app -RUN go build -o autoscale . -CMD ["/app/autoscale"] diff --git a/test/e2e/test_images/helloworld/Dockerfile b/test/e2e/test_images/helloworld/Dockerfile deleted file mode 100644 index 5a61955739d2..000000000000 --- a/test/e2e/test_images/helloworld/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM golang:latest -RUN mkdir /app -ADD . /app/ -WORKDIR /app -RUN go build -o helloworld . -CMD ["/app/helloworld"] diff --git a/test/e2e_flags.go b/test/e2e_flags.go index e24016e130a8..c7bf55ad8253 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -45,7 +45,7 @@ func initializeFlags() *EnvironmentFlags { flag.StringVar(&f.Cluster, "cluster", defaultCluster, "Provide the cluster to test against. Defaults to $K8S_CLUSTER_OVERRIDE, then current cluster in kubeconfig if $K8S_CLUSTER_OVERRIDE is unset.") - defaultRepo := os.Getenv("DOCKER_REPO_OVERRIDE") + defaultRepo := path.Join(os.Getenv("DOCKER_REPO_OVERRIDE"), "github.com/knative/serving/test/test_images") flag.StringVar(&f.DockerRepo, "dockerrepo", defaultRepo, "Provide the uri of the docker repo you have uploaded the test image to using `uploadtestimage.sh`. Defaults to $DOCKER_REPO_OVERRIDE") diff --git a/test/conformance/test_images/README.md b/test/test_images/README.md similarity index 91% rename from test/conformance/test_images/README.md rename to test/test_images/README.md index e6df9295fa79..81cb2a3a55a5 100644 --- a/test/conformance/test_images/README.md +++ b/test/test_images/README.md @@ -1,6 +1,6 @@ # Test images node -The subdirectories contain the test images used in the conformance tests. +The subdirectories contain the test images used in the conformance and e2e tests. For details about building and adding new images, see the [section about test images](/test/README.md#test-images). diff --git a/test/e2e/test_images/autoscale/README.md b/test/test_images/autoscale/README.md similarity index 100% rename from test/e2e/test_images/autoscale/README.md rename to test/test_images/autoscale/README.md diff --git a/test/e2e/test_images/autoscale/autoscale.go b/test/test_images/autoscale/autoscale.go similarity index 100% rename from test/e2e/test_images/autoscale/autoscale.go rename to test/test_images/autoscale/autoscale.go diff --git a/test/e2e/test_images/helloworld/README.md b/test/test_images/helloworld/README.md similarity index 100% rename from test/e2e/test_images/helloworld/README.md rename to test/test_images/helloworld/README.md diff --git a/test/e2e/test_images/helloworld/helloworld.go b/test/test_images/helloworld/helloworld.go similarity index 100% rename from test/e2e/test_images/helloworld/helloworld.go rename to test/test_images/helloworld/helloworld.go diff --git a/test/e2e/test_images/helloworld/helloworld.yaml b/test/test_images/helloworld/helloworld.yaml similarity index 100% rename from test/e2e/test_images/helloworld/helloworld.yaml rename to test/test_images/helloworld/helloworld.yaml diff --git a/test/conformance/test_images/pizzaplanetv1/README.md b/test/test_images/pizzaplanetv1/README.md similarity index 100% rename from test/conformance/test_images/pizzaplanetv1/README.md rename to test/test_images/pizzaplanetv1/README.md diff --git a/test/conformance/test_images/pizzaplanetv1/main.go b/test/test_images/pizzaplanetv1/main.go similarity index 100% rename from test/conformance/test_images/pizzaplanetv1/main.go rename to test/test_images/pizzaplanetv1/main.go diff --git a/test/conformance/test_images/pizzaplanetv2/README.md b/test/test_images/pizzaplanetv2/README.md similarity index 100% rename from test/conformance/test_images/pizzaplanetv2/README.md rename to test/test_images/pizzaplanetv2/README.md diff --git a/test/conformance/test_images/pizzaplanetv2/main.go b/test/test_images/pizzaplanetv2/main.go similarity index 100% rename from test/conformance/test_images/pizzaplanetv2/main.go rename to test/test_images/pizzaplanetv2/main.go diff --git a/test/upload-test-images.sh b/test/upload-test-images.sh index d4478185e6e3..9ba07410ca09 100755 --- a/test/upload-test-images.sh +++ b/test/upload-test-images.sh @@ -16,15 +16,11 @@ set -o errexit -: ${1:?"Pass the directory with the test images as argument"} : ${DOCKER_REPO_OVERRIDE:?"You must set 'DOCKER_REPO_OVERRIDE', see DEVELOPMENT.md"} -DOCKER_FILES="$(ls -1 $1/*/Dockerfile)" -: ${DOCKER_FILES:?"No subdirectories with Dockerfile files found in $1"} +export KO_DOCKER_REPO=${DOCKER_REPO_OVERRIDE} +IMAGE_DIRS="$(find $(dirname $0)/test_images -mindepth 1 -maxdepth 1 -type d)" -for docker_file in ${DOCKER_FILES}; do - image_dir="$(dirname ${docker_file})" - versioned_name="${DOCKER_REPO_OVERRIDE}/$(basename ${image_dir})" - docker build "${image_dir}" -f "${docker_file}" -t "${versioned_name}" - docker push "${versioned_name}" +for image_dir in ${IMAGE_DIRS}; do + ko publish -P "github.com/knative/serving/test/test_images/$(basename ${image_dir})" done