2
2
IMG ?= controller:latest
3
3
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
4
4
ENVTEST_K8S_VERSION = 1.29.0
5
+ TRIVY_VERSION = 0.49.1
6
+ GO_VERSION ?= 1.23.9
5
7
6
8
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
7
9
ifeq (,$(shell go env GOBIN) )
@@ -21,6 +23,9 @@ CONTAINER_TOOL ?= docker
21
23
SHELL = /usr/bin/env bash -o pipefail
22
24
.SHELLFLAGS = -ec
23
25
26
+ # Enables shell script tracing. Enable by running: TRACE=1 make <target>
27
+ TRACE ?= 0
28
+
24
29
.PHONY : all
25
30
all : build
26
31
@@ -157,6 +162,7 @@ docker-build: ## Build docker image with the manager.
157
162
source hack/version.sh && version::get_git_vars && version::get_build_date && \
158
163
$(CONTAINER_TOOL ) build \
159
164
--tag ${IMG} \
165
+ --build-arg " GO_VERSION=$( GO_VERSION) " \
160
166
--build-arg " BUILD_DATE=$$ {BUILD_DATE}" \
161
167
--build-arg " GIT_COMMIT=$$ {GIT_COMMIT}" \
162
168
--build-arg " GIT_RELEASE_COMMIT=$$ {GIT_RELEASE_COMMIT}" \
@@ -185,6 +191,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
185
191
$(CONTAINER_TOOL ) buildx build \
186
192
--platform=$(PLATFORMS ) \
187
193
--tag ${IMG} --push \
194
+ --build-arg " GO_VERSION=$( GO_VERSION) " \
188
195
--build-arg " BUILD_DATE=$$ {BUILD_DATE}" \
189
196
--build-arg " GIT_COMMIT=$$ {GIT_COMMIT}" \
190
197
--build-arg " GIT_RELEASE_COMMIT=$$ {GIT_RELEASE_COMMIT}" \
@@ -251,6 +258,28 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
251
258
undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
252
259
$(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
253
260
261
+ # #@ Security
262
+
263
+ .PHONY : verify-container-images
264
+ verify-container-images : # # Verify container images
265
+ TRACE=$(TRACE ) ./hack/verify-container-images.sh $(TRIVY_VERSION )
266
+
267
+ .PHONY : verify-govulncheck
268
+ verify-govulncheck : $(GOVULNCHECK ) # # Verify code for vulnerabilities
269
+ $(GOVULNCHECK ) ./... && R1=$$? || R1=$$? ; \
270
+ if [ " $$ R1" -ne " 0" ]; then \
271
+ exit 1; \
272
+ fi
273
+
274
+ .PHONY : verify-security
275
+ verify-security : # # Verify code and images for vulnerabilities
276
+ $(MAKE ) verify-container-images && R1=$$? || R1=$$? ; \
277
+ $(MAKE ) verify-govulncheck && R2=$$? || R2=$$? ; \
278
+ if [ " $$ R1" -ne " 0" ] || [ " $$ R2" -ne " 0" ]; then \
279
+ echo " Check for vulnerabilities failed! There are vulnerabilities to be fixed" ; \
280
+ exit 1; \
281
+ fi
282
+
254
283
# #@ Dependencies
255
284
256
285
# # Location to install dependencies to
@@ -269,6 +298,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
269
298
GOLANGCI_KAL = $(LOCALBIN ) /golangci-kube-api-linter
270
299
MOCKGEN = $(LOCALBIN ) /mockgen
271
300
KUTTL = $(LOCALBIN ) /kubectl-kuttl
301
+ GOVULNCHECK = $(LOCALBIN ) /govulncheck
272
302
273
303
# # Tool Versions
274
304
KUSTOMIZE_VERSION ?= v5.6.0
@@ -278,6 +308,7 @@ GOLANGCI_LINT_VERSION ?= v2.0.1
278
308
KAL_VERSION ?= v0.0.0-20250501211755-2c83ed303cde
279
309
MOCKGEN_VERSION ?= v0.5.0
280
310
KUTTL_VERSION ?= v0.22.0
311
+ GOVULNCHECK_VERSION ?= v1.1.4
281
312
282
313
.PHONY : kustomize
283
314
kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
@@ -327,6 +358,11 @@ kuttl: $(KUTTL) ## Download kuttl locally if necessary.
327
358
$(KUTTL ) : $(LOCALBIN )
328
359
$(call go-install-tool,$(KUTTL ) ,github.com/kudobuilder/kuttl/cmd/kubectl-kuttl,$(KUTTL_VERSION ) )
329
360
361
+ .PHONY : govulncheck
362
+ govulncheck : $(GOVULNCHECK ) # # Download govulncheck locally if necessary.
363
+ $(GOVULNCHECK ) : $(LOCALBIN )
364
+ $(call go-install-tool,$(GOVULNCHECK ) ,golang.org/x/vuln/cmd/govulncheck,$(GOVULNCHECK_VERSION ) )
365
+
330
366
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
331
367
# $1 - target path with name of binary
332
368
# $2 - package url which can be installed
@@ -342,3 +378,8 @@ mv $(1) $(1)-$(3) ;\
342
378
} ;\
343
379
ln -sf $(1 ) -$(3 ) $(1 )
344
380
endef
381
+
382
+ # #@ helpers:
383
+
384
+ go-version : # # Print the go version we use to compile our binaries and images
385
+ @echo $(GO_VERSION )
0 commit comments