Skip to content

Commit 51fe16f

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 3f4d5f4 commit 51fe16f

File tree

16 files changed

+92
-51
lines changed

16 files changed

+92
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
7979
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
8080
exit 1; \
8181
}
82-
go test ./test/e2e/ -v -ginkgo.v
82+
KIND=$(KIND) go test ./test/e2e/ -v -ginkgo.v
8383

8484
.PHONY: lint
8585
lint: golangci-lint ## Run golangci-lint linter

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ 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+
defaultKindCluster = "kind"
3134
prometheusOperatorVersion = "v0.77.1"
3235
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3336
"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"
3737
)
3838

3939
func warnError(err error) {
@@ -167,12 +167,16 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := defaultKindCluster
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}
174174
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
175+
kindBinary := defaultKindCluster
176+
if v, ok := os.LookupEnv("KIND"); ok {
177+
kindBinary = v
178+
}
179+
cmd := exec.Command(kindBinary, kindOptions...)
176180
_, err := Run(cmd)
177181
return err
178182
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
7575
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
7676
exit 1; \
7777
}
78-
go test ./test/e2e/ -v -ginkgo.v
78+
KIND=$(KIND) go test ./test/e2e/ -v -ginkgo.v
7979

8080
.PHONY: lint
8181
lint: golangci-lint ## Run golangci-lint linter

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ 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+
defaultKindCluster = "kind"
3134
prometheusOperatorVersion = "v0.77.1"
3235
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3336
"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"
3737
)
3838

3939
func warnError(err error) {
@@ -167,12 +167,16 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := defaultKindCluster
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}
174174
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
175+
kindBinary := defaultKindCluster
176+
if v, ok := os.LookupEnv("KIND"); ok {
177+
kindBinary = v
178+
}
179+
cmd := exec.Command(kindBinary, kindOptions...)
176180
_, err := Run(cmd)
177181
return err
178182
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
7979
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
8080
exit 1; \
8181
}
82-
go test ./test/e2e/ -v -ginkgo.v
82+
KIND=$(KIND) go test ./test/e2e/ -v -ginkgo.v
8383

8484
.PHONY: lint
8585
lint: golangci-lint ## Run golangci-lint linter

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ 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+
defaultKindCluster = "kind"
3134
prometheusOperatorVersion = "v0.77.1"
3235
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3336
"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"
3737
)
3838

3939
func warnError(err error) {
@@ -167,12 +167,16 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := defaultKindCluster
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}
174174
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
175-
cmd := exec.Command("kind", kindOptions...)
175+
kindBinary := defaultKindCluster
176+
if v, ok := os.LookupEnv("KIND"); ok {
177+
kindBinary = v
178+
}
179+
cmd := exec.Command(kindBinary, kindOptions...)
176180
_, err := Run(cmd)
177181
return err
178182
}

docs/book/src/reference/envtest.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ Check the following example of how you can implement the above operations:
258258
259259
```go
260260
const (
261+
certmanagerVersion = "v1.5.3"
262+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
263+
defaultKindCluster = "kind"
261264
prometheusOperatorVersion = "0.51"
262265
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" + "prometheus-operator/release-%s/bundle.yaml"
263-
certmanagerVersion = "v1.5.3"
264-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
265266
)
266267
267268
func warnError(err error) {
@@ -315,13 +316,16 @@ func InstallCertManager() error {
315316
316317
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
317318
func LoadImageToKindClusterWithName(name string) error {
318-
cluster := "kind"
319+
cluster := defaultKindCluster
319320
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
320321
cluster = v
321322
}
322-
323323
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
324-
cmd := exec.Command("kind", kindOptions...)
324+
kindBinary := defaultKindCluster
325+
if v, ok := os.LookupEnv("KIND"); ok {
326+
kindBinary = v
327+
}
328+
cmd := exec.Command(kindBinary, kindOptions...)
325329
_, err := Run(cmd)
326330
return err
327331
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
154154
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
155155
exit 1; \
156156
}
157-
go test ./test/e2e/ -v -ginkgo.v
157+
KIND=$(KIND) go test ./test/e2e/ -v -ginkgo.v
158158
159159
.PHONY: lint
160160
lint: golangci-lint ## Run golangci-lint linter

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ import (
5555
)
5656
5757
const (
58+
certmanagerVersion = "v1.16.3"
59+
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
60+
defaultKindCluster = "kind"
5861
prometheusOperatorVersion = "v0.77.1"
5962
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
6063
"releases/download/%s/bundle.yaml"
61-
62-
certmanagerVersion = "v1.16.3"
63-
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
6464
)
6565
6666
func warnError(err error) {
@@ -194,12 +194,16 @@ func IsCertManagerCRDsInstalled() bool {
194194
195195
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
196196
func LoadImageToKindClusterWithName(name string) error {
197-
cluster := "kind"
197+
cluster := defaultKindCluster
198198
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
199199
cluster = v
200200
}
201201
kindOptions := []string{"load", "docker-image", name, "--name", cluster}
202-
cmd := exec.Command("kind", kindOptions...)
202+
kindBinary := defaultKindCluster
203+
if v, ok := os.LookupEnv("KIND"); ok {
204+
kindBinary = v
205+
}
206+
cmd := exec.Command(kindBinary, kindOptions...)
203207
_, err := Run(cmd)
204208
return err
205209
}

test/e2e/utils/test_context.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
const (
3434
certmanagerVersion = "v1.16.3"
3535
certmanagerURLTmpl = "https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml"
36+
defaultKindCluster = "kind"
3637
prometheusOperatorVersion = "v0.77.1"
3738
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3839
"releases/download/%s/bundle.yaml"
@@ -269,24 +270,32 @@ func (t *TestContext) RemoveNamespaceLabelToEnforceRestricted() error {
269270

270271
// LoadImageToKindCluster loads a local docker image to the kind cluster
271272
func (t *TestContext) LoadImageToKindCluster() error {
272-
cluster := "kind"
273+
cluster := defaultKindCluster
273274
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
274275
cluster = v
275276
}
276277
kindOptions := []string{"load", "docker-image", t.ImageName, "--name", cluster}
277-
cmd := exec.Command("kind", kindOptions...)
278+
kindBinary := defaultKindCluster
279+
if v, ok := os.LookupEnv("KIND"); ok {
280+
kindBinary = v
281+
}
282+
cmd := exec.Command(kindBinary, kindOptions...)
278283
_, err := t.Run(cmd)
279284
return err
280285
}
281286

282287
// LoadImageToKindClusterWithName loads a local docker image with the name informed to the kind cluster
283288
func (t TestContext) LoadImageToKindClusterWithName(image string) error {
284-
cluster := "kind"
289+
cluster := defaultKindCluster
285290
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
286291
cluster = v
287292
}
288293
kindOptions := []string{"load", "docker-image", "--name", cluster, image}
289-
cmd := exec.Command("kind", kindOptions...)
294+
kindBinary := defaultKindCluster
295+
if v, ok := os.LookupEnv("KIND"); ok {
296+
kindBinary = v
297+
}
298+
cmd := exec.Command(kindBinary, kindOptions...)
290299
_, err := t.Run(cmd)
291300
return err
292301
}

0 commit comments

Comments
 (0)