1- IMG ?= controller:latest
1+ IMG ?= image-prefetch:dev
22ENVTEST_K8S_VERSION = 1.31.0
33
44# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
@@ -28,6 +28,22 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
2828generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
2929 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
3030
31+ # refer to https://github.com/statnett/image-scanner-operator/pull/668/files
32+ GO_MODULE = $(shell go list -m)
33+ API_DIRS = $(shell find api -mindepth 1 -type d | sed "s|^|$(shell go list -m) /|" | paste -sd " " )
34+ .PHONY : k8s-client-gen
35+ k8s-client-gen : applyconfiguration-gen models-schema
36+ @echo " generating"
37+ $(MODELS_SCHEMA ) > /tmp/schema.json
38+ rm -rf internal/client/applyconfigurations
39+ $(APPLYCONFIGURATION_GEN ) \
40+ --go-header-file hack/boilerplate.go.txt \
41+ --output-dir internal/applyconfigurations \
42+ --output-pkg $(GO_MODULE)/internal/applyconfigurations \
43+ --openapi-schema /tmp/schema.json \
44+ $(API_DIRS)
45+ rm -f /tmp/schema.json
46+
3147.PHONY : fmt
3248fmt : # # Run go fmt against code.
3349 go fmt ./...
@@ -37,8 +53,8 @@ vet: ## Run go vet against code.
3753 go vet ./...
3854
3955.PHONY : test
40- test : manifests generate fmt vet envtest # # Run tests.
41- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$( go list ./... | grep -v / e2e) -coverprofile cover.out
56+ test : manifests generate fmt vet envtest ginkgo # # Run tests.
57+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " $( GINKGO ) run --skip-file e2e. * -r - -coverprofile cover.out
4258
4359# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
4460.PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
@@ -111,12 +127,18 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
111127CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
112128ENVTEST ?= $(LOCALBIN ) /setup-envtest
113129GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
130+ GINKGO = $(LOCALBIN ) /ginkgo
131+ APPLYCONFIGURATION_GEN = $(LOCALBIN ) /applyconfiguration-gen
132+ MODELS_SCHEMA = $(LOCALBIN ) /models-schema
114133
115134# # Tool Versions
116135KUSTOMIZE_VERSION ?= v5.6.0
117136CONTROLLER_TOOLS_VERSION ?= v0.17.2
118137ENVTEST_VERSION ?= release-0.20
119138GOLANGCI_LINT_VERSION ?= v1.64.5
139+ GINKGO_VERSION ?= v2.1.4
140+ CODE_GENERATOR_VERSION ?= v0.31.1
141+ MODELS_SCHEMA_VERSION ?= v1.31.1
120142
121143.PHONY : kustomize
122144kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
@@ -138,6 +160,26 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
138160$(GOLANGCI_LINT ) : $(LOCALBIN )
139161 $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
140162
163+ .PHONY : ginkgo
164+ ginkgo : $(GINKGO ) # # Download ginkgo locally if necessary.
165+ $(GINKGO ) : $(LOCALBIN )
166+ $(call go-install-tool,$(GINKGO ) ,github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION ) )
167+
168+ .PHONY : models-schema # # Download models-schema locally if necessary.
169+ models-schema : $(LOCALBIN )
170+ test -s $(LOCALBIN ) /models-schema || \
171+ ( \
172+ mkdir -p /tmp/work-models-schema/pkg/generated/openapi/cmd/models-schema && \
173+ curl -sSfL https://github.com/kubernetes/kubernetes/archive/$(MODELS_SCHEMA_VERSION ) .tar.gz | tar -C /tmp/work-models-schema -xzf - --strip-components=1 && \
174+ cd /tmp/work-models-schema/pkg/generated/openapi/cmd/models-schema && \
175+ GOBIN=$(LOCALBIN ) go install \
176+ )
177+
178+ .PHONY : applyconfiguration-gen # # Download applyconfiguration-gen locally if necessary.
179+ applyconfiguration-gen : $(APPLYCONFIGURATION_GEN ) # # Download applyconfiguration-gen locally if necessary.
180+ $(APPLYCONFIGURATION_GEN ) : $(LOCALBIN )
181+ $(call go-install-tool,$(APPLYCONFIGURATION_GEN ) ,k8s.io/code-generator/cmd/applyconfiguration-gen,$(CODE_GENERATOR_VERSION ) )
182+
141183# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
142184# $1 - target path with name of binary
143185# $2 - package url which can be installed
0 commit comments