1717set -euo pipefail
1818source hack/lib.sh
1919
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+
2029# build the agent, we will start it many times during the tests
2130echodate " Building the api-syncagent…"
2231make build
@@ -31,27 +40,44 @@ KUBEBUILDER_ASSETS="$(realpath "$KUBEBUILDER_ASSETS")"
3140make _tools/kcp
3241
3342KCP_ROOT_DIRECTORY=.kcp.e2e
34- KCP_LOGFILE=kcp.e2e.log
43+ KCP_LOGFILE=" $ARTIFACTS /kcp.log"
44+ KCP_TOKENFILE=hack/ci/testdata/e2e-kcp.tokens
3545
3646echodate " Starting kcp…"
3747rm -rf " $KCP_ROOT_DIRECTORY " " $KCP_LOGFILE "
3848_tools/kcp start \
49+ -v4 \
50+ --token-auth-file " $KCP_TOKENFILE " \
3951 --root-directory " $KCP_ROOT_DIRECTORY " 1> " $KCP_LOGFILE " 2>&1 &
4052
4153stop_kcp () {
42- echodate " Stopping kcp processes…"
54+ echodate " Stopping kcp processes (set \$ KEEP_KCP=true to not do this) …"
4355 pkill -e kcp
4456}
45- append_trap stop_kcp EXIT
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,) "
4666
4767# Wait for kcp to be ready; this env name is also hardcoded in the Go tests.
4868export KCP_KUBECONFIG=" $KCP_ROOT_DIRECTORY /admin.kubeconfig"
4969
50- if ! retry_linear 3 20 kubectl --kubeconfig " $KCP_KUBECONFIG " get logicalcluster; then
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
5172 echodate " kcp never became ready."
5273 exit 1
5374fi
5475
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+
5581# time to run the tests
5682echodate " Running e2e tests…"
5783(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...)
0 commit comments