|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2026 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 | +source hack/lib.sh |
| 19 | + |
| 20 | +# have a place to store things |
| 21 | +if [ -z "${ARTIFACTS:-}" ]; then |
| 22 | + ARTIFACTS=.e2e/artifacts |
| 23 | + mkdir -p "$ARTIFACTS" |
| 24 | +fi |
| 25 | + |
| 26 | +echodate "Build artifacts will be placed in $ARTIFACTS." |
| 27 | +export ARTIFACTS="$(realpath "$ARTIFACTS")" |
| 28 | + |
| 29 | +# build the agent, we will start it many times during the tests |
| 30 | +echodate "Building the init-agent…" |
| 31 | +make build |
| 32 | + |
| 33 | +# start a shared kcp process |
| 34 | +KCP="$(UGET_PRINT_PATH=relative make --no-print-directory install-kcp)" |
| 35 | + |
| 36 | +KCP_ROOT_DIRECTORY=.kcp.e2e |
| 37 | +KCP_LOGFILE="$ARTIFACTS/kcp.log" |
| 38 | +KCP_TOKENFILE=hack/ci/testdata/e2e-kcp.tokens |
| 39 | + |
| 40 | +echodate "Starting kcp…" |
| 41 | +rm -rf "$KCP_ROOT_DIRECTORY" "$KCP_LOGFILE" |
| 42 | +"$KCP" start \ |
| 43 | + -v4 \ |
| 44 | + --token-auth-file "$KCP_TOKENFILE" \ |
| 45 | + --root-directory "$KCP_ROOT_DIRECTORY" 1>"$KCP_LOGFILE" 2>&1 & |
| 46 | + |
| 47 | +stop_kcp() { |
| 48 | + echodate "Stopping kcp processes (set \$KEEP_KCP=true to not do this)…" |
| 49 | + pkill -e kcp |
| 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 | +KUBECTL="$(UGET_PRINT_PATH=relative make --no-print-directory install-kubectl)" |
| 66 | +if ! retry_linear 3 20 "$KUBECTL" --kubeconfig "$KCP_KUBECONFIG" get workspaces; then |
| 67 | + echodate "kcp never became ready." |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# makes it easier to reference these files from various _test.go files. |
| 72 | +export ROOT_DIRECTORY="$(realpath .)" |
| 73 | +export KCP_KUBECONFIG="$(realpath "$KCP_KUBECONFIG")" |
| 74 | +export AGENT_BINARY="$(realpath _build/init-agent)" |
| 75 | + |
| 76 | +# time to run the tests |
| 77 | +echodate "Running e2e tests…" |
| 78 | +WHAT="${WHAT:-./test/e2e/...}" |
| 79 | +(set -x; go test -tags e2e -timeout 2h -v $WHAT) |
| 80 | + |
| 81 | +echodate "Done. :-)" |
0 commit comments