From c0cb38bc36599237ef06207fbdd149c5d89de8da Mon Sep 17 00:00:00 2001 From: Oleg Kunitsyn <114359669+hiddenmarten@users.noreply.github.com> Date: Tue, 11 Jun 2024 19:56:40 +0200 Subject: [PATCH] [232] Create kind with accurate kubernetes version (#233) --- .github/workflows/make-test-e2e.yaml | 6 +++--- .github/workflows/make-test.yaml | 6 +++--- Makefile | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/make-test-e2e.yaml b/.github/workflows/make-test-e2e.yaml index 669ee2b..ccac6da 100644 --- a/.github/workflows/make-test-e2e.yaml +++ b/.github/workflows/make-test-e2e.yaml @@ -15,9 +15,9 @@ jobs: strategy: matrix: k8s: - - version: 1.28.3 + - version: v1.28.0 attribute: penultimate - - version: 1.29.3 + - version: v1.29.0 attribute: previous - version: default attribute: latest @@ -38,5 +38,5 @@ jobs: # For latest version use default from Makefile make test-e2e else - ENVTEST_K8S_VERSION=${{ matrix.k8s.version }} make test-e2e + K8S_VERSION=${{ matrix.k8s.version }} make test-e2e fi diff --git a/.github/workflows/make-test.yaml b/.github/workflows/make-test.yaml index 09c1594..8d58d1b 100644 --- a/.github/workflows/make-test.yaml +++ b/.github/workflows/make-test.yaml @@ -15,9 +15,9 @@ jobs: strategy: matrix: k8s: - - version: 1.28.3 + - version: v1.28.0 attribute: penultimate - - version: 1.29.3 + - version: v1.29.0 attribute: previous - version: default attribute: latest @@ -32,5 +32,5 @@ jobs: # For latest version use default from Makefile make test else - ENVTEST_K8S_VERSION=${{ matrix.k8s.version }} make test + K8S_VERSION=${{ matrix.k8s.version }} make test fi diff --git a/Makefile b/Makefile index 1197242..90df6e9 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ # Image URL to use all building/pushing image targets IMG ?= ghcr.io/aenix-io/etcd-operator:latest -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. +# K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. # renovate: datasource=github-tags depName=kubernetes/kubernetes -ENVTEST_K8S_VERSION ?= v1.30.0 -ENVTEST_K8S_VERSION_TRIMMED_V = $(subst v,,$(ENVTEST_K8S_VERSION)) +K8S_VERSION ?= v1.30.0 +K8S_VERSION_TRIMMED_V = $(subst v,,$(K8S_VERSION)) # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -74,9 +74,9 @@ mod-tidy: ## Run go mod tidy against code. .PHONY: test test: manifests generate fmt vet envtest ## Run tests. - echo "Check for kubernetes version $(ENVTEST_K8S_VERSION_TRIMMED_V) in $(ENVTEST)" - @$(ENVTEST) list | grep -q $(ENVTEST_K8S_VERSION_TRIMMED_V) - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION_TRIMMED_V) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out + echo "Check for kubernetes version $(K8S_VERSION_TRIMMED_V) in $(ENVTEST)" + @$(ENVTEST) list | grep -q $(K8S_VERSION_TRIMMED_V) + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(K8S_VERSION_TRIMMED_V) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors. .PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up. @@ -198,9 +198,13 @@ kind-load: docker-build kind ## Build and upload docker image to the local Kind $(KIND) load docker-image ${IMG} --name $(KIND_CLUSTER_NAME) .PHONY: kind-create -kind-create: kind ## Create kubernetes cluster using Kind. +kind-create: kind yq ## Create kubernetes cluster using Kind. @if ! $(KIND) get clusters | grep -q $(KIND_CLUSTER_NAME); then \ - $(KIND) create cluster --name $(KIND_CLUSTER_NAME); \ + $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image kindest/node:$(K8S_VERSION); \ + fi + @if ! $(CONTAINER_TOOL) container inspect $$($(KIND) get nodes) | $(YQ) e '.[0].Config.Image' | grep -q $(K8S_VERSION); then \ + $(KIND) delete cluster --name $(KIND_CLUSTER_NAME); \ + $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image kindest/node:$(K8S_VERSION); \ fi .PHONY: kind-delete