diff --git a/go.mod b/go.mod index 964caeab66..4086523b9c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/knative/build v0.6.0 // indirect github.com/knative/pkg v0.0.0-20190518173526-34792a92cec2 github.com/knative/serving v0.6.0 - github.com/knative/test-infra v0.0.0-20190531180034-a3c073a2fea1 + github.com/knative/test-infra v0.0.0-20190624052103-517330119155 github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/modern-go/reflect2 v1.0.1 // indirect diff --git a/go.sum b/go.sum index 6b6b4ab24d..37933a8a76 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/knative/test-infra v0.0.0-20190529123930-7d0c44fb03a9 h1:2kupVzyk+zet github.com/knative/test-infra v0.0.0-20190529123930-7d0c44fb03a9/go.mod h1:l77IWBscEV5T4sYb64/9iwRCVY4UXEIqMcAppsblHW4= github.com/knative/test-infra v0.0.0-20190531180034-a3c073a2fea1 h1:Y2QunZIzGuyvBNfWNpwK9/AAgu2P+Aa+k/3ykATGw30= github.com/knative/test-infra v0.0.0-20190531180034-a3c073a2fea1/go.mod h1:l77IWBscEV5T4sYb64/9iwRCVY4UXEIqMcAppsblHW4= +github.com/knative/test-infra v0.0.0-20190624052103-517330119155 h1:ceTQvUNU19Vc13TlSNo6u0F0pHak9wcGJQ+gv0X4KlE= +github.com/knative/test-infra v0.0.0-20190624052103-517330119155/go.mod h1:l77IWBscEV5T4sYb64/9iwRCVY4UXEIqMcAppsblHW4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= diff --git a/test/e2e/e2e_flags.go b/test/e2e/e2e_flags.go new file mode 100644 index 0000000000..a21adc45c1 --- /dev/null +++ b/test/e2e/e2e_flags.go @@ -0,0 +1,31 @@ +/* +Copyright 2019 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. +*/ + +package e2e + +import ( + "flag" +) + +var _ = initializeFlags() + +func initializeFlags() bool { + // emitmetrics is a required flag for running periodic test jobs, add it here as a no-op to avoid the error + emitMetrics := flag.Bool("emitmetrics", false, + "Set this flag to true if you would like tests to emit metrics, e.g. latency of resources being realized in the system.") + flag.Parse() + return *emitMetrics +} diff --git a/vendor/github.com/knative/test-infra/scripts/README.md b/vendor/github.com/knative/test-infra/scripts/README.md index cb0aa4e6b3..6a8d6f48be 100644 --- a/vendor/github.com/knative/test-infra/scripts/README.md +++ b/vendor/github.com/knative/test-infra/scripts/README.md @@ -1,7 +1,7 @@ # Helper scripts -This directory contains helper scripts used by Prow test jobs, as well and -local development scripts. +This directory contains helper scripts used by Prow test jobs, as well and local +development scripts. ## Using the `presubmit-tests.sh` helper script @@ -28,45 +28,47 @@ This is a helper script to run the presubmit tests. To use it: in the `/test` directory. 1. [optional] Customize the default build test runner, if you're using it. Set - the following environment variables if the default values don't fit your needs: + the following environment variables if the default values don't fit your + needs: - - `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0 (false). + - `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0 + (false). - `DISABLE_MD_LINK_CHECK`: Disable checking links in markdown files, defaults to 0 (false). - - `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test fails, - defaults to 0 (false). + - `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test + fails, defaults to 0 (false). 1. [optional] Define the functions `pre_build_tests()` and/or `post_build_tests()`. These functions will be called before or after the - build tests (either your custom one or the default action) and will cause - the test to fail if they don't return success. + build tests (either your custom one or the default action) and will cause the + test to fail if they don't return success. 1. [optional] Define the function `unit_tests()`. If you don't define this - function, the default action for running the unit tests is to run all go tests - in the repo. + function, the default action for running the unit tests is to run all go + tests in the repo. 1. [optional] Define the functions `pre_unit_tests()` and/or - `post_unit_tests()`. These functions will be called before or after the - unit tests (either your custom one or the default action) and will cause - the test to fail if they don't return success. + `post_unit_tests()`. These functions will be called before or after the unit + tests (either your custom one or the default action) and will cause the test + to fail if they don't return success. 1. [optional] Define the function `integration_tests()`. If you don't define this function, the default action for running the integration tests is to run all run all `./test/e2e-*tests.sh` scripts, in sequence. 1. [optional] Define the functions `pre_integration_tests()` and/or - `post_integration_tests()`. These functions will be called before or after the - integration tests (either your custom one or the default action) and will cause - the test to fail if they don't return success. + `post_integration_tests()`. These functions will be called before or after + the integration tests (either your custom one or the default action) and will + cause the test to fail if they don't return success. 1. Call the `main()` function passing `$@` (without quotes). -Running the script without parameters, or with the `--all-tests` flag causes -all tests to be executed, in the right order (i.e., build, then unit, then +Running the script without parameters, or with the `--all-tests` flag causes all +tests to be executed, in the right order (i.e., build, then unit, then integration tests). -Use the flags `--build-tests`, `--unit-tests` and `--integration-tests` to run -a specific set of tests. The flag `--emit-metrics` is used to emit metrics when +Use the flags `--build-tests`, `--unit-tests` and `--integration-tests` to run a +specific set of tests. The flag `--emit-metrics` is used to emit metrics when running the tests, and is automatically handled by the default action for integration tests (see above). @@ -104,63 +106,64 @@ main $@ This is a helper script for Knative E2E test scripts. To use it: -1. [optional] Customize the test cluster. Set the following environment variables - if the default values don't fit your needs: +1. [optional] Customize the test cluster. Set the following environment + variables if the default values don't fit your needs: - `E2E_CLUSTER_REGION`: Cluster region, defaults to `us-central1`. - `E2E_CLUSTER_BACKUP_REGIONS`: Space-separated list of regions to retry test cluster creation in case of stockout. Defaults to `us-west1 us-east1`. - - `E2E_CLUSTER_ZONE`: Cluster zone (e.g., `a`), defaults to none (i.e. use a regional - cluster). - - `E2E_CLUSTER_BACKUP_ZONES`: Space-separated list of zones to retry test cluster - creation in case of stockout. If defined, `E2E_CLUSTER_BACKUP_REGIONS` will be - ignored thus it defaults to none. - - `E2E_CLUSTER_MACHINE`: Cluster node machine type, defaults to `n1-standard-4}`. - - `E2E_MIN_CLUSTER_NODES`: Minimum number of nodes in the cluster when autoscaling, - defaults to 1. - - `E2E_MAX_CLUSTER_NODES`: Maximum number of nodes in the cluster when autoscaling, - defaults to 3. + - `E2E_CLUSTER_ZONE`: Cluster zone (e.g., `a`), defaults to none (i.e. use a + regional cluster). + - `E2E_CLUSTER_BACKUP_ZONES`: Space-separated list of zones to retry test + cluster creation in case of stockout. If defined, + `E2E_CLUSTER_BACKUP_REGIONS` will be ignored thus it defaults to none. + - `E2E_CLUSTER_MACHINE`: Cluster node machine type, defaults to + `n1-standard-4}`. + - `E2E_MIN_CLUSTER_NODES`: Minimum number of nodes in the cluster when + autoscaling, defaults to 1. + - `E2E_MAX_CLUSTER_NODES`: Maximum number of nodes in the cluster when + autoscaling, defaults to 3. 1. Source the script. 1. [optional] Write the `knative_setup()` function, which will set up your - system under test (e.g., Knative Serving). This function won't be called if you - use the `--skip-knative-setup` flag. + system under test (e.g., Knative Serving). This function won't be called if + you use the `--skip-knative-setup` flag. 1. [optional] Write the `knative_teardown()` function, which will tear down your - system under test (e.g., Knative Serving). This function won't be called if you - use the `--skip-knative-setup` flag. + system under test (e.g., Knative Serving). This function won't be called if + you use the `--skip-knative-setup` flag. 1. [optional] Write the `test_setup()` function, which will set up the test resources. -1. [optional] Write the `test_teardown()` function, which will tear down the test - resources. +1. [optional] Write the `test_teardown()` function, which will tear down the + test resources. -1. [optional] Write the `cluster_setup()` function, which will set up any resources - before the test cluster is created. +1. [optional] Write the `cluster_setup()` function, which will set up any + resources before the test cluster is created. 1. [optional] Write the `cluster_teardown()` function, which will tear down any resources after the test cluster is destroyed. -1. [optional] Write the `dump_extra_cluster_state()` function. It will be - called when a test fails, and can dump extra information about the current state - of the cluster (typically using `kubectl`). +1. [optional] Write the `dump_extra_cluster_state()` function. It will be called + when a test fails, and can dump extra information about the current state of + the cluster (typically using `kubectl`). 1. [optional] Write the `parse_flags()` function. It will be called whenever an - unrecognized flag is passed to the script, allowing you to define your own flags. - The function must return 0 if the flag is unrecognized, or the number of items - to skip in the command line if the flag was parsed successfully. For example, - return 1 for a simple flag, and 2 for a flag with a parameter. + unrecognized flag is passed to the script, allowing you to define your own + flags. The function must return 0 if the flag is unrecognized, or the number + of items to skip in the command line if the flag was parsed successfully. For + example, return 1 for a simple flag, and 2 for a flag with a parameter. 1. Call the `initialize()` function passing `$@` (without quotes). 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` 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: + `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. @@ -175,18 +178,19 @@ This is a helper script for Knative E2E test scripts. To use it: will immediately start the tests against the cluster currently configured for `kubectl`. -1. By default Istio is installed on the cluster via Addon, use `--skip-istio-addon` if - you choose not to have it preinstalled. +1. By default Istio is installed on the cluster via Addon, use + `--skip-istio-addon` if you choose not to have it preinstalled. -1. You can force running the tests against a specific GKE cluster version by using - the `--cluster-version` flag and passing a full version as the flag value. +1. You can force running the tests against a specific GKE cluster version by + using the `--cluster-version` flag and passing a full version as the flag + value. ### Sample end-to-end test script This script will test that the latest Knative Serving nightly release works. It -defines a special flag (`--no-knative-wait`) that causes the script not to -wait for Knative Serving to be up before running the tests. It also requires that -the test cluster is created in a specific region, `us-west2`. +defines a special flag (`--no-knative-wait`) that causes the script not to wait +for Knative Serving to be up before running the tests. It also requires that the +test cluster is created in a specific region, `us-west2`. ```bash @@ -226,40 +230,46 @@ This is a helper script for Knative release scripts. To use it: 1. Source the script. -1. [optional] By default, the release script will run `./test/presubmit-tests.sh` - as the release validation tests. If you need to run something else, set the - environment variable `VALIDATION_TESTS` to the executable to run. +1. [optional] By default, the release script will run + `./test/presubmit-tests.sh` as the release validation tests. If you need to + run something else, set the environment variable `VALIDATION_TESTS` to the + executable to run. 1. Write logic for building the release in a function named `build_release()`. - Set the environment variable `ARTIFACTS_TO_PUBLISH` to the list of files created, - space separated. Use the following boolean (0 is false, 1 is true) and string - environment variables for the logic: - - - `RELEASE_VERSION`: contains the release version if `--version` was passed. This - also overrides the value of the `TAG` variable as `v`. - - `RELEASE_BRANCH`: contains the release branch if `--branch` was passed. Otherwise - it's empty and `master` HEAD will be considered the release branch. - - `RELEASE_NOTES`: contains the filename with the release notes if `--release-notes` - was passed. The release notes is a simple markdown file. - - `RELEASE_GCS_BUCKET`: contains the GCS bucket name to store the manifests if - `--release-gcs` was passed, otherwise the default value `knative-nightly/` - will be used. It is empty if `--publish` was not passed. - - `BUILD_COMMIT_HASH`: the commit short hash for the current repo. If the current - git tree is dirty, it will have `-dirty` appended to it. + Set the environment variable `ARTIFACTS_TO_PUBLISH` to the list of files + created, space separated. Use the following boolean (0 is false, 1 is true) + and string environment variables for the logic: + + - `RELEASE_VERSION`: contains the release version if `--version` was passed. + This also overrides the value of the `TAG` variable as `v`. + - `RELEASE_BRANCH`: contains the release branch if `--branch` was passed. + Otherwise it's empty and `master` HEAD will be considered the release + branch. + - `RELEASE_NOTES`: contains the filename with the release notes if + `--release-notes` was passed. The release notes is a simple markdown file. + - `RELEASE_GCS_BUCKET`: contains the GCS bucket name to store the manifests + if `--release-gcs` was passed, otherwise the default value + `knative-nightly/` will be used. It is empty if `--publish` was not + passed. + - `BUILD_COMMIT_HASH`: the commit short hash for the current repo. If the + current git tree is dirty, it will have `-dirty` appended to it. - `BUILD_YYYYMMDD`: current UTC date in `YYYYMMDD` format. - - `BUILD_TIMESTAMP`: human-readable UTC timestamp in `YYYY-MM-DD HH:MM:SS` format. + - `BUILD_TIMESTAMP`: human-readable UTC timestamp in `YYYY-MM-DD HH:MM:SS` + format. - `BUILD_TAG`: a tag in the form `v$BUILD_YYYYMMDD-$BUILD_COMMIT_HASH`. - - `KO_DOCKER_REPO`: contains the GCR to store the images if `--release-gcr` was - passed, otherwise the default value `gcr.io/knative-nightly` will be used. It - is set to `ko.local` if `--publish` was not passed. - - `SKIP_TESTS`: true if `--skip-tests` was passed. This is handled automatically. - - `TAG_RELEASE`: true if `--tag-release` was passed. In this case, the environment - variable `TAG` will contain the release tag in the form `v$BUILD_TAG`. - - `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the environment - variable `KO_FLAGS` will be updated with the `-L` option and `TAG` will contain - the release tag in the form `v$RELEASE_VERSION`. - - `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and `--publish-release` - were passed. + - `KO_DOCKER_REPO`: contains the GCR to store the images if `--release-gcr` + was passed, otherwise the default value `gcr.io/knative-nightly` will be + used. It is set to `ko.local` if `--publish` was not passed. + - `SKIP_TESTS`: true if `--skip-tests` was passed. This is handled + automatically. + - `TAG_RELEASE`: true if `--tag-release` was passed. In this case, the + environment variable `TAG` will contain the release tag in the form + `v$BUILD_TAG`. + - `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the + environment variable `KO_FLAGS` will be updated with the `-L` option and + `TAG` will contain the release tag in the form `v$RELEASE_VERSION`. + - `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and + `--publish-release` were passed. All boolean environment variables default to false for safety. diff --git a/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh index b6faf49a7c..ea01eeae69 100644 --- a/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh +++ b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh @@ -127,29 +127,41 @@ function save_metadata() { EOF } -# Delete target pools and health checks that might have leaked. -# See https://github.com/knative/serving/issues/959 for details. -# TODO(adrcunha): Remove once the leak issue is resolved. -function delete_leaked_network_resources() { - # On boskos, don't bother with leaks as the janitor will delete everything in the project. - (( IS_BOSKOS )) && return - # Ensure we're using the GCP project used by kubetest - local gcloud_project="$(gcloud config get-value project)" - local http_health_checks="$(gcloud compute target-pools list \ - --project=${gcloud_project} --format='value(healthChecks)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ - grep httpHealthChecks | tr '\n' ' ')" - local target_pools="$(gcloud compute target-pools list \ - --project=${gcloud_project} --format='value(name)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ - tr '\n' ' ')" - if [[ -n "${target_pools}" ]]; then - echo "Found leaked target pools, deleting" - gcloud compute forwarding-rules delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools} - gcloud compute target-pools delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools} +# Set E2E_CLUSTER_VERSION to a specific GKE version. +# Parameters: $1 - target GKE version (X.Y, X.Y.Z, X.Y.Z-gke.W, default or gke-latest). +# $2 - region[-zone] where the clusteer will be created. +function resolve_k8s_version() { + local target_version="$1" + if [[ "${target_version}" == "default" ]]; then + local version="$(gcloud container get-server-config \ + --format='value(defaultClusterVersion)' \ + --zone=$2)" + [[ -z "${version}" ]] && return 1 + E2E_CLUSTER_VERSION="${version}" + echo "Using default version, ${E2E_CLUSTER_VERSION}" + return 0 fi - if [[ -n "${http_health_checks}" ]]; then - echo "Found leaked health checks, deleting" - gcloud compute http-health-checks delete -q --project=${gcloud_project} ${http_health_checks} + # Fetch valid versions + local versions="$(gcloud container get-server-config \ + --format='value(validMasterVersions)' \ + --zone=$2)" + [[ -z "${versions}" ]] && return 1 + local gke_versions=($(echo -n "${versions//;/ }")) + echo "Available GKE versions in $2 are [${versions//;/, }]" + if [[ "${target_version}" == "gke-latest" ]]; then + # Get first (latest) version, excluding the "-gke.#" suffix + E2E_CLUSTER_VERSION="${gke_versions[0]}" + echo "Using latest version, ${E2E_CLUSTER_VERSION}" + else + local latest="$(echo "${gke_versions[@]}" | tr ' ' '\n' | grep -E ^${target_version} | cut -f1 -d- | sort | tail -1)" + if [[ -z "${latest}" ]]; then + echo "ERROR: version ${target_version} is not available" + return 1 + fi + E2E_CLUSTER_VERSION="${latest}" + echo "Using ${E2E_CLUSTER_VERSION} for supplied version ${target_version}" fi + return 0 } # Create a test cluster with kubetest and call the current script again. @@ -172,9 +184,11 @@ function create_test_cluster() { --deployment=gke --cluster="${E2E_CLUSTER_NAME}" --gcp-network="${E2E_NETWORK_NAME}" + --gcp-node-image="${SERVING_GKE_IMAGE}" --gke-environment="${E2E_GKE_ENVIRONMENT}" --gke-command-group="${E2E_GKE_COMMAND_GROUP}" --test=false + --up ) if (( ! IS_BOSKOS )); then CLUSTER_CREATION_ARGS+=(--gcp-project=${GCP_PROJECT}) @@ -202,19 +216,28 @@ function create_test_cluster() { local extra_flags=() # If using boskos, save time and let it tear down the cluster (( ! IS_BOSKOS )) && extra_flags+=(--down) + + # Set a minimal kubernetes environment that satisfies kubetest + # TODO(adrcunha): Remove once https://github.com/kubernetes/test-infra/issues/13029 is fixed. + local kubedir="$(mktemp -d --tmpdir kubernetes.XXXXXXXXXX)" + local test_wrapper="${kubedir}/e2e-test.sh" + mkdir ${kubedir}/cluster + ln -s "$(which kubectl)" ${kubedir}/cluster/kubectl.sh + echo "#!/bin/bash" > ${test_wrapper} + echo "cd $(pwd) && set -x" >> ${test_wrapper} + echo "${E2E_SCRIPT} ${test_cmd_args}" >> ${test_wrapper} + chmod +x ${test_wrapper} + cd ${kubedir} + + # Create cluster and run the tests create_test_cluster_with_retries "${CLUSTER_CREATION_ARGS[@]}" \ - --up \ - --extract "${E2E_CLUSTER_VERSION}" \ - --gcp-node-image "${SERVING_GKE_IMAGE}" \ - --test-cmd "${E2E_SCRIPT}" \ - --test-cmd-args "${test_cmd_args}" \ + --test-cmd "${test_wrapper}" \ ${extra_flags[@]} \ ${EXTRA_KUBETEST_FLAGS[@]} echo "Test subprocess exited with code $?" # Ignore any errors below, this is a best-effort cleanup and shouldn't affect the test result. set +o errexit function_exists cluster_teardown && cluster_teardown - delete_leaked_network_resources local result=$(get_test_return_code) echo "Artifacts were written to ${ARTIFACTS}" echo "Test result code is ${result}" @@ -240,21 +263,23 @@ function create_test_cluster_with_retries() { echo "No backup region/zone set, cluster creation will fail in case of stockout" fi + local e2e_cluster_target_version="${E2E_CLUSTER_VERSION}" for e2e_cluster_region in "${e2e_cluster_regions[@]}"; do for e2e_cluster_zone in "${e2e_cluster_zones[@]}"; do E2E_CLUSTER_REGION=${e2e_cluster_region} E2E_CLUSTER_ZONE=${e2e_cluster_zone} [[ "${E2E_CLUSTER_ZONE}" == "${zone_not_provided}" ]] && E2E_CLUSTER_ZONE="" + local cluster_creation_zone="${E2E_CLUSTER_REGION}" + [[ -n "${E2E_CLUSTER_ZONE}" ]] && cluster_creation_zone="${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}" + resolve_k8s_version ${e2e_cluster_target_version} ${cluster_creation_zone} || return 1 - local geoflag="--gcp-region=${E2E_CLUSTER_REGION}" - [[ -n "${E2E_CLUSTER_ZONE}" ]] && geoflag="--gcp-zone=${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}" - - header "Creating test cluster in $E2E_CLUSTER_REGION $E2E_CLUSTER_ZONE" + header "Creating test cluster ${E2E_CLUSTER_VERSION} in ${cluster_creation_zone}" # Don't fail test for kubetest, as it might incorrectly report test failure # if teardown fails (for details, see success() below) set +o errexit - { run_go_tool k8s.io/test-infra/kubetest \ - kubetest "$@" ${geoflag}; } 2>&1 | tee ${cluster_creation_log} + export CLUSTER_API_VERSION=${E2E_CLUSTER_VERSION} + run_go_tool k8s.io/test-infra/kubetest \ + kubetest "$@" --gcp-region=${cluster_creation_zone} 2>&1 | tee ${cluster_creation_log} # Exit if test succeeded [[ "$(get_test_return_code)" == "0" ]] && return 0 @@ -262,7 +287,8 @@ function create_test_cluster_with_retries() { # - stockout (https://github.com/knative/test-infra/issues/592) # - latest GKE not available in this region/zone yet (https://github.com/knative/test-infra/issues/694) [[ -z "$(grep -Fo 'does not have enough resources available to fulfill' ${cluster_creation_log})" \ - && -z "$(grep -Fo 'ResponseError: code=400, message=No valid versions with the prefix' ${cluster_creation_log})" ]] \ + && -z "$(grep -Fo 'ResponseError: code=400, message=No valid versions with the prefix' ${cluster_creation_log})" \ + && -z "$(grep -Po 'ResponseError: code=400, message=Master version "[0-9a-z\-\.]+" is unsupported' ${cluster_creation_log})" ]] \ && return 1 done done @@ -297,7 +323,8 @@ 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/${E2E_PROJECT_ID}/${E2E_BASE_NAME}-e2e-img + # Incorporate an element of randomness to ensure that each run properly publishes images. + export KO_DOCKER_REPO=gcr.io/${E2E_PROJECT_ID}/${E2E_BASE_NAME}-e2e-img/${RANDOM} fi # Safety checks @@ -421,7 +448,7 @@ function initialize() { echo "\$PROJECT_ID is set to '${PROJECT_ID}', using it to run the tests" GCP_PROJECT="${PROJECT_ID}" fi - if (( ! IS_PROW )) && [[ -z "${GCP_PROJECT}" ]]; then + if (( ! IS_PROW )) && (( ! RUN_TESTS )) && [[ -z "${GCP_PROJECT}" ]]; then abort "set \$PROJECT_ID or use --gcp-project to select the GCP project where the tests are run" fi diff --git a/vendor/github.com/knative/test-infra/scripts/library.sh b/vendor/github.com/knative/test-infra/scripts/library.sh index d3e98d5b09..f5f54f87ab 100644 --- a/vendor/github.com/knative/test-infra/scripts/library.sh +++ b/vendor/github.com/knative/test-infra/scripts/library.sh @@ -36,7 +36,8 @@ fi # Useful environment variables [[ -n "${PROW_JOB_ID:-}" ]] && IS_PROW=1 || IS_PROW=0 readonly IS_PROW -readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" +[[ -z "${REPO_ROOT_DIR:-}" ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" +readonly REPO_ROOT_DIR readonly REPO_NAME="$(basename ${REPO_ROOT_DIR})" # Useful flags about the current OS @@ -75,6 +76,9 @@ function make_banner() { local msg="$1$1$1$1 $2 $1$1$1$1" local border="${msg//[-0-9A-Za-z _.,\/()\']/$1}" echo -e "${border}\n${msg}\n${border}" + # TODO(adrcunha): Remove once logs have timestamps on Prow + # For details, see https://github.com/kubernetes/test-infra/issues/10100 + echo -e "$1$1$1$1 $(date)\n${border}" } # Simple header for logging purposes. @@ -327,17 +331,29 @@ function report_go_test() { return ${failed} } -# Install the latest stable Knative/serving in the current cluster. -function start_latest_knative_serving() { +# Install Knative Serving in the current cluster. +# Parameters: $1 - Knative Serving manifest. +function start_knative_serving() { header "Starting Knative Serving" subheader "Installing Knative Serving" - echo "Installing Serving CRDs from ${KNATIVE_SERVING_RELEASE}" - kubectl apply --selector knative.dev/crd-install=true -f ${KNATIVE_SERVING_RELEASE} - echo "Installing the rest of serving components from ${KNATIVE_SERVING_RELEASE}" - kubectl apply -f ${KNATIVE_SERVING_RELEASE} + echo "Installing Serving CRDs from $1" + kubectl apply --selector knative.dev/crd-install=true -f "$1" + echo "Installing the rest of serving components from $1" + kubectl apply -f "$1" wait_until_pods_running knative-serving || return 1 } +# Install the stable release Knative/serving in the current cluster. +# Parameters: $1 - Knative Serving version number, e.g. 0.6.0. +function start_release_knative_serving() { + start_knative_serving "https://storage.googleapis.com/knative-releases/serving/previous/v$1/serving.yaml" +} + +# Install the latest stable Knative Serving in the current cluster. +function start_latest_knative_serving() { + start_knative_serving "${KNATIVE_SERVING_RELEASE}" +} + # Run a go tool, installing it first if necessary. # Parameters: $1 - tool package/dir for go get/install. # $2 - tool to run. @@ -360,16 +376,17 @@ function update_licenses() { cd ${REPO_ROOT_DIR} || return 1 local dst=$1 shift - run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector $@ > ./${dst} + run_go_tool github.com/knative/test-infra/tools/dep-collector dep-collector $@ > ./${dst} } # Run dep-collector to check for forbidden liceses. # Parameters: $1...$n - directories and files to inspect. function check_licenses() { # Fetch the google/licenseclassifier for its license db + rm -fr ${GOPATH}/src/github.com/google/licenseclassifier go get -u github.com/google/licenseclassifier # Check that we don't have any forbidden licenses in our images. - run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector -check $@ + run_go_tool github.com/knative/test-infra/tools/dep-collector dep-collector -check $@ } # Run the given linter on the given files, checking it exists first. diff --git a/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh b/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh index 8b077f6ddc..07a2e13551 100644 --- a/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh +++ b/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh @@ -85,6 +85,24 @@ function results_banner() { header "$1 tests ${result}" } +# Create a JUnit XML for a failure. +# Parameters: $1 - check name as an identifier (e.g., PresubmitBuildTest) +# $2 - failure message (can contain newlines) +function create_junit_xml() { + local xml="$(mktemp ${ARTIFACTS}/junit_XXXXXXXX.xml)" + # Transform newlines into HTML code. + local msg="$(echo -n "$2" | sed 's/$/\ /g' | tr -d '\n')" + cat << EOF > "${xml}" + + + + ${msg} + + + +EOF +} + # Run build tests. If there's no `build_tests` function, run the default # build test runner. function run_build_tests() { @@ -148,7 +166,15 @@ function default_build_test_runner() { [[ -z "${go_pkg_dirs}" ]] && return ${failed} # Ensure all the code builds subheader "Checking that go code builds" - go build -v ./... || failed=1 + local report=$(mktemp) + go build -v ./... 2>&1 | tee ${report} + local build_failed=( ${PIPESTATUS[@]} ) + if [[ ${build_failed[0]} -ne 0 ]]; then + failed=1 + # Consider an error message everything that's not a package name. + local errors="$(grep -v '^github.com/' "${report}" | sort | uniq)" + create_junit_xml PresubmitBuildTest "${errors}" + fi # Get all build tags in go code (ignore /vendor) local tags="$(grep -r '// +build' . \ | grep -v '^./vendor/' | cut -f3 -d' ' | sort | uniq | tr '\n' ' ')" @@ -273,7 +299,7 @@ function main() { echo ">> git version" git version echo ">> bazel version" - bazel version 2> /dev/null + [[ -f /bazel_version ]] && cat /bazel_version || echo "unknown" if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then echo ">> docker version" docker version diff --git a/vendor/modules.txt b/vendor/modules.txt index 0b6613f8fa..36e4ca057e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -84,7 +84,7 @@ github.com/knative/serving/pkg/apis/networking github.com/knative/serving/pkg/apis/networking/v1alpha1 github.com/knative/serving/pkg/apis/config github.com/knative/serving/pkg/apis/autoscaling/v1alpha1 -# github.com/knative/test-infra v0.0.0-20190531180034-a3c073a2fea1 +# github.com/knative/test-infra v0.0.0-20190624052103-517330119155 github.com/knative/test-infra/scripts # github.com/magiconair/properties v1.8.0 github.com/magiconair/properties