Skip to content

Commit b35bc2c

Browse files
committed
test: upgrade kind, make the image configurable and fix help make target
Signed-off-by: Peter Wilcsinszky <[email protected]>
1 parent 527fd5a commit b35bc2c

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ VERSION := $(shell git describe --abbrev=0 --tags)
2323

2424
E2E_TEST_TIMEOUT ?= 20m
2525

26-
2726
CONTROLLER_GEN = ${BIN}/controller-gen
2827
CONTROLLER_GEN_VERSION = v0.6.0
2928

@@ -35,7 +34,8 @@ GOLANGCI_LINT := ${BIN}/golangci-lint
3534
GOLANGCI_LINT_VERSION := v1.51.2
3635

3736
KIND := ${BIN}/kind
38-
KIND_VERSION := v0.11.1
37+
KIND_VERSION := v0.19.0
38+
KIND_IMAGE := kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff
3939

4040
KUBEBUILDER := ${BIN}/kubebuilder
4141
KUBEBUILDER_VERSION = v3.1.0
@@ -99,10 +99,6 @@ generate: ${CONTROLLER_GEN} tidy ## Generate code
9999
cd pkg/sdk && $(CONTROLLER_GEN) object:headerFile=./../../hack/boilerplate.go.txt paths=./resourcebuilder/...
100100
cd pkg/sdk && go generate ./static
101101

102-
.PHONY: help
103-
help: ## Show this help message
104-
@grep -h -E '^[a-zA-Z0-9%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
105-
106102
.PHONY: install
107103
install: manifests ## Install CRDs into the cluster in ~/.kube/config
108104
kubectl create -f config/crd/bases || kubectl replace -f config/crd/bases
@@ -153,7 +149,12 @@ test: generate fmt vet manifests ${ENVTEST_BINARY_ASSETS} ${KUBEBUILDER} ## Run
153149

154150
.PHONY: test-e2e
155151
test-e2e: ${KIND} docker-build generate fmt vet manifests stern ## Run E2E tests
156-
cd e2e && LOGGING_OPERATOR_IMAGE="${IMG}" PROJECT_DIR="$(PWD)" go test -v -timeout ${E2E_TEST_TIMEOUT} ./...
152+
cd e2e && \
153+
LOGGING_OPERATOR_IMAGE="${IMG}" \
154+
KIND_PATH="$(KIND)" \
155+
KIND_IMAGE="$(KIND_IMAGE)" \
156+
PROJECT_DIR="$(PWD)" \
157+
go test -v -timeout ${E2E_TEST_TIMEOUT} ./...
157158

158159
.PHONY: tidy
159160
tidy: ## Tidy Go modules
@@ -239,3 +240,9 @@ find ${BIN} -name '$(notdir ${IMPORT_PATH})_*' -exec rm {} +
239240
GOBIN=${BIN} go install ${IMPORT_PATH}@${VERSION}
240241
mv ${BIN}/$(notdir ${IMPORT_PATH}) $@
241242
endef
243+
244+
# Self-documenting Makefile
245+
.DEFAULT_GOAL = help
246+
.PHONY: help
247+
help: ## Show this help
248+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

e2e/common/cluster.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ func DeleteTestCluster(clusterName string) error {
109109
}
110110

111111
func CmdEnv(cmd *exec.Cmd, c Cluster) *exec.Cmd {
112-
cmd.Env = []string{
113-
fmt.Sprintf("KUBECONFIG=%s", c.KubeConfigFilePath()),
114-
}
112+
cmd.Env = append(os.Environ(), fmt.Sprintf("KUBECONFIG=%s", c.KubeConfigFilePath()))
115113
cmd.Stderr = os.Stderr
116114
return cmd
117115
}

e2e/common/kind/commands.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,31 @@
1515
package kind
1616

1717
import (
18+
"fmt"
19+
"os"
1820
"os/exec"
1921
"strings"
2022
)
2123

22-
const CommandName = "kind"
24+
var KindPath string
25+
var KindImage string
26+
27+
func init() {
28+
KindPath = os.Getenv("KIND_PATH")
29+
if KindPath == "" {
30+
fmt.Fprintln(os.Stderr, "KIND_PATH need to be set")
31+
os.Exit(1)
32+
}
33+
KindImage = os.Getenv("KIND_IMAGE")
34+
}
2335

2436
func CreateCluster(options CreateClusterOptions) error {
2537
args := []string{"create", "cluster"}
38+
if KindImage != "" && options.Image == "" {
39+
options.Image = KindImage
40+
}
2641
args = options.AppendToArgs(args)
27-
_, err := exec.Command(CommandName, args...).Output()
42+
_, err := exec.Command(KindPath, args...).Output()
2843
return err
2944
}
3045

@@ -64,7 +79,7 @@ func (options CreateClusterOptions) AppendToArgs(args []string) []string {
6479
func DeleteCluster(options DeleteClusterOptions) error {
6580
args := []string{"delete", "cluster"}
6681
args = options.AppendToArgs(args)
67-
return exec.Command(CommandName, args...).Run()
82+
return exec.Command(KindPath, args...).Run()
6883
}
6984

7085
type DeleteClusterOptions struct {
@@ -87,7 +102,7 @@ func (options DeleteClusterOptions) AppendToArgs(args []string) []string {
87102
func GetKubeconfig(options GetKubeconfigOptions) ([]byte, error) {
88103
args := []string{"get", "kubeconfig"}
89104
args = options.AppendToArgs(args)
90-
return exec.Command(CommandName, args...).Output()
105+
return exec.Command(KindPath, args...).Output()
91106
}
92107

93108
type GetKubeconfigOptions struct {
@@ -115,7 +130,7 @@ func LoadDockerImage(images []string, options LoadDockerImageOptions) error {
115130
args := []string{"load", "docker-image"}
116131
args = options.AppendToArgs(args)
117132
args = append(args, images...)
118-
_, err := exec.Command(CommandName, args...).Output()
133+
_, err := exec.Command(KindPath, args...).Output()
119134
return err
120135
}
121136

0 commit comments

Comments
 (0)