Skip to content

Commit 6229262

Browse files
authored
Merge pull request #4618 from kersten/feat/use-custom-kind-in-e2e-test
✨ (go/v4) : Improve Kind Integration: Ensure Custom Kind Binary is Used in E2E Tests
2 parents 0e66e83 + 651ce94 commit 6229262

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
@@ -87,7 +87,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8787

8888
.PHONY: test-e2e
8989
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
90-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
90+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
9191
$(MAKE) cleanup-test-e2e
9292

9393
.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
@@ -83,7 +83,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8383

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

8989
.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
@@ -87,7 +87,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
8787

8888
.PHONY: test-e2e
8989
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
90-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
90+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
9191
$(MAKE) cleanup-test-e2e
9292

9393
.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
@@ -162,7 +162,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
162162
163163
.PHONY: test-e2e
164164
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
165-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
165+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
166166
$(MAKE) cleanup-test-e2e
167167
168168
.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"
@@ -287,24 +291,32 @@ func (t *TestContext) RemoveNamespaceLabelToEnforceRestricted() error {
287291

288292
// LoadImageToKindCluster loads a local docker image to the kind cluster
289293
func (t *TestContext) LoadImageToKindCluster() error {
290-
cluster := "kind"
294+
cluster := defaultKindCluster
291295
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
292296
cluster = v
293297
}
294298
kindOptions := []string{"load", "docker-image", t.ImageName, "--name", cluster}
295-
cmd := exec.Command("kind", kindOptions...)
299+
kindBinary := defaultKindBinary
300+
if v, ok := os.LookupEnv("KIND"); ok {
301+
kindBinary = v
302+
}
303+
cmd := exec.Command(kindBinary, kindOptions...)
296304
_, err := t.Run(cmd)
297305
return err
298306
}
299307

300308
// LoadImageToKindClusterWithName loads a local docker image with the name informed to the kind cluster
301309
func (t TestContext) LoadImageToKindClusterWithName(image string) error {
302-
cluster := "kind"
310+
cluster := defaultKindCluster
303311
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
304312
cluster = v
305313
}
306314
kindOptions := []string{"load", "docker-image", "--name", cluster, image}
307-
cmd := exec.Command("kind", kindOptions...)
315+
kindBinary := defaultKindCluster
316+
if v, ok := os.LookupEnv("KIND"); ok {
317+
kindBinary = v
318+
}
319+
cmd := exec.Command(kindBinary, kindOptions...)
308320
_, err := t.Run(cmd)
309321
return err
310322
}

0 commit comments

Comments
 (0)