From 3d5a3da1005a1525fa3ce35920a5ed73ad1327dc Mon Sep 17 00:00:00 2001 From: Nikhil Barthwal Date: Thu, 4 Apr 2019 17:24:23 -0700 Subject: [PATCH] Update dep for test-infra --- Gopkg.lock | 4 +- .../knative/test-infra/scripts/README.md | 6 ++ .../knative/test-infra/scripts/e2e-tests.sh | 56 +++++++++++-------- .../knative/test-infra/scripts/library.sh | 37 ++++++++---- .../knative/test-infra/scripts/release.sh | 12 +++- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 943183d249a..5ff273f9b1e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -116,14 +116,14 @@ [[projects]] branch = "master" - digest = "1:572fae71c667a449da06887af349157fdc85d933812df9b7209c22d8d1aeb618" + digest = "1:921c8888ac7bf7240bc5473d029201b3eb19f9592c7647c4c29f96b6c901b1bb" name = "github.com/knative/test-infra" packages = [ "scripts", "tools/dep-collector", ] pruneopts = "UT" - revision = "e52aec9de72a3ac41e2cde49ff501dcb59a30055" + revision = "582b6fbee8ae00260baf916b0f9db2aa5f3483d9" [[projects]] digest = "1:5985ef4caf91ece5d54817c11ea25f182697534f8ae6521eadcd628c142ac4b6" diff --git a/vendor/github.com/knative/test-infra/scripts/README.md b/vendor/github.com/knative/test-infra/scripts/README.md index 1d14a55f710..07398fb7fed 100644 --- a/vendor/github.com/knative/test-infra/scripts/README.md +++ b/vendor/github.com/knative/test-infra/scripts/README.md @@ -132,6 +132,12 @@ This is a helper script for Knative E2E test scripts. To use it: 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_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`). 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 c6879a0da80..c2328e7b8d5 100755 --- a/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh +++ b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh @@ -120,12 +120,40 @@ 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() { + (( 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} + 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} + fi +} + # Create a test cluster with kubetest and call the current script again. function create_test_cluster() { # Fail fast during setup. set -o errexit set -o pipefail + if function_exists cluster_setup; then + cluster_setup || fail_test "cluster setup failed" + fi + header "Creating test cluster" echo "Cluster will have a minimum of ${E2E_MIN_CLUSTER_NODES} and a maximum of ${E2E_MAX_CLUSTER_NODES} nodes." @@ -167,45 +195,29 @@ function create_test_cluster() { (( SKIP_KNATIVE_SETUP )) && test_cmd_args+=" --skip-knative-setup" [[ -n "${GCP_PROJECT}" ]] && test_cmd_args+=" --gcp-project ${GCP_PROJECT}" [[ -n "${E2E_SCRIPT_CUSTOM_FLAGS[@]}" ]] && test_cmd_args+=" ${E2E_SCRIPT_CUSTOM_FLAGS[@]}" + local extra_flags=() + # If using boskos, save time and let it tear down the cluster + (( ! IS_BOSKOS )) && extra_flags+=(--down) # 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 "${CLUSTER_CREATION_ARGS[@]}" \ --up \ - --down \ --extract "${E2E_CLUSTER_VERSION}" \ --gcp-node-image "${SERVING_GKE_IMAGE}" \ --test-cmd "${E2E_SCRIPT}" \ --test-cmd-args "${test_cmd_args}" \ + ${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 - # Ensure we're using the GCP project used by kubetest - gcloud_project="$(gcloud config get-value project)" - # 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. - 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} - 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} - fi + function_exists cluster_teardown && cluster_teardown + delete_leaked_network_resources local result="$(cat ${TEST_RESULT_FILE})" echo "Artifacts were written to ${ARTIFACTS}" echo "Test result code is ${result}" - exit ${result} } diff --git a/vendor/github.com/knative/test-infra/scripts/library.sh b/vendor/github.com/knative/test-infra/scripts/library.sh index 3472b477357..89a93c91aa9 100755 --- a/vendor/github.com/knative/test-infra/scripts/library.sh +++ b/vendor/github.com/knative/test-infra/scripts/library.sh @@ -146,6 +146,25 @@ function wait_until_pods_running() { return 1 } +# Waits until all batch job pods are running in the given namespace. +# Parameters: $1 - namespace. +function wait_until_batch_job_complete() { + echo -n "Waiting until all batch job pods in namespace $1 run to completion." + for i in {1..150}; do # timeout after 5 minutes + local pods="$(kubectl get pods --selector=job-name --no-headers -n $1 2>/dev/null | grep -v '^[[:space:]]*$')" + # All pods must be complete + local not_complete=$(echo "${pods}" | grep -v Completed | wc -l) + if [[ ${not_complete} -eq 0 ]]; then + echo -e "\nAll pods are complete:\n${pods}" + return 0 + fi + echo -n "." + sleep 2 + done + echo -e "\n\nERROR: timeout waiting for pods to complete\n${pods}" + return 1 +} + # Waits until the given service has an external address (IP/hostname). # Parameters: $1 - namespace. # $2 - service name. @@ -302,8 +321,9 @@ function report_go_test() { function start_latest_knative_serving() { header "Starting Knative Serving" subheader "Installing Istio" - echo "Installing Istio CRD from ${KNATIVE_ISTIO_CRD_YAML}" + echo "Running Istio CRD from ${KNATIVE_ISTIO_CRD_YAML}" kubectl apply -f ${KNATIVE_ISTIO_CRD_YAML} || return 1 + wait_until_batch_job_complete istio-system || return 1 echo "Installing Istio from ${KNATIVE_ISTIO_YAML}" kubectl apply -f ${KNATIVE_ISTIO_YAML} || return 1 wait_until_pods_running istio-system || return 1 @@ -314,15 +334,6 @@ function start_latest_knative_serving() { wait_until_pods_running knative-serving || return 1 } -# Install the latest stable Knative/build in the current cluster. -function start_latest_knative_build() { - header "Starting Knative Build" - subheader "Installing Knative Build" - echo "Installing Build from ${KNATIVE_BUILD_RELEASE}" - kubectl apply -f ${KNATIVE_BUILD_RELEASE} || return 1 - wait_until_pods_running knative-build || return 1 -} - # Run a go tool, installing it first if necessary. # Parameters: $1 - tool package/dir for go get/install. # $2 - tool to run. @@ -429,6 +440,12 @@ function remove_broken_symlinks() { done } +# Return whether the given parameter is knative-tests. +# Parameters: $1 - project name +function is_protected_project() { + [[ -n "$1" && "$1" == "knative-tests" ]] +} + # Returns the canonical path of a filesystem object. # Parameters: $1 - path to return in canonical form # $2 - base dir for relative links; optional, defaults to current diff --git a/vendor/github.com/knative/test-infra/scripts/release.sh b/vendor/github.com/knative/test-infra/scripts/release.sh index fe80f6f1be7..5704576ab45 100755 --- a/vendor/github.com/knative/test-infra/scripts/release.sh +++ b/vendor/github.com/knative/test-infra/scripts/release.sh @@ -64,9 +64,12 @@ function publish_yamls() { echo "Publishing [$@] to ${DEST}" gsutil -m cp $@ ${DEST} } - # Before publishing the YAML files, cleanup the `latest` dir. - echo "Cleaning up the 'latest' directory first" - gsutil -m rm gs://${RELEASE_GCS_BUCKET}/latest/** + # Before publishing the YAML files, cleanup the `latest` dir if it exists. + local latest_dir="gs://${RELEASE_GCS_BUCKET}/latest" + if [[ -n "$(gsutil ls ${latest_dir} 2> /dev/null)" ]]; then + echo "Cleaning up '${latest_dir}' first" + gsutil -m rm ${latest_dir}/** + fi verbose_gsutil_cp latest $@ [[ -n ${TAG} ]] && verbose_gsutil_cp previous/${TAG} $@ } @@ -465,6 +468,9 @@ function main() { parse_flags $@ # Log what will be done and where. banner "Release configuration" + echo "- gcloud user: $(gcloud config get-value core/account)" + echo "- Go path: ${GOPATH}" + echo "- Repository root: ${REPO_ROOT_DIR}" echo "- Destination GCR: ${KO_DOCKER_REPO}" (( SKIP_TESTS )) && echo "- Tests will NOT be run" || echo "- Tests will be run" if (( TAG_RELEASE )); then