Skip to content

Commit 0e24491

Browse files
committed
start kcp natively without kind, use envtest
On-behalf-of: @SAP [email protected]
1 parent 5d3b31f commit 0e24491

File tree

2 files changed

+58
-54
lines changed

2 files changed

+58
-54
lines changed

hack/ci/run-e2e-tests.sh

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,45 @@
1515
# limitations under the License.
1616

1717
set -euo pipefail
18+
source hack/lib.sh
1819

19-
# build the image(s)
20-
export IMAGE_TAG=local
20+
# build the agent, we will start it many times during the tests
21+
echodate "Building the api-syncagent…"
22+
make build
2123

22-
echo "Building container images…"
23-
# ARCHITECTURES=amd64 DRY_RUN=yes ./hack/ci/build-image.sh
24+
# get kube envtest binaries
25+
echodate "Setting up Kube binaries…"
26+
make _tools/setup-envtest
27+
export KUBEBUILDER_ASSETS="$(_tools/setup-envtest use 1.31.0 --bin-dir _tools -p path)"
28+
KUBEBUILDER_ASSETS="$(realpath "$KUBEBUILDER_ASSETS")"
2429

25-
# start docker so we can run kind
26-
# start-docker.sh
30+
# start a shared kcp process
31+
make _tools/kcp
2732

28-
# create a local kind cluster
29-
KIND_CLUSTER_NAME=e2e
33+
KCP_ROOT_DIRECTORY=.kcp.e2e
34+
KCP_LOGFILE=kcp.e2e.log
3035

31-
# echo "Preloading the kindest/node image…"
32-
# docker load --input /kindest.tar
36+
echodate "Starting kcp…"
37+
rm -rf "$KCP_ROOT_DIRECTORY" "$KCP_LOGFILE"
38+
_tools/kcp start \
39+
--root-directory "$KCP_ROOT_DIRECTORY" 1>"$KCP_LOGFILE" 2>&1 &
3340

34-
export KUBECONFIG=$(mktemp)
35-
export KUBECONFIG=e2e.kubeconfig
36-
echo "Creating kind cluster $KIND_CLUSTER_NAME"
37-
kind create cluster --name "$KIND_CLUSTER_NAME"
38-
chmod 600 "$KUBECONFIG"
41+
stop_kcp() {
42+
echodate "Stopping kcp processes…"
43+
pkill -e kcp
44+
}
45+
append_trap stop_kcp EXIT
3946

40-
# load the agent image into the kind cluster
41-
image="ghcr.io/kcp-dev/api-syncagent:$IMAGE_TAG"
42-
archive=agent.tar
47+
# Wait for kcp to be ready; this env name is also hardcoded in the Go tests.
48+
export KCP_KUBECONFIG="$KCP_ROOT_DIRECTORY/admin.kubeconfig"
4349

44-
echo "Loading api-syncagent image into kind…"
45-
buildah manifest push --all "$image" "oci-archive:$archive:$image"
46-
kind load image-archive "$archive" --name "$KIND_CLUSTER_NAME"
47-
48-
# deploy cert-manager
49-
echo "Installing cert-manager…"
50-
51-
helm repo add jetstack https://charts.jetstack.io
52-
helm repo update
53-
54-
kubectl apply --filename https://github.com/cert-manager/cert-manager/releases/download/v1.17.0/cert-manager.crds.yaml
55-
helm install \
56-
--wait \
57-
--namespace cert-manager \
58-
--create-namespace \
59-
--version v1.17.0 \
60-
cert-manager jetstack/cert-manager
61-
62-
# deploy a kcp which will live for the entire runtime of the e2e tests and be shared among all subtests
63-
echo "Installing kcp into kind…"
64-
65-
helm repo add kcp https://kcp-dev.github.io/helm-charts
66-
helm repo update
67-
68-
helm install \
69-
--wait \
70-
--namespace kcp \
71-
--create-namespace \
72-
--values hack/ci/testdata/kcp-kind-values.yaml \
73-
kcp-e2e kcp/kcp
50+
if ! retry_linear 3 20 kubectl --kubeconfig "$KCP_KUBECONFIG" get logicalcluster; then
51+
echodate "kcp never became ready."
52+
exit 1
53+
fi
7454

7555
# time to run the tests
76-
echo "Running e2e tests…"
56+
echodate "Running e2e tests…"
7757
(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...)
7858

79-
echo "Done. :-)"
59+
echodate "Done. :-)"

hack/lib.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ retry() {
3636
# Works only with bash but doesn't fail on other shells
3737
start_time=$(date +%s)
3838
set +e
39-
actual_retry $@
39+
# We use an extra wrapping to write junit and have a timer
40+
retry_backoff $@
4041
rc=$?
4142
set -e
4243
elapsed_time=$(($(date +%s) - $start_time))
4344
write_junit "$rc" "$elapsed_time"
4445
return $rc
4546
}
4647

47-
# We use an extra wrapping to write junit and have a timer
48-
actual_retry() {
48+
retry_backoff() {
4949
retries=$1
5050
shift
5151

@@ -66,9 +66,33 @@ actual_retry() {
6666
return 0
6767
}
6868

69+
retry_linear() {
70+
delay=$1
71+
retries=$2
72+
shift
73+
shift
74+
75+
count=0
76+
until "$@"; do
77+
rc=$?
78+
count=$((count + 1))
79+
if [ $count -lt "$retries" ]; then
80+
echodate "[$count/$retries] Command returned $rc, retrying…"
81+
sleep $delay
82+
else
83+
echodate "Command returned $rc, no more retries left."
84+
return $rc
85+
fi
86+
done
87+
88+
echodate "Command succeeded."
89+
90+
return 0
91+
}
92+
6993
echodate() {
7094
# do not use -Is to keep this compatible with macOS
71-
echo "[$(date +%Y-%m-%dT%H:%M:%S%:z)]" "$@"
95+
echo "[$(date +%Y-%m-%dT%H:%M:%S%:z)]" "$@" > /dev/stderr
7296
}
7397

7498
write_junit() {

0 commit comments

Comments
 (0)