-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·124 lines (115 loc) · 5.92 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·124 lines (115 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
# run_tests.sh - acquire an e2e binary and run it, or defer to bz tests.
#
# Selection (automatic, matches Semaphore):
# - TEST_TYPE == k8s-e2e → run the monorepo e2e binary via `make e2e-run`.
# The binary is acquired first: built from local source when RUN_LOCAL_TESTS
# is set (per-PR CI), otherwise downloaded from the hashrelease (scheduled
# CI). E2E_TEST_CONFIG selects specs and may be empty (default config).
# - Else (non-e2e test types: benchmarks, certification, etc.) → `bz tests`.
#
# Required env:
# BZ_LOCAL_DIR, BZ_LOGS_DIR, HOME, REPORT_DIR, TEST_TYPE
# Required for local builds:
# E2E_TEST_CONFIG
# Required for hashrelease downloads:
# RELEASE_STREAM
#
# Sourced from body_*.sh. Exits with the test exit code.
for _var in BZ_LOCAL_DIR BZ_LOGS_DIR HOME REPORT_DIR TEST_TYPE; do
if [[ -z "${!_var}" ]]; then echo "[ERROR] ${_var} is required but not set"; exit 1; fi
done
if [[ -n "${RUN_LOCAL_TESTS:-}" ]]; then
# Per-PR CI: build the e2e binary from the local source tree.
echo "[INFO] building e2e binary from local source..."
pushd "${CI_HOME}/${CI_GIT_DIR}" || exit
make -C e2e build |& tee >(gzip --stdout > "${BZ_LOGS_DIR}/${TEST_TYPE}-build.log.gz")
E2E_BINARY=/go/src/github.com/projectcalico/calico/e2e/bin/k8s/e2e.test
popd || exit
elif [[ "${TEST_TYPE}" == "k8s-e2e" ]]; then
# Scheduled CI: download the pre-built e2e binary from the hashrelease.
echo "[INFO] downloading e2e binary from hashrelease..."
HASHREL_URL=$(curl --retry 9 --retry-all-errors -sS "https://latest-os.docs.eng.tigera.net/${RELEASE_STREAM}.txt")
echo "[INFO] hashrelease URL: ${HASHREL_URL}"
ARCH=$(uname -m); [[ "$ARCH" == "x86_64" ]] && ARCH=amd64; [[ "$ARCH" == "aarch64" ]] && ARCH=arm64
mkdir -p "${CI_HOME}/${CI_GIT_DIR}/e2e/bin/k8s"
curl --retry 9 --retry-all-errors -fsSL "${HASHREL_URL}/files/e2e/e2e-linux-${ARCH}.test" -o "${CI_HOME}/${CI_GIT_DIR}/e2e/bin/k8s/e2e.test"
chmod +x "${CI_HOME}/${CI_GIT_DIR}/e2e/bin/k8s/e2e.test"
echo "[INFO] downloaded e2e binary to ${CI_HOME}/${CI_GIT_DIR}/e2e/bin/k8s/e2e.test"
E2E_BINARY=/go/src/github.com/projectcalico/calico/e2e/bin/k8s/e2e.test
fi
# E2E_BINARY is a set/unset sentinel (its value is not used here -- make
# e2e-run locates the binary itself). Take the structured path whenever a
# k8s-e2e binary was acquired above; non-e2e test types fall through to bz
# tests below. E2E_TEST_CONFIG may be empty (selects the default config).
if [[ -n "${E2E_BINARY:-}" ]]; then
echo "[INFO] starting e2e tests..."
pushd "${CI_HOME}/${CI_GIT_DIR}" || exit
# Pick a runtime image. The local-build path already pulled
# calico/go-build to compile the binary, so reusing it for the run
# step is free. The hashrelease path didn't compile anything, so
# there's no reason to drag in the build toolchain -- use the
# official golang image (debian-bookworm base, glibc-compatible
# with the binary, ~800MB vs ~2GB).
# The e2e binary is CGO-linked against libbpf and dynamically depends on
# libelf and libz at runtime; the test scripts also call uuidgen. The
# calico/go-build image already has these; the upstream golang:bookworm
# image does not, so install them on the fly when using that path.
PRE_RUN=":"
if [[ -n "${RUN_LOCAL_TESTS:-}" ]]; then
GO_BUILD_VER=$(make --no-print-directory -f ./metadata.mk -f - <<<'print:; @echo $(GO_BUILD_VER)' print)
RUN_IMAGE="calico/go-build:${GO_BUILD_VER}"
else
GO_VERSION=$(make --no-print-directory -f ./metadata.mk -f - <<<'print:; @echo $(GO_VERSION)' print)
RUN_IMAGE="golang:${GO_VERSION}-bookworm"
PRE_RUN="apt-get update -qq && apt-get install -y --no-install-recommends libelf1 zlib1g uuid-runtime"
fi
# The upstream k8s e2e framework shells out to `kubectl` for any
# exec-into-pod step (RunHostCmd, etc.), so kubectl must be on PATH inside
# the runner. Fetch a K8S_VERSION-pinned binary via the repo's `make
# kubectl` target; it lands in hack/test/kind/ which is bind-mounted into
# the container, and we prepend that to PATH inside the bash -c below.
make kubectl
# EKS kubeconfigs exec aws-iam-authenticator (PATH lookup), which the stock
# golang image lacks, so client-go fails before any tests run. The aws-eks
# provisioner installs it on the host; bind-mount it when present (no-op otherwise).
auth_mount=()
if [[ -x "${BZ_LOCAL_DIR}/bin/aws-iam-authenticator" ]]; then
auth_mount=(-v "${BZ_LOCAL_DIR}/bin/aws-iam-authenticator:/usr/local/bin/aws-iam-authenticator:ro")
fi
# Capture the exit code so the JUnit copy below runs even when tests fail
# (set -e would otherwise bail out before the cp).
e2e_rc=0
docker run --rm --init --net=host \
-e LOCAL_USER_ID="$(id -u)" \
-e GOCACHE=/go-cache \
-e GOPATH=/go \
-e KUBECONFIG=/kubeconfig \
-e PRODUCT=${PRODUCT:-calico} \
${K8S_E2E_DOCKER_EXTRA_FLAGS:-} \
"${auth_mount[@]}" \
-v "$(pwd)":/go/src/github.com/projectcalico/calico:rw \
-v "$(pwd)"/.go-pkg-cache:/go-cache:rw \
-v "${BZ_LOCAL_DIR}/kubeconfig:/kubeconfig:ro" \
-w /go/src/github.com/projectcalico/calico \
"${RUN_IMAGE}" \
bash -c "${PRE_RUN} && \
export PATH=/go/src/github.com/projectcalico/calico/hack/test/kind:\$PATH && \
git config --global --add safe.directory '*' && \
make e2e-run \
KUBECONFIG=/kubeconfig \
E2E_TEST_CONFIG='${E2E_TEST_CONFIG}' \
E2E_OUTPUT_DIR=report \
E2E_JUNIT_REPORT=junit.xml" \
|& tee "${BZ_LOGS_DIR}/${TEST_TYPE}-tests.log" || e2e_rc=$?
# Copy JUnit XML to REPORT_DIR so the epilogue publishes it.
mkdir -p "${REPORT_DIR}"
cp report/junit.xml "${REPORT_DIR}/junit.xml" 2>/dev/null || true
popd || exit
# Propagate the original test exit code.
exit ${e2e_rc}
else
# Non-e2e test types (benchmarks, certification, etc.) -- defer to bz.
echo "[INFO] starting bz testing (K8S_E2E_FLAGS=${K8S_E2E_FLAGS:-<none>})..."
bz tests ${VERBOSE} |& tee >(gzip --stdout > "${BZ_LOGS_DIR}/${TEST_TYPE}-tests.log.gz")
fi