diff --git a/Gopkg.lock b/Gopkg.lock index 6c203d981321..dbd6c89e145c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -348,11 +348,11 @@ [[projects]] branch = "master" - digest = "1:851129618684df5fe963fd5fe7bf75efb28e9adde03855d836cfe1a9ed1e5f4a" + digest = "1:c9a813ac651ba08533e49b886b85d272296119512ca3fda10bc318a5199080cd" name = "github.com/knative/test-infra" packages = ["."] pruneopts = "T" - revision = "f53c40459b2d126c32f5139ee0d9251748ad6dd8" + revision = "4a4a682ee1fd31f33e450406393c3553b9ec5c2a" [[projects]] branch = "master" diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh index e54a475b964e..19166fc5ebab 100755 --- a/test/presubmit-tests.sh +++ b/test/presubmit-tests.sh @@ -33,11 +33,9 @@ function build_tests() { go test -run=^$ -tags=e2e ./test/... || result=1 subheader "Checking autogenerated code is up-to-date" ./hack/verify-codegen.sh || result=1 - subheader "Checking for forbidden licenses" - # Fetch the google/licenseclassifier for its license db - go get github.com/google/licenseclassifier # Check that we don't have any forbidden licenses in our images. - dep-collector -check ./cmd/* || result=1 + subheader "Checking for forbidden licenses" + check_licenses ./cmd/* || result=1 return ${result} } 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 b850489cc79e..1262f98217c8 100755 --- a/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh +++ b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh @@ -58,7 +58,8 @@ function build_resource_name() { readonly E2E_BASE_NAME=k$(basename ${REPO_ROOT_DIR}) readonly E2E_CLUSTER_NAME=$(build_resource_name e2e-cls) readonly E2E_NETWORK_NAME=$(build_resource_name e2e-net) -readonly E2E_CLUSTER_ZONE=us-central1-a +readonly E2E_CLUSTER_REGION=us-central1 +readonly E2E_CLUSTER_ZONE=${E2E_CLUSTER_REGION}-a readonly E2E_CLUSTER_NODES=3 readonly E2E_CLUSTER_MACHINE=n1-standard-4 readonly TEST_RESULT_FILE=/tmp/${E2E_BASE_NAME}-e2e-result @@ -90,6 +91,45 @@ function fail_test() { exit 1 } +# Download the k8s binaries required by kubetest. +function download_k8s() { + local version=${SERVING_GKE_VERSION} + if [[ "${version}" == "latest" ]]; then + # Fetch latest valid version + local versions="$(gcloud container get-server-config \ + --project=${GCP_PROJECT} \ + --format='value(validMasterVersions)' \ + --region=${E2E_CLUSTER_REGION})" + local gke_versions=(`echo -n ${versions//;/ /}`) + # Get first (latest) version, excluding the "-gke.#" suffix + version="${gke_versions[0]%-*}" + echo "Latest GKE is ${version}, from [${versions//;/, /}]" + elif [[ "${version}" == "default" ]]; then + echo "ERROR: `default` GKE version is not supported yet" + return 1 + fi + # Download k8s to staging dir + version=v${version} + local staging_dir=${GOPATH}/src/k8s.io/kubernetes/_output/gcs-stage + rm -fr ${staging_dir} + staging_dir=${staging_dir}/${version} + mkdir -p ${staging_dir} + pushd ${staging_dir} + export KUBERNETES_PROVIDER=gke + export KUBERNETES_RELEASE=${version} + curl -fsSL https://get.k8s.io | bash + local result=$? + if [[ ${result} -eq 0 ]]; then + mv kubernetes/server/kubernetes-server-*.tar.gz . + mv kubernetes/client/kubernetes-client-*.tar.gz . + rm -fr kubernetes + # Create an empty kubernetes test tarball; we don't use it but kubetest will fetch it + tar -czf kubernetes-test.tar.gz -T /dev/null + fi + popd + return ${result} +} + # Dump info about the test cluster. If dump_extra_cluster_info() is defined, calls it too. # This is intended to be called when a test fails to provide debugging information. function dump_cluster_state() { @@ -126,6 +166,8 @@ function create_test_cluster() { ) if (( ! IS_PROW )); then CLUSTER_CREATION_ARGS+=(--gcp-project=${PROJECT_ID:?"PROJECT_ID must be set to the GCP project where the tests are run."}) + else + CLUSTER_CREATION_ARGS+=(--gcp-service-account=/etc/service-account/service-account.json) 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. @@ -136,15 +178,19 @@ function create_test_cluster() { # be a writeable docker repo. export K8S_USER_OVERRIDE= export K8S_CLUSTER_OVERRIDE= + # Get the current GCP project + export GCP_PROJECT=${PROJECT_ID} + [[ -z ${GCP_PROJECT} ]] && export GCP_PROJECT=$(gcloud config get-value project) # Assume test failed (see more details at the end of this script). echo -n "1"> ${TEST_RESULT_FILE} local test_cmd_args="--run-tests" (( EMIT_METRICS )) && test_cmd_args+=" --emit-metrics" echo "Test script is ${E2E_SCRIPT}" + download_k8s || return 1 kubetest "${CLUSTER_CREATION_ARGS[@]}" \ --up \ --down \ - --extract "gke-${SERVING_GKE_VERSION}" \ + --extract local \ --gcp-node-image ${SERVING_GKE_IMAGE} \ --test-cmd "${E2E_SCRIPT}" \ --test-cmd-args "${test_cmd_args}" @@ -152,23 +198,20 @@ function create_test_cluster() { # 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 gcp_project=${PROJECT_ID} - [[ -z ${gcp_project} ]] && gcp_project=$(gcloud config get-value project) local http_health_checks="$(gcloud compute target-pools list \ - --project=${gcp_project} --format='value(healthChecks)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ + --project=${GCP_PROJECT} --format='value(healthChecks)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ grep httpHealthChecks | tr '\n' ' ')" local target_pools="$(gcloud compute target-pools list \ - --project=${gcp_project} --format='value(name)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ + --project=${GCP_PROJECT} --format='value(name)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ tr '\n' ' ')" - local region="$(gcloud compute zones list --filter=name=${E2E_CLUSTER_ZONE} --format='value(region)')" if [[ -n "${target_pools}" ]]; then echo "Found leaked target pools, deleting" - gcloud compute forwarding-rules delete -q --project=${gcp_project} --region=${region} ${target_pools} - gcloud compute target-pools delete -q --project=${gcp_project} --region=${region} ${target_pools} + gcloud compute forwarding-rules delete -q --project=${GCP_PROJECT} --region=${E2E_CLUSTER_REGION} ${target_pools} + gcloud compute target-pools delete -q --project=${GCP_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=${gcp_project} ${http_health_checks} + gcloud compute http-health-checks delete -q --project=${GCP_PROJECT} ${http_health_checks} fi local result="$(cat ${TEST_RESULT_FILE})" echo "Test result code is $result" diff --git a/vendor/github.com/knative/test-infra/scripts/library.sh b/vendor/github.com/knative/test-infra/scripts/library.sh index 5936fde1d83c..d9a2e0bdbabb 100755 --- a/vendor/github.com/knative/test-infra/scripts/library.sh +++ b/vendor/github.com/knative/test-infra/scripts/library.sh @@ -19,7 +19,7 @@ # called from command line. # Default GKE version to be used with Knative Serving -readonly SERVING_GKE_VERSION=default +readonly SERVING_GKE_VERSION=latest readonly SERVING_GKE_IMAGE=cos # Public images and yaml files. @@ -44,7 +44,8 @@ function make_banner() { # Simple header for logging purposes. function header() { - make_banner "=" "${1^^}" + local upper="$(echo $1 | tr a-z A-Z)" + make_banner "=" "${upper}" } # Simple subheader for logging purposes. @@ -102,7 +103,7 @@ function wait_until_pods_running() { local pods="$(kubectl get pods --no-headers -n $1 2>/dev/null)" # All pods must be running local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l) - if [[ -n "${pods}" && ${not_running} == 0 ]]; then + if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then local all_ready=1 while read pod ; do local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`) @@ -112,17 +113,16 @@ function wait_until_pods_running() { [[ ${status[0]} -lt 1 ]] && all_ready=0 && break [[ ${status[1]} -lt 1 ]] && all_ready=0 && break [[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break - done <<< $(echo "${pods}") + done <<< $(echo "${pods}" | grep -v Completed) if (( all_ready )); then - echo -e "\nAll pods are up:" - kubectl get pods -n $1 + echo -e "\nAll pods are up:\n${pods}" return 0 fi fi echo -n "." sleep 2 done - echo -e "\n\nERROR: timeout waiting for pods to come up" + echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}" kubectl get pods -n $1 return 1 } @@ -164,10 +164,16 @@ 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 \ + kubectl config set-credentials cluster-admin \ + --username=admin --password=${password} + 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. @@ -259,6 +265,16 @@ function start_latest_knative_build() { wait_until_pods_running knative-build || return 1 } +# Run dep-collector, installing it first if necessary. +# Parameters: $1..$n - parameters passed to dep-collector. +function run_dep_collector() { + local local_dep_collector="$(which dep-collector)" + if [[ -z ${local_dep_collector} ]]; then + go get -u github.com/mattmoor/dep-collector + fi + dep-collector $@ +} + # Run dep-collector to update licenses. # Parameters: $1 - output file, relative to repo root dir. # $2...$n - directories and files to inspect. @@ -266,11 +282,16 @@ function update_licenses() { cd ${REPO_ROOT_DIR} || return 1 local dst=$1 shift - local local_dep_collector="$(which dep-collector)" - if [[ -z ${local_dep_collector} ]]; then - go get -u github.com/mattmoor/dep-collector - fi - dep-collector $@ > ./${dst} + run_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 + go get -u github.com/google/licenseclassifier + # Check that we don't have any forbidden licenses in our images. + run_dep_collector -check $@ } # Check links in all .md files in the repo.