|
| 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 | +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 api-syncagent…" |
| 31 | +make build |
| 32 | + |
| 33 | +# get kube envtest binaries |
| 34 | +echodate "Setting up Kube binaries…" |
| 35 | +make _tools/setup-envtest |
| 36 | +export KUBEBUILDER_ASSETS="$(_tools/setup-envtest use 1.31.0 --bin-dir _tools -p path)" |
| 37 | +KUBEBUILDER_ASSETS="$(realpath "$KUBEBUILDER_ASSETS")" |
| 38 | + |
| 39 | +# start a shared kcp process |
| 40 | +make _tools/kcp |
| 41 | + |
| 42 | +KCP_ROOT_DIRECTORY=.kcp.e2e |
| 43 | +KCP_LOGFILE="$ARTIFACTS/kcp.log" |
| 44 | +KCP_TOKENFILE=hack/ci/testdata/e2e-kcp.tokens |
| 45 | + |
| 46 | +echodate "Starting kcp…" |
| 47 | +rm -rf "$KCP_ROOT_DIRECTORY" "$KCP_LOGFILE" |
| 48 | +_tools/kcp start \ |
| 49 | + -v4 \ |
| 50 | + --token-auth-file "$KCP_TOKENFILE" \ |
| 51 | + --root-directory "$KCP_ROOT_DIRECTORY" 1>"$KCP_LOGFILE" 2>&1 & |
| 52 | + |
| 53 | +stop_kcp() { |
| 54 | + echodate "Stopping kcp processes (set \$KEEP_KCP=true to not do this)…" |
| 55 | + pkill -e kcp |
| 56 | +} |
| 57 | + |
| 58 | +if [[ -v KEEP_KCP ]] && $KEEP_KCP; then |
| 59 | + echodate "\$KEEP_KCP is set, will not stop kcp once the script is finished." |
| 60 | +else |
| 61 | + append_trap stop_kcp EXIT |
| 62 | +fi |
| 63 | + |
| 64 | +# make the token available to the Go tests |
| 65 | +export KCP_AGENT_TOKEN="$(grep e2e "$KCP_TOKENFILE" | cut -f1 -d,)" |
| 66 | + |
| 67 | +# Wait for kcp to be ready; this env name is also hardcoded in the Go tests. |
| 68 | +export KCP_KUBECONFIG="$KCP_ROOT_DIRECTORY/admin.kubeconfig" |
| 69 | + |
| 70 | +# the tenancy API becomes available pretty late during startup, so it's a good readiness check |
| 71 | +if ! retry_linear 3 20 kubectl --kubeconfig "$KCP_KUBECONFIG" get workspaces; then |
| 72 | + echodate "kcp never became ready." |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +# makes it easier to reference thesefiles from various _test.go files. |
| 77 | +export ROOT_DIRECTORY="$(realpath .)" |
| 78 | +export KCP_KUBECONFIG="$(realpath "$KCP_KUBECONFIG")" |
| 79 | +export AGENT_BINARY="$(realpath _build/api-syncagent)" |
| 80 | + |
| 81 | +# time to run the tests |
| 82 | +echodate "Running e2e tests…" |
| 83 | +(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...) |
| 84 | + |
| 85 | +echodate "Done. :-)" |
0 commit comments