6363GOBIN =$(shell go env GOBIN)
6464endif
6565
66- GOLANGCI_LINT ?= go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint
66+ PACKAGE =github.com/openshift/cert-manager-operator
67+ PROJECT_ROOT := $(shell pwd)
6768
68- CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/controller-gen
69+ BIN =$(lastword $(subst /, ,$(PACKAGE ) ) )
70+ BIN_DIR =$(PROJECT_ROOT ) /bin
71+ TOOLS_DIR =$(PROJECT_ROOT ) /tools
6972
70- SETUP_ENVTEST := go run sigs.k8s.io/controller-runtime/tools/setup-envtest
73+ GOLANGCI_LINT := $( BIN_DIR ) /golangci-lint
7174
72- KUSTOMIZE := go run sigs.k8s.io/kustomize/kustomize/v5
75+ CONTROLLER_GEN := cd $( TOOLS_DIR ) && GOFLAGS="" go run sigs.k8s.io/controller-tools/cmd/controller-gen
7376
74- K8S_ENVTEST_VERSION := 1.21.4
77+ SETUP_ENVTEST := cd $( TOOLS_DIR ) && GOFLAGS="" go run sigs.k8s.io/controller-runtime/tools/setup-envtest
7578
76- PACKAGE =github.com/openshift/cert-manager-operator
77-
78- BIN =$(lastword $(subst /, ,$(PACKAGE ) ) )
79- BIN_DIR =$(shell pwd) /bin
79+ KUSTOMIZE := $(BIN_DIR ) /kustomize
8080
8181# Setting SHELL to bash allows bash commands to be executed by recipes.
8282# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -94,8 +94,6 @@ BUNDLE_IMG ?= olm-bundle:latest
9494INDEX_IMG ?= olm-bundle-index:latest
9595OPM_VERSION ?= v1.23.0
9696
97- GOLANGCI_LINT_BIN =$(BIN_DIR ) /golangci-lint
98-
9997OPERATOR_SDK_BIN =$(BIN_DIR ) /operator-sdk
10098
10199HELM_BIN =$(BIN_DIR ) /helm
@@ -123,26 +121,26 @@ $(call add-bindata,assets,./bindata/...,bindata,assets,pkg/operator/assets/binda
123121
124122.PHONY : manifests
125123manifests : # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
126- $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" . /..." output:crd:artifacts:config=config/crd/bases
124+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" $( PROJECT_ROOT ) /..." output:crd:artifacts:config=$( PROJECT_ROOT ) / config/crd/bases output:rbac:artifacts:config= $( PROJECT_ROOT ) /config/rbac
127125
128126.PHONY : generate
129127generate : # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
130- $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" . /api/..."
128+ $(CONTROLLER_GEN ) object:headerFile=" $( PROJECT_ROOT ) / hack/boilerplate.go.txt" paths=" $( PROJECT_ROOT ) /api/..."
131129 hack/update-clientgen.sh
132130
133131.PHONY : fmt
134132fmt : # # Run go fmt against code.
135- go fmt ./...
133+ GOFLAGS= " " go fmt ./...
136134
137135.PHONY : vet
138136vet : # # Run go vet against code.
139- go vet ./...
137+ GOFLAGS= " " go vet ./...
140138
141- ENVTEST_ASSETS_DIR ?= $(shell pwd ) /testbin
139+ ENVTEST_ASSETS_DIR ?= $(PROJECT_ROOT ) /testbin
142140.PHONY : test
143141test : manifests generate fmt vet # # Run tests.
144142 mkdir -p " $( ENVTEST_ASSETS_DIR) "
145- KUBEBUILDER_ASSETS=" $( shell $( SETUP_ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( ENVTEST_ASSETS_DIR) -p path) " go test ./... -coverprofile cover.out
143+ KUBEBUILDER_ASSETS=" $( shell $( SETUP_ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( ENVTEST_ASSETS_DIR) -p path) " GOFLAGS= " " go test ./... -coverprofile cover.out
146144
147145update-manifests : $(HELM_BIN )
148146 hack/update-cert-manager-manifests.sh $(MANIFEST_SOURCE )
@@ -154,25 +152,44 @@ update: generate update-manifests update-bindata
154152
155153.PHONY : update-with-container
156154update-with-container :
157- $(CONTAINER_ENGINE ) run -ti --rm -v $(PWD ) :/go/src/github.com/openshift/cert-manager-operator:z -w /go/src/github.com/openshift/cert-manager-operator $(CONTAINER_IMAGE_NAME ) make update
155+ $(CONTAINER_ENGINE ) run -ti --rm -v $(PROJECT_ROOT ) :/go/src/github.com/openshift/cert-manager-operator:z -w /go/src/github.com/openshift/cert-manager-operator $(CONTAINER_IMAGE_NAME ) make update
158156
159- verify-scripts :
157+ verify-scripts : verify-bindata
160158 hack/verify-deepcopy.sh
161159 hack/verify-clientgen.sh
162160 hack/verify-bundle.sh
163161.PHONY : verify-scripts
164162
165163.PHONY : verify
166- verify : verify-scripts fmt
164+ verify : verify-scripts verify-deps fmt vet
167165
168166.PHONY : verify-with-container
169167verify-with-container :
170- $(CONTAINER_ENGINE ) run -ti --rm -v $(PWD ) :/go/src/github.com/openshift/cert-manager-operator:z -w /go/src/github.com/openshift/cert-manager-operator $(CONTAINER_IMAGE_NAME ) make verify
168+ $(CONTAINER_ENGINE ) run -ti --rm -v $(PROJECT_ROOT ) :/go/src/github.com/openshift/cert-manager-operator:z -w /go/src/github.com/openshift/cert-manager-operator $(CONTAINER_IMAGE_NAME ) make verify
171169
172170.PHONY : verify-deps
173171verify-deps :
174172 hack/verify-deps.sh
175173
174+ .PHONY : update-vendor
175+ update-vendor : # # Update vendor directory for all modules in the workspace.
176+ go mod tidy
177+ cd tools && go mod tidy
178+ cd test/e2e && go mod tidy
179+ go work vendor
180+
181+ .PHONY : update-dep
182+ update-dep : # # Update a dependency across all modules. Usage: make update-dep PKG=k8s.io/api@v0.35.0
183+ @if [ -z " $( PKG) " ]; then echo " Usage: make update-dep PKG=package@version" ; exit 1; fi
184+ @echo " Updating $( PKG) in main module..."
185+ go get $(PKG )
186+ @echo " Updating $( PKG) in tools module..."
187+ -cd tools && go get $(PKG )
188+ @echo " Updating $( PKG) in test/e2e module..."
189+ -cd test/e2e && go get $(PKG )
190+ @echo " Running update-vendor..."
191+ $(MAKE ) update-vendor
192+
176193.PHONY : local-run
177194local-run : build
178195 RELATED_IMAGE_CERT_MANAGER_WEBHOOK=quay.io/jetstack/cert-manager-webhook:$(CERT_MANAGER_VERSION ) \
@@ -222,7 +239,7 @@ image-push: check-tools ## Push container image with the operator.
222239# #@ Deployment
223240
224241.PHONY : deploy
225- deploy : manifests # # Deploy controller to the K8s cluster specified in ~/.kube/config.
242+ deploy : $( KUSTOMIZE ) manifests # # Deploy controller to the K8s cluster specified in ~/.kube/config.
226243 @kubectl get namespace cert-manager-operator > /dev/null 2>&1 || { \
227244 echo " Namespace 'cert-manager-operator' does not exist. Creating it..." ; \
228245 kubectl create namespace cert-manager-operator; \
@@ -231,12 +248,12 @@ deploy: manifests ## Deploy controller to the K8s cluster specified in ~/.kube/c
231248 $(KUSTOMIZE ) build config/default | kubectl apply -f -
232249
233250.PHONY : undeploy
234- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
251+ undeploy : $( KUSTOMIZE ) # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
235252 $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found -f -
236253 kubectl delete namespace cert-manager-operator --ignore-not-found
237254
238255.PHONY : bundle
239- bundle : check-tools $(OPERATOR_SDK_BIN ) manifests
256+ bundle : check-tools $(OPERATOR_SDK_BIN ) $( KUSTOMIZE ) manifests
240257 $(OPERATOR_SDK_BIN ) generate kustomize manifests -q
241258 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
242259 $(KUSTOMIZE ) build config/manifests | $(OPERATOR_SDK_BIN ) generate bundle -q --version $(BUNDLE_VERSION ) $(BUNDLE_METADATA_OPTS )
@@ -274,14 +291,14 @@ endef
274291
275292.PHONY : test-e2e
276293test-e2e : test-e2e-wait-for-stable-state
277- go test \
294+ cd test/e2e && GOFLAGS= " " go test \
278295 -timeout $(E2E_TIMEOUT ) \
279296 -count 1 \
280297 -v \
281298 -p 1 \
282299 -tags e2e \
283300 -run " $( TEST) " \
284- ./test/e2e \
301+ . \
285302 -ginkgo.label-filter=$(E2E_GINKGO_LABEL_FILTER )
286303
287304.PHONY : test-e2e-wait-for-stable-state
@@ -306,16 +323,16 @@ test-e2e-debug-cluster:
306323 @echo " ---- /Debugging the current state ----"
307324
308325.PHONY : lint
309- lint :
310- $(GOLANGCI_LINT ) run --verbose --config .golangci.yaml
326+ lint : $( GOLANGCI_LINT )
327+ $(GOLANGCI_LINT ) run --verbose --config $( PROJECT_ROOT ) / .golangci.yaml $( PROJECT_ROOT ) /...
311328
312329.PHONY : lint-fix
313- lint-fix :
314- $(GOLANGCI_LINT ) run --config .golangci.yaml --fix
330+ lint-fix : $( GOLANGCI_LINT )
331+ $(GOLANGCI_LINT ) run --config $( PROJECT_ROOT ) / .golangci.yaml --fix $( PROJECT_ROOT ) /...
315332
316- $(GOLANGCI_LINT_BIN ) :
333+ $(GOLANGCI_LINT ) :
317334 mkdir -p $(BIN_DIR )
318- hack/golangci-lint.sh $(GOLANGCI_LINT_BIN )
335+ cd $( TOOLS_DIR ) && GOFLAGS= " " go build -o $(GOLANGCI_LINT ) github.com/golangci/golangci-lint/v2/cmd/golangci-lint
319336
320337$(OPERATOR_SDK_BIN ) :
321338 mkdir -p $(BIN_DIR )
@@ -325,6 +342,10 @@ $(HELM_BIN):
325342 mkdir -p $(BIN_DIR )
326343 hack/helm.sh $(HELM_BIN )
327344
345+ $(KUSTOMIZE ) :
346+ mkdir -p $(BIN_DIR )
347+ cd $(TOOLS_DIR ) && GOFLAGS=" " go build -o $(KUSTOMIZE ) sigs.k8s.io/kustomize/kustomize/v5
348+
328349.PHONY : clean
329350clean :
330351 go clean
0 commit comments