|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The KCP Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +cd "$(dirname $0)/.." |
| 20 | + |
| 21 | +source hack/lib.sh |
| 22 | + |
| 23 | +# get kube envtest binaries |
| 24 | +echodate "Setting up Kube binaries…" |
| 25 | +export KUBEBUILDER_ASSETS="$(_tools/setup-envtest use 1.31.0 --bin-dir _tools -p path)" |
| 26 | +KUBEBUILDER_ASSETS="$(realpath "$KUBEBUILDER_ASSETS")" |
| 27 | + |
| 28 | +export ARTIFACTS=.e2e |
| 29 | + |
| 30 | +rm -rf "$ARTIFACTS" |
| 31 | +mkdir -p "$ARTIFACTS" |
| 32 | + |
| 33 | +KCP_ROOT_DIRECTORY="$ARTIFACTS/kcp" |
| 34 | +KCP_LOGFILE="$ARTIFACTS/kcp.log" |
| 35 | +KCP_TOKENFILE=hack/ci/testdata/e2e-kcp.tokens |
| 36 | +KCP_PID=0 |
| 37 | + |
| 38 | +echodate "Starting kcp…" |
| 39 | +rm -rf "$KCP_ROOT_DIRECTORY" "$KCP_LOGFILE" |
| 40 | +_tools/kcp start \ |
| 41 | + -v4 \ |
| 42 | + --token-auth-file "$KCP_TOKENFILE" \ |
| 43 | + --root-directory "$KCP_ROOT_DIRECTORY" 1>"$KCP_LOGFILE" 2>&1 & |
| 44 | +KCP_PID=$! |
| 45 | + |
| 46 | +stop_kcp() { |
| 47 | + echodate "Stopping kcp (set \$KEEP_KCP=true to not do this)…" |
| 48 | + kill -TERM $KCP_PID |
| 49 | + wait $KCP_PID |
| 50 | +} |
| 51 | + |
| 52 | +if [[ -v KEEP_KCP ]] && $KEEP_KCP; then |
| 53 | + echodate "\$KEEP_KCP is set, will not stop kcp once the script is finished." |
| 54 | +else |
| 55 | + append_trap stop_kcp EXIT |
| 56 | +fi |
| 57 | + |
| 58 | +# make the token available to the Go tests |
| 59 | +export KCP_AGENT_TOKEN="$(grep e2e "$KCP_TOKENFILE" | cut -f1 -d,)" |
| 60 | + |
| 61 | +# Wait for kcp to be ready; this env name is also hardcoded in the Go tests. |
| 62 | +export KCP_KUBECONFIG="$KCP_ROOT_DIRECTORY/admin.kubeconfig" |
| 63 | + |
| 64 | +# the tenancy API becomes available pretty late during startup, so it's a good readiness check |
| 65 | +if ! retry_linear 3 20 kubectl --kubeconfig "$KCP_KUBECONFIG" get workspaces; then |
| 66 | + echodate "kcp never became ready." |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +# makes it easier to reference these files from various _test.go files. |
| 71 | +export ROOT_DIRECTORY="$(realpath .)" |
| 72 | +export KCP_KUBECONFIG="$(realpath "$KCP_KUBECONFIG")" |
| 73 | +export AGENT_BINARY="$(realpath _build/api-syncagent)" |
| 74 | + |
| 75 | +# The tests require ARTIFACTS to be absolute. |
| 76 | +ARTIFACTS="$(realpath "$ARTIFACTS")" |
| 77 | + |
| 78 | +# time to run the tests |
| 79 | +echodate "Running e2e tests…" |
| 80 | + |
| 81 | +WHAT="${WHAT:-./test/e2e/...}" |
| 82 | +TEST_ARGS="${TEST_ARGS:--timeout 30m -v}" |
| 83 | +E2E_PARALLELISM=${E2E_PARALLELISM:-2} |
| 84 | + |
| 85 | +(set -x; go test -tags e2e -parallel $E2E_PARALLELISM $TEST_ARGS "$WHAT") |
0 commit comments