Skip to content

Commit 234c358

Browse files
author
Per Goncalves da Silva
committed
pin setup_envtest environment to client-go version
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
1 parent 9193d71 commit 234c358

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

.github/workflows/unit.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
name: unit
2-
env:
3-
K8S_VERSION: 1.19.2
42
on:
53
push:
64
branches:
@@ -20,9 +18,5 @@ jobs:
2018
- uses: actions/setup-go@v5
2119
with:
2220
go-version-file: "go.mod"
23-
- name: Envtest setup
24-
run: |
25-
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
26-
setup-envtest use ${K8S_VERSION}
2721
- name: Run unit tests
28-
run: KUBEBUILDER_ASSETS=$(setup-envtest use -i -p path ${K8S_VERSION}) make unit
22+
run: make unit

Makefile

+14-23
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export GO111MODULE=on
2828
YQ_INTERNAL := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v3/
2929
HELM := go run $(MOD_FLAGS) ./vendor/helm.sh/helm/v3/cmd/helm
3030
KIND := go run $(MOD_FLAGS) ./vendor/sigs.k8s.io/kind
31-
KUBEBUILDER_ASSETS := $(or $(or $(KUBEBUILDER_ASSETS),$(dir $(shell command -v kubebuilder))),/usr/local/kubebuilder/bin)
32-
export KUBEBUILDER_ASSETS
3331
GO := GO111MODULE=on GOFLAGS="$(MOD_FLAGS)" go
3432
GINKGO := $(GO) run github.com/onsi/ginkgo/v2/ginkgo
3533
BINDATA := $(GO) run github.com/go-bindata/go-bindata/v3/go-bindata
@@ -41,12 +39,17 @@ else
4139
ARCH := amd64
4240
endif
4341

42+
# Track the minor version of kubernetes we are building against by looking at the client-go dependency version
43+
# For example, a client-go version of v0.28.5 will map to kube version 1.28
44+
KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/')
45+
46+
# Unit test against the latest available version for the minor version of kubernetes we are building against e.g. 1.30.x
47+
ENVTEST_KUBE_VERSION ?= $(KUBE_MINOR).x
48+
49+
# Node image tags are in the format x.y.z, so pin kind node image version to x.y.0
50+
# As patch releases and node images are not guaranteed to be available when a new version of the kube apis is released
51+
KIND_NODE_VERSION ?= $(KUBE_MINOR).0
4452
KIND_CLUSTER_NAME ?= kind-olmv0
45-
# Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - no v1.28, v1.29, etc.)
46-
# The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
47-
# and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
48-
# will map to a KIND_NODE_VERSION of 1.28.0
49-
KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.0/')
5053
KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION)
5154

5255
# Phony prerequisite for targets that rely on the go build cache to determine staleness.
@@ -64,24 +67,12 @@ vet:
6467
all: test build
6568

6669
test: clean cover.out
67-
68-
unit: kubebuilder
70+
.PHONY: unit
71+
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -p path $(ENVTEST_KUBE_VERSION))
72+
unit:
73+
@echo "Running unit tests with setup_envtest for kubernetes $(ENVTEST_KUBE_VERSION)"
6974
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -tags "json1" -race -count=1 ./pkg/... ./test/e2e/split/...
7075

71-
# Ensure kubectl installed before continuing
72-
KUBEBUILDER_ASSETS_ERR := not detected in $(KUBEBUILDER_ASSETS), to override the assets path set the KUBEBUILDER_ASSETS environment variable, for install instructions see https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest
73-
KUBECTL_ASSETS_ERR := kubectl not detected.
74-
kubebuilder:
75-
ifeq (, $(shell which kubectl))
76-
$(error $(KUBECTL_ASSETS_ERR))
77-
endif
78-
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/etcd))
79-
$(error etcd $(KUBEBUILDER_ASSETS_ERR))
80-
endif
81-
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kube-apiserver))
82-
$(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
83-
endif
84-
8576
cover.out:
8677
go test $(MOD_FLAGS) -tags "json1" -race -coverprofile=cover.out -covermode=atomic \
8778
-coverpkg ./pkg/controller/... ./pkg/...

0 commit comments

Comments
 (0)