43
43
44
44
TESTARGS_DEFAULT := "-v"
45
45
export TESTARGS ?= $(TESTARGS_DEFAULT )
46
- BUNDLE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
46
+ BUNDLE_VERSION ?= $(shell cat ./internal/ version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
47
47
VERSION ?= $(BUNDLE_VERSION )
48
48
49
49
LOCAL_OS := $(shell uname)
@@ -161,24 +161,30 @@ LOCALBIN ?= $(shell pwd)/bin
161
161
$(LOCALBIN ) :
162
162
mkdir -p $(LOCALBIN )
163
163
164
- # # Tool Binaries
164
+ # # Local Tool Binaries
165
+ KUBECTL ?= kubectl
166
+ KIND ?= kind
167
+
168
+ # # Repo Tool Binaries
165
169
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
166
170
YQ ?= $(LOCALBIN ) /yq
167
171
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
168
172
OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
169
173
ENVTEST ?= $(LOCALBIN ) /setup-envtest
174
+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
170
175
171
176
# # Tool Versions
172
- KUSTOMIZE_VERSION ?= v5.4.3
177
+ KUSTOMIZE_VERSION ?= v5.7.0
173
178
CONTROLLER_TOOLS_VERSION ?= v0.17.2
174
179
OPERATOR_SDK_VERSION ?= v1.37.0
175
180
YQ_VERSION ?= v4.44.3
176
181
GO_VERSION ?= 1.24.1
177
182
178
- # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
183
+ # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
179
184
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
180
- # ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
185
+ # ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
181
186
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
187
+ GOLANGCI_LINT_VERSION ?= v1.63.4
182
188
183
189
# This pinned version of go has its version pinned to its name, so order of operations is inverted here.
184
190
GO ?= $(LOCALBIN ) /go$(GO_VERSION )
@@ -208,8 +214,7 @@ $(KUSTOMIZE): $(LOCALBIN) go
208
214
.PHONY : controller-gen
209
215
controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
210
216
$(CONTROLLER_GEN ) : $(LOCALBIN ) go
211
- test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
212
- GOSUMDB=sum.golang.org GOBIN=$(LOCALBIN ) $(GO ) install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
217
+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
213
218
214
219
.PHONY : operator-sdk
215
220
operator-sdk : $(OPERATOR_SDK ) # # Download operator-sdk locally if necessary. If wrong version is installed, it will be overwritten.
@@ -229,11 +234,7 @@ $(OPERATOR_SDK): $(LOCALBIN) go
229
234
.PHONY : yq
230
235
yq : $(YQ )
231
236
$(YQ ) : $(LOCALBIN ) go
232
- @if test -x $(LOCALBIN ) /yq && ! $(LOCALBIN ) /yq --version | grep -q $(YQ_VERSION ) ; then \
233
- echo " $( LOCALBIN) /yq version is not expected $( YQ_VERSION) . Removing it before installing." ; \
234
- rm -rf $(LOCALBIN ) /yq; \
235
- fi
236
- test -s $(LOCALBIN ) /yq || GOSUMDB=sum.golang.org GOBIN=$(LOCALBIN ) $(GO ) install github.com/mikefarah/yq/v4@$(YQ_VERSION )
237
+ $(call go-install-tool,$(YQ ) ,github.com/mikefarah/yq/v4,$(YQ_VERSION ) )
237
238
238
239
.PHONY : setup-envtest
239
240
setup-envtest : envtest # # Download the binaries required for ENVTEST in the local bin directory.
@@ -247,7 +248,12 @@ setup-envtest: envtest ## Download the binaries required for ENVTEST in the loca
247
248
.PHONY : envtest
248
249
envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
249
250
$(ENVTEST ) : $(LOCALBIN ) go
250
- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) $(GO ) install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION )
251
+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
252
+
253
+ .PHONY : golangci-lint
254
+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
255
+ $(GOLANGCI_LINT ) : $(LOCALBIN )
256
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
251
257
252
258
.PHONY : opm
253
259
OPM = ./bin/opm
@@ -311,24 +317,51 @@ vet: ## Run go vet against code.
311
317
312
318
.PHONY : test
313
319
test : manifests generate fmt vet envtest # # Run tests.
314
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " $(GO ) test ./... -coverprofile cover.out
320
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " $(GO ) test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
321
+
322
+ # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
323
+ # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
324
+ # CertManager is installed by default; skip with:
325
+ # - CERT_MANAGER_INSTALL_SKIP=true
326
+ .PHONY : test-e2e
327
+ test-e2e : go manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
328
+ @command -v $(KIND ) > /dev/null 2>&1 || { \
329
+ echo " Kind is not installed. Please install Kind manually." ; \
330
+ exit 1; \
331
+ }
332
+ @$(KIND ) get clusters | grep -q ' kind' || { \
333
+ echo " No Kind cluster is running. Please start a Kind cluster before running the e2e tests." ; \
334
+ exit 1; \
335
+ }
336
+ $(GO ) test ./test/e2e/ -v -ginkgo.v
315
337
316
338
.PHONY : update-version
317
339
update-version : manifests kustomize yq # # Update the Operator SemVer across the project.
318
340
./hack/update_operator_version
319
341
342
+ .PHONY : lint
343
+ lint : golangci-lint # # Run golangci-lint linter
344
+ $(GOLANGCI_LINT ) run
345
+
346
+ .PHONY : lint-fix
347
+ lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
348
+ $(GOLANGCI_LINT ) run --fix
349
+
350
+ .PHONY : lint-config
351
+ lint-config : golangci-lint # # Verify golangci-lint linter configuration
352
+ $(GOLANGCI_LINT ) config verify
320
353
321
354
# #@ Build
322
355
323
356
.PHONY : build
324
357
build : go manifests generate fmt vet # # Build manager binary.
325
358
@echo " Building the manager binary"
326
- @CGO_ENABLED=0 $(GO ) build -o build/_output/bin/manager main.go
359
+ @CGO_ENABLED=0 $(GO ) build -o build/_output/bin/manager cmd/ main.go
327
360
@strip $(STRIP_FLAGS ) build/_output/bin/manager
328
361
329
362
.PHONY : run
330
363
run : go manifests generate fmt vet # # Run a controller from your host.
331
- $(GO ) run ./main.go
364
+ $(GO ) run ./cmd/ main.go
332
365
333
366
.PHONY : licenses-dir
334
367
licenses-dir :
@@ -383,7 +416,7 @@ bundle-render: ## Render the bundle contents into the local FBC index.
383
416
TARGET_ARCH =$(LOCAL_ARCH )
384
417
build-image : $(GO ) $(CONFIG_DOCKER_TARGET ) licenses-dir # # Build the Operator manager image
385
418
@echo " Building manager binary for linux/$( TARGET_ARCH) "
386
- @CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH ) $(GO ) build -a -o build/_output/bin/manager main.go
419
+ @CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH ) $(GO ) build -a -o build/_output/bin/manager cmd/ main.go
387
420
@echo " Building manager image for linux/$( TARGET_ARCH) "
388
421
@DOCKER_BUILDKIT=1 $(CONTAINER_CLI ) build --platform=linux/$(TARGET_ARCH ) ${IMAGE_BUILD_OPTS} -t $(REGISTRY ) /$(IMG ) -$(TARGET_ARCH ) :$(GIT_COMMIT_ID ) -f ./Dockerfile .
389
422
@echo " Inspect built image $( REGISTRY) /$( IMG) -$( TARGET_ARCH) :$( GIT_COMMIT_ID) "
@@ -471,3 +504,19 @@ clean-all: clean-bin clean-dev clean-licenses ## Runs all cleanup targets.
471
504
472
505
473
506
.PHONY : all build run check install uninstall code-dev test test-e2e coverage images csv clean-all clean-bin clean-dev clean-licenses help
507
+
508
+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
509
+ # $1 - target path with name of binary
510
+ # $2 - package url which can be installed
511
+ # $3 - specific version of package
512
+ define go-install-tool
513
+ @[ -f "$(1 ) -$(3 ) " ] || { \
514
+ set -e; \
515
+ package=$(2 ) @$(3 ) ;\
516
+ echo "Downloading $${package}" ;\
517
+ rm -f $(1 ) || true ;\
518
+ GOBIN=$(LOCALBIN ) $(GO ) install $${package} ;\
519
+ mv $(1 ) $(1 ) -$(3 ) ;\
520
+ } ;\
521
+ ln -sf $(1 ) -$(3 ) $(1 )
522
+ endef
0 commit comments