Skip to content

Commit 256e9ff

Browse files
committed
add make test-e2e-with-kind
On-behalf-of: @SAP [email protected]
1 parent 04b0322 commit 256e9ff

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ go.work.sum
2727
# Downloaded and built binaries
2828
/_build/
2929
/_tools/
30+
31+
# e2e test logs and artifacts
32+
/.e2e-*

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ test: fmt vet ## Run tests.
6464
go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6565

6666
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
67-
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
67+
.PHONY: test-e2e # Run the e2e tests against a kind k8s instance that is already spun up.
6868
test-e2e:
6969
go test ./test/e2e/ -v
7070

71+
# Creates a kind cluster and runs the e2e tests in them. The kind cluster is destroyed after the tests.
72+
.PHONY: test-e2e-with-kind # Run the e2e tests against a temporary kind cluster.
73+
test-e2e-with-kind:
74+
@./hack/run-e2e-tests.sh
75+
7176
.PHONY: lint
7277
lint: golangci-lint ## Run golangci-lint linter.
7378
$(GOLANGCI_LINT) run --timeout 10m

hack/ci/run-e2e-tests.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ helm upgrade \
9898
kubectl apply --filename hack/ci/testdata/clusterissuer.yaml
9999

100100
echo "Running e2e tests…"
101-
(set -x; go test -tags e2e -timeout 2h -v ./test/e2e/...)
101+
102+
WHAT="${WHAT:-./test/e2e/...}"
103+
TEST_ARGS="${TEST_ARGS:--timeout 2h -v}"
104+
E2E_PARALLELISM=${E2E_PARALLELISM:-2}
105+
106+
(set -x; go test -tags e2e -p $E2E_PARALLELISM $TEST_ARGS "$WHAT")
102107

103108
echo "Done. :-)"

hack/run-e2e-tests.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-e2e}"
20+
DATA_DIR=".e2e-$KIND_CLUSTER_NAME"
21+
OPERATOR_PID=0
22+
23+
mkdir -p "$DATA_DIR"
24+
echo "Logs are stored in $DATA_DIR/."
25+
DATA_DIR="$(realpath "$DATA_DIR")"
26+
27+
# create a local kind cluster
28+
29+
export KUBECONFIG="$DATA_DIR/kind.kubeconfig"
30+
echo "Creating kind cluster $KIND_CLUSTER_NAME"
31+
kind create cluster --name "$KIND_CLUSTER_NAME"
32+
chmod 600 "$KUBECONFIG"
33+
34+
teardown_kind() {
35+
echo "Stopping kcp-operator…"
36+
kill -TERM $OPERATOR_PID
37+
wait $OPERATOR_PID
38+
39+
kind delete cluster --name "$KIND_CLUSTER_NAME"
40+
rm "$KUBECONFIG"
41+
}
42+
trap teardown_kind EXIT
43+
44+
echo "Kubeconfig is in $KUBECONFIG."
45+
46+
# deploying operator CRDs
47+
echo "Deploying operator CRDs…"
48+
kubectl apply --kustomize config/crd
49+
50+
# deploying cert-manager
51+
echo "Deploying cert-manager…"
52+
53+
helm repo add jetstack https://charts.jetstack.io --force-update
54+
helm repo update
55+
56+
helm upgrade \
57+
--install \
58+
--namespace cert-manager \
59+
--create-namespace \
60+
--version v1.18.2 \
61+
--set crds.enabled=true \
62+
--atomic \
63+
cert-manager jetstack/cert-manager
64+
65+
kubectl apply --filename hack/ci/testdata/clusterissuer.yaml
66+
67+
# start the operator locally
68+
echo "Starting kcp-operator…"
69+
_build/manager \
70+
-kubeconfig "$KUBECONFIG" \
71+
-zap-log-level debug \
72+
-zap-encoder console \
73+
-zap-time-encoding iso8601 \
74+
>"$DATA_DIR/kcp-operator.log" 2>&1 &
75+
OPERATOR_PID=$!
76+
echo "Running as process $OPERATOR_PID."
77+
78+
echo "Running e2e tests…"
79+
80+
WHAT="${WHAT:-./test/e2e/...}"
81+
TEST_ARGS="${TEST_ARGS:--timeout 2h -v}"
82+
E2E_PARALLELISM=${E2E_PARALLELISM:-2}
83+
84+
(set -x; go test -tags e2e -p $E2E_PARALLELISM $TEST_ARGS "$WHAT")

0 commit comments

Comments
 (0)