@@ -23,16 +23,19 @@ include $(ROOT_DIR_RELATIVE)/common.mk
2323export GO111MODULE =on
2424unexport GOPATH
2525
26+ # Enables shell script tracing. Enable by running: TRACE=1 make <target>
27+ TRACE ?= 0
28+
2629# Go
2730GO_VERSION ?= 1.22.7
2831
2932# Directories.
3033ARTIFACTS ?= $(REPO_ROOT ) /_artifacts
3134TOOLS_DIR := hack/tools
35+ BIN_DIR := bin
3236TOOLS_DIR_DEPS := $(TOOLS_DIR ) /go.sum $(TOOLS_DIR ) /go.mod $(TOOLS_DIR ) /Makefile
33- TOOLS_BIN_DIR := $(TOOLS_DIR ) /bin
37+ TOOLS_BIN_DIR := $(TOOLS_DIR ) /$( BIN_DIR )
3438
35- BIN_DIR := bin
3639REPO_ROOT := $(shell git rev-parse --show-toplevel)
3740GH_REPO ?= kubernetes-sigs/cluster-api-provider-openstack
3841TEST_E2E_DIR := test/e2e
@@ -49,6 +52,13 @@ GO_APIDIFF_VER := v0.8.2
4952GO_APIDIFF_BIN := go-apidiff
5053GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
5154
55+ # govulncheck
56+ GOVULNCHECK_VER := v1.1.4
57+ GOVULNCHECK_BIN := govulncheck
58+ GOVULNCHECK_PKG := golang.org/x/vuln/cmd/govulncheck
59+
60+ TRIVY_VER := 0.49.1
61+
5262# Binaries.
5363CONTROLLER_GEN := $(TOOLS_BIN_DIR ) /controller-gen
5464CONVERSION_GEN := $(TOOLS_BIN_DIR ) /conversion-gen
@@ -63,6 +73,7 @@ RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
6373SETUP_ENVTEST := $(TOOLS_BIN_DIR ) /setup-envtest
6474GEN_CRD_API_REFERENCE_DOCS := $(TOOLS_BIN_DIR ) /gen-crd-api-reference-docs
6575GO_APIDIFF := $(TOOLS_BIN_DIR ) /$(GO_APIDIFF_BIN ) -$(GO_APIDIFF_VER )
76+ GOVULNCHECK := $(TOOLS_BIN_DIR ) /$(GOVULNCHECK_BIN ) -$(GOVULNCHECK_VER )
6677
6778# Kubebuilder
6879export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.28.0
@@ -252,6 +263,12 @@ $(GO_APIDIFF_BIN): $(GO_APIDIFF)
252263$(GO_APIDIFF ) : # Build go-apidiff.
253264 GOBIN=$(abspath $(TOOLS_BIN_DIR ) ) $(GO_INSTALL ) $(GO_APIDIFF_PKG ) $(GO_APIDIFF_BIN ) $(GO_APIDIFF_VER )
254265
266+ .PHONY : $(GOVULNCHECK_BIN )
267+ $(GOVULNCHECK_BIN ) : $(GOVULNCHECK ) # # Build a local copy of govulncheck.
268+
269+ $(GOVULNCHECK ) : # Build govulncheck.
270+ GOBIN=$(abspath $(TOOLS_BIN_DIR ) ) $(GO_INSTALL ) $(GOVULNCHECK_PKG ) $(GOVULNCHECK_BIN ) $(GOVULNCHECK_VER )
271+
255272# # --------------------------------------
256273# #@ Linting
257274# # --------------------------------------
@@ -563,8 +580,12 @@ clean-temporary: ## Remove all temporary files and folders
563580clean-release : # # Remove the release folder
564581 rm -rf $(RELEASE_DIR )
565582
583+ .PHONY : clean-release-git
584+ clean-release-git : # # Restores the git files usually modified during a release
585+ git restore ./* manager_image_patch.yaml ./* manager_pull_policy.yaml
586+
566587.PHONY : verify
567- verify : verify-boilerplate verify-modules verify-gen verify-orc
588+ verify : verify-boilerplate verify-modules verify-gen verify-orc verify-govulncheck
568589
569590.PHONY : verify-boilerplate
570591verify-boilerplate :
@@ -588,6 +609,27 @@ verify-gen: generate
588609verify-orc :
589610 $(MAKE ) -C $(REPO_ROOT ) /orc verify-generated
590611
612+ .PHONY : verify-container-images
613+ verify-container-images : # # Verify container images
614+ TRACE=$(TRACE ) ./hack/verify-container-images.sh $(TRIVY_VER )
615+
616+ .PHONY : verify-govulncheck
617+ verify-govulncheck : $(GOVULNCHECK ) # # Verify code for vulnerabilities
618+ $(GOVULNCHECK ) ./... && R1=$$? || R1=$$? ; \
619+ $(GOVULNCHECK ) -C " $( TOOLS_DIR) " ./... && R2=$$? || R2=$$? ; \
620+ if [ " $$ R1" -ne " 0" ] || [ " $$ R2" -ne " 0" ]; then \
621+ exit 1; \
622+ fi
623+
624+ .PHONY : verify-security
625+ verify-security : # # Verify code and images for vulnerabilities
626+ $(MAKE ) verify-container-images && R1=$$? || R1=$$? ; \
627+ $(MAKE ) verify-govulncheck && R2=$$? || R2=$$? ; \
628+ if [ " $$ R1" -ne " 0" ] || [ " $$ R2" -ne " 0" ]; then \
629+ echo " Check for vulnerabilities failed! There are vulnerabilities to be fixed" ; \
630+ exit 1; \
631+ fi
632+
591633.PHONY : compile-e2e
592634compile-e2e : # # Test e2e compilation
593635 go test -c -o /dev/null -tags=e2e ./test/e2e/suites/conformance
0 commit comments