Skip to content

Commit 651ce94

Browse files
committed
feat(e2e): allow custom kind binary in e2e tests
add support for using a custom kind binary by reading from the KIND environment variable. This allows flexibility in testing environments where a different kind binary might be needed. The default behavior remains unchanged, using "kind" if no environment variable is set.
1 parent 4ce8307 commit 651ce94

File tree

16 files changed

+121
-53
lines changed

16 files changed

+121
-53
lines changed

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8181

8282
.PHONY: test-e2e
8383
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
84+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
8585
$(MAKE) cleanup-test-e2e
8686

8787
.PHONY: cleanup-test-e2e

docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ import (
2828
)
2929

3030
const (
31+
certmanagerVersion = "v1.16.3"
32+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
33+
34+
defaultKindBinary = "kind"
35+
defaultKindCluster = "kind"
36+
3137
prometheusOperatorVersion = "v0.77.1"
3238
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3339
"releases/download/%s/bundle.yaml"
34-
35-
certmanagerVersion = "v1.16.3"
36-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
3740
)
3841

3942
func warnError(err error) {
@@ -167,12 +170,16 @@ func IsCertManagerCRDsInstalled() bool {
167170

168171
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169172
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
173+
cluster := defaultKindCluster
171174
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172175
cluster = v
173176
}
174177
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
178+
kindBinary := defaultKindBinary
179+
if v, ok := os.LookupEnv("KIND"); ok {
180+
kindBinary = v
181+
}
182+
cmd := exec.Command(kindBinary, kindOptions...)
176183
_, err := Run(cmd)
177184
return err
178185
}

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7777

7878
.PHONY: test-e2e
7979
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
80+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
8181
$(MAKE) cleanup-test-e2e
8282

8383
.PHONY: cleanup-test-e2e

docs/book/src/getting-started/testdata/project/test/utils/utils.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ import (
2828
)
2929

3030
const (
31+
certmanagerVersion = "v1.16.3"
32+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
33+
34+
defaultKindBinary = "kind"
35+
defaultKindCluster = "kind"
36+
3137
prometheusOperatorVersion = "v0.77.1"
3238
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3339
"releases/download/%s/bundle.yaml"
34-
35-
certmanagerVersion = "v1.16.3"
36-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
3740
)
3841

3942
func warnError(err error) {
@@ -167,12 +170,16 @@ func IsCertManagerCRDsInstalled() bool {
167170

168171
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169172
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
173+
cluster := defaultKindCluster
171174
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172175
cluster = v
173176
}
174177
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
178+
kindBinary := defaultKindBinary
179+
if v, ok := os.LookupEnv("KIND"); ok {
180+
kindBinary = v
181+
}
182+
cmd := exec.Command(kindBinary, kindOptions...)
176183
_, err := Run(cmd)
177184
return err
178185
}

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8181

8282
.PHONY: test-e2e
8383
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
84+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
8585
$(MAKE) cleanup-test-e2e
8686

8787
.PHONY: cleanup-test-e2e

docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ import (
2828
)
2929

3030
const (
31+
certmanagerVersion = "v1.16.3"
32+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
33+
34+
defaultKindBinary = "kind"
35+
defaultKindCluster = "kind"
36+
3137
prometheusOperatorVersion = "v0.77.1"
3238
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3339
"releases/download/%s/bundle.yaml"
34-
35-
certmanagerVersion = "v1.16.3"
36-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
3740
)
3841

3942
func warnError(err error) {
@@ -167,12 +170,16 @@ func IsCertManagerCRDsInstalled() bool {
167170

168171
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169172
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
173+
cluster := defaultKindCluster
171174
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172175
cluster = v
173176
}
174177
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
178+
kindBinary := defaultKindBinary
179+
if v, ok := os.LookupEnv("KIND"); ok {
180+
kindBinary = v
181+
}
182+
cmd := exec.Command(kindBinary, kindOptions...)
176183
_, err := Run(cmd)
177184
return err
178185
}

docs/book/src/reference/envtest.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,14 @@ Check the following example of how you can implement the above operations:
258258
259259
```go
260260
const (
261-
prometheusOperatorVersion = "0.51"
262-
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" + "prometheus-operator/release-%s/bundle.yaml"
263261
certmanagerVersion = "v1.5.3"
264262
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
263+
264+
defaultKindCluster = "kind"
265+
defaultKindBinary = "kind"
266+
267+
prometheusOperatorVersion = "0.51"
268+
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" + "prometheus-operator/release-%s/bundle.yaml"
265269
)
266270
267271
func warnError(err error) {
@@ -315,13 +319,16 @@ func InstallCertManager() error {
315319
316320
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
317321
func LoadImageToKindClusterWithName(name string) error {
318-
cluster := "kind"
322+
cluster := defaultKindCluster
319323
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
320324
cluster = v
321325
}
322-
323326
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
324-
cmd := exec.Command("kind", kindOptions...)
327+
kindBinary := defaultKindBinary
328+
if v, ok := os.LookupEnv("KIND"); ok {
329+
kindBinary = v
330+
}
331+
cmd := exec.Command(kindBinary, kindOptions...)
325332
_, err := Run(cmd)
326333
return err
327334
}

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
156156
157157
.PHONY: test-e2e
158158
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
159-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
159+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
160160
$(MAKE) cleanup-test-e2e
161161
162162
.PHONY: cleanup-test-e2e

pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ import (
5656
)
5757
5858
const (
59+
certmanagerVersion = "v1.16.3"
60+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
61+
62+
defaultKindBinary = "kind"
63+
defaultKindCluster = "kind"
64+
5965
prometheusOperatorVersion = "v0.77.1"
6066
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
6167
"releases/download/%s/bundle.yaml"
62-
63-
certmanagerVersion = "v1.16.3"
64-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
6568
)
6669
6770
func warnError(err error) {
@@ -195,12 +198,16 @@ func IsCertManagerCRDsInstalled() bool {
195198
196199
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
197200
func LoadImageToKindClusterWithName(name string) error {
198-
cluster := "kind"
201+
cluster := defaultKindCluster
199202
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
200203
cluster = v
201204
}
202205
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
203-
cmd := exec.Command("kind", kindOptions...)
206+
kindBinary := defaultKindBinary
207+
if v, ok := os.LookupEnv("KIND"); ok {
208+
kindBinary = v
209+
}
210+
cmd := exec.Command(kindBinary, kindOptions...)
204211
_, err := Run(cmd)
205212
return err
206213
}

test/e2e/utils/test_context.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ import (
3232
)
3333

3434
const (
35-
certmanagerVersion = "v1.16.3"
36-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
35+
certmanagerVersion = "v1.16.3"
36+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
37+
38+
defaultKindCluster = "kind"
39+
defaultKindBinary = "kind"
40+
3741
prometheusOperatorVersion = "v0.77.1"
3842
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3943
"releases/download/%s/bundle.yaml"
@@ -273,24 +277,32 @@ func (t *TestContext) RemoveNamespaceLabelToEnforceRestricted() error {
273277

274278
// LoadImageToKindCluster loads a local docker image to the kind cluster
275279
func (t *TestContext) LoadImageToKindCluster() error {
276-
cluster := "kind"
280+
cluster := defaultKindCluster
277281
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
278282
cluster = v
279283
}
280284
kindOptions := []string{"load", "docker-image", t.ImageName, "--name", cluster}
281-
cmd := exec.Command("kind", kindOptions...)
285+
kindBinary := defaultKindBinary
286+
if v, ok := os.LookupEnv("KIND"); ok {
287+
kindBinary = v
288+
}
289+
cmd := exec.Command(kindBinary, kindOptions...)
282290
_, err := t.Run(cmd)
283291
return err
284292
}
285293

286294
// LoadImageToKindClusterWithName loads a local docker image with the name informed to the kind cluster
287295
func (t TestContext) LoadImageToKindClusterWithName(image string) error {
288-
cluster := "kind"
296+
cluster := defaultKindCluster
289297
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
290298
cluster = v
291299
}
292300
kindOptions := []string{"load", "docker-image", "--name", cluster, image}
293-
cmd := exec.Command("kind", kindOptions...)
301+
kindBinary := defaultKindCluster
302+
if v, ok := os.LookupEnv("KIND"); ok {
303+
kindBinary = v
304+
}
305+
cmd := exec.Command(kindBinary, kindOptions...)
294306
_, err := t.Run(cmd)
295307
return err
296308
}

0 commit comments

Comments
 (0)