Skip to content

Commit 9a121a1

Browse files
committed
test/e2e: export KIND_CLUSTER so local tests get correct cluster name
Signed-off-by: Eric Stroczynski <[email protected]>
1 parent 2018a4f commit 9a121a1

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

test/e2e/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
source "$(dirname "$0")/../common.sh"
1818
source "$(dirname "$0")/setup.sh"
1919

20-
kind_cluster="kind"
21-
create_cluster ${KIND_K8S_VERSION} $kind_cluster
20+
export KIND_CLUSTER="kind"
21+
create_cluster ${KIND_K8S_VERSION}
2222
trap delete_cluster EXIT
2323

2424
test_cluster

test/e2e/local.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
source "$(dirname "$0")/../common.sh"
1818
source "$(dirname "$0")/setup.sh"
1919

20-
kind_cluster=local-kubebuilder-e2e
21-
create_cluster ${KIND_K8S_VERSION:-v1.18.0} $kind_cluster
20+
export KIND_CLUSTER="local-kubebuilder-e2e"
21+
create_cluster ${KIND_K8S_VERSION:-v1.18.0}
2222
if [ -z "${SKIP_KIND_CLEANUP:-}" ]; then
23-
trap delete_cluster EXIT
23+
trap delete_cluster EXIT
2424
fi
2525

26-
kind export kubeconfig --kubeconfig $tmp_root/kubeconfig --name $kind_cluster
26+
kind export kubeconfig --kubeconfig $tmp_root/kubeconfig --name $KIND_CLUSTER
2727
export KUBECONFIG=$tmp_root/kubeconfig
2828

2929
test_cluster -v -ginkgo.v

test/e2e/setup.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,32 @@ export PATH=$kb_root_dir/bin:$PATH
1919
fetch_tools
2020
install_kind
2121

22-
# Creates a kind cluster given a k8s version and a cluster name.
22+
# Creates a named kind cluster given a k8s version.
23+
# The KIND_CLUSTER variable defines the cluster name and
24+
# is expected to be defined in the calling environment.
2325
#
2426
# Usage:
2527
#
26-
# create_cluster <k8s version> <kind cluster name>
28+
# export KIND_CLUSTER=<kind cluster name>
29+
# create_cluster <k8s version>
2730
function create_cluster {
28-
if ! kind get clusters | grep -q $2 ; then
29-
kind create cluster -v 4 --name $2 --retain --wait=1m --config $(dirname "$0")/kind-config.yaml --image=kindest/node:$1
31+
: ${KIND_CLUSTER:?"KIND_CLUSTER must be set"}
32+
if ! kind get clusters | grep -q $KIND_CLUSTER ; then
33+
kind create cluster -v 4 --name $KIND_CLUSTER --retain --wait=1m --config $(dirname "$0")/kind-config.yaml --image=kindest/node:$1
3034
fi
3135
}
3236

33-
# Deletes a kind cluster by cluster name. The kind cluster needs to be defined as a variable instead of an argument
34-
# so that this function can be used with `trap`
37+
# Deletes a kind cluster by cluster name.
38+
# The KIND_CLUSTER variable defines the cluster name and
39+
# is expected to be defined in the calling environment.
3540
#
3641
# Usage:
3742
#
38-
# kind_cluster=<kind cluster name>
43+
# export KIND_CLUSTER=<kind cluster name>
3944
# delete_cluster
4045
function delete_cluster {
41-
kind delete cluster --name $kind_cluster
46+
: ${KIND_CLUSTER:?"KIND_CLUSTER must be set"}
47+
kind delete cluster --name $KIND_CLUSTER
4248
}
4349

4450
function test_cluster {

0 commit comments

Comments
 (0)