...
1#!/usr/bin/env bash
2# Copyright 2018 The Kubernetes Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -o errexit
17set -o nounset
18set -o pipefail
19
20# Shutdown the tests gracefully then save the results
21# shellcheck disable=SC2317 # false positive
22shutdown () {
23 E2E_SUITE_PID=$(pgrep e2e.test)
24 echo "sending TERM to ${E2E_SUITE_PID}"
25 kill -s TERM "${E2E_SUITE_PID}"
26
27 # Kind of a hack to wait for this pid to finish.
28 # Since it's not a child of this shell we cannot use wait.
29 tail --pid "${E2E_SUITE_PID}" -f /dev/null
30 saveResults
31}
32
33saveResults() {
34 cd "${RESULTS_DIR}" || exit
35 tar -czf e2e.tar.gz ./*
36 # mark the done file as a termination notice.
37 echo -n "${RESULTS_DIR}/e2e.tar.gz" > "${RESULTS_DIR}/done"
38}
39
40# Optional Golang runner alternative to the bash script.
41# Entry provided via env var to simplify invocation.
42if [[ -n ${E2E_USE_GO_RUNNER:-} ]]; then
43 set -x
44 /gorunner && ret=0 || ret=$?
45 exit "${ret}"
46fi
47
48# We get the TERM from kubernetes and handle it gracefully
49trap shutdown TERM
50
51ginkgo_args=()
52if [[ -n ${E2E_DRYRUN:-} ]]; then
53 ginkgo_args+=("--dry-run=true")
54fi
55
56# NOTE: Ginkgo's default timeout has been reduced from 24h to 1h in V2, set it manually here as "24h"
57# for backward compatibility purpose.
58ginkgo_args+=("--timeout=24h")
59
60case ${E2E_PARALLEL} in
61 'y'|'Y'|'true')
62 # The flag '--p' will automatically detect the optimal number of ginkgo nodes.
63 ginkgo_args+=("--p")
64 # Skip serial tests if parallel mode is enabled.
65 E2E_SKIP="\\[Serial\\]|${E2E_SKIP}" ;;
66esac
67
68ginkgo_args+=(
69 "--focus=${E2E_FOCUS}"
70 "--skip=${E2E_SKIP}"
71 "--no-color=true"
72)
73
74set -x
75/usr/local/bin/ginkgo "${ginkgo_args[@]}" /usr/local/bin/e2e.test -- --disable-log-dump --repo-root=/kubernetes --provider="${E2E_PROVIDER}" --report-dir="${RESULTS_DIR}" --kubeconfig="${KUBECONFIG}" -v="${E2E_VERBOSITY}" > >(tee "${RESULTS_DIR}"/e2e.log) && ret=0 || ret=$?
76set +x
77saveResults
78exit "${ret}"
View as plain text