@@ -4,12 +4,20 @@ IMG ?= fluxcd/kustomize-controller:latest
44CRD_OPTIONS ?= crd:crdVersions=v1
55SOURCE_VER ?= v0.22.3
66
7- # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
7+ # Use the same version of SOPS already referenced on go.mod
8+ SOPS_VER := $(shell go list -m all | grep go.mozilla.org/sops | awk '{print $$2}')
9+
10+ # Repository root based on Git metadata
11+ REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
12+ BUILD_DIR := $(REPOSITORY_ROOT ) /build
13+
14+ # If gobin not set, create one on ./build and add to path.
815ifeq (,$(shell go env GOBIN) )
9- GOBIN =$(shell go env GOPATH) /bin
16+ GOBIN =$(BUILD_DIR ) /gobin
1017else
1118GOBIN =$(shell go env GOBIN)
1219endif
20+ export PATH: =$(GOBIN ) :${PATH}
1321
1422# Allows for defining additional Go test args, e.g. '-tags integration'.
1523GO_TEST_ARGS ?=
@@ -25,20 +33,24 @@ ENVTEST_ARCH ?= amd64
2533all : manager
2634
2735# Download the envtest binaries to testbin
28- ENVTEST_ASSETS_DIR =$(shell pwd) /build /testbin
36+ ENVTEST_ASSETS_DIR =$(BUILD_DIR ) /testbin
2937ENVTEST_KUBERNETES_VERSION? =latest
3038install-envtest : setup-envtest
3139 mkdir -p ${ENVTEST_ASSETS_DIR}
3240 $(ENVTEST ) use $(ENVTEST_KUBERNETES_VERSION ) --arch=$(ENVTEST_ARCH ) --bin-dir=$(ENVTEST_ASSETS_DIR )
3341
42+ SOPS = $(GOBIN ) /sops
43+ $(SOPS ) : # # Download latest sops binary if none is found.
44+ $(call go-install-tool,$(SOPS ) ,go.mozilla.org/sops/v3/cmd/sops@$(SOPS_VER ) )
45+
3446# Run controller tests
3547KUBEBUILDER_ASSETS? ="$(shell $(ENVTEST ) --arch=$(ENVTEST_ARCH ) use -i $(ENVTEST_KUBERNETES_VERSION ) --bin-dir=$(ENVTEST_ASSETS_DIR ) -p path) "
36- test : tidy generate fmt vet manifests api-docs download-crd-deps install-envtest
48+ test : tidy generate fmt vet manifests api-docs download-crd-deps install-envtest $( SOPS )
3749 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) go test ./... $(GO_TEST_ARGS ) -v -coverprofile cover.out
3850
3951# Build manager binary
4052manager : generate fmt vet
41- go build -o bin/manager main.go
53+ go build -o $( BUILD_DIR ) / bin/manager main.go
4254
4355# Run against the configured Kubernetes cluster in ~/.kube/config
4456run : generate fmt vet manifests
@@ -120,18 +132,18 @@ docker-deploy:
120132 kubectl -n flux-system set image deployment/kustomize-controller manager=${IMG}
121133
122134# Find or download controller-gen
123- CONTROLLER_GEN = $(shell pwd) /bin /controller-gen
135+ CONTROLLER_GEN = $(GOBIN ) /controller-gen
124136.PHONY : controller-gen
125137controller-gen : # # Download controller-gen locally if necessary.
126138 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
127139
128140# Find or download gen-crd-api-reference-docs
129- GEN_CRD_API_REFERENCE_DOCS = $(shell pwd) /bin /gen-crd-api-reference-docs
141+ GEN_CRD_API_REFERENCE_DOCS = $(GOBIN ) /gen-crd-api-reference-docs
130142.PHONY : gen-crd-api-reference-docs
131143gen-crd-api-reference-docs :
132144 $(call go-install-tool,$(GEN_CRD_API_REFERENCE_DOCS ) ,github.com/ahmetb/gen-crd-api-reference-docs@v0.3.0)
133145
134- ENVTEST = $(shell pwd) /bin /setup-envtest
146+ ENVTEST = $(GOBIN ) /setup-envtest
135147.PHONY : envtest
136148setup-envtest : # # Download envtest-setup locally if necessary.
137149 $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
@@ -145,26 +157,26 @@ TMP_DIR=$$(mktemp -d) ;\
145157cd $$TMP_DIR ;\
146158go mod init tmp ;\
147159echo "Downloading $(2 ) " ;\
148- GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
160+ GOBIN=$(GOBIN ) go install $(2 ) ;\
149161rm -rf $$TMP_DIR ;\
150162}
151163endef
152164
153165# Build fuzzers
154166fuzz-build :
155- rm -rf $(shell pwd) /build /fuzz/
156- mkdir -p $(shell pwd) /build /fuzz/out/
167+ rm -rf $(BUILD_DIR ) /fuzz/
168+ mkdir -p $(BUILD_DIR ) /fuzz/out/
157169
158170 docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
159171 docker run --rm \
160172 -e FUZZING_LANGUAGE=go -e SANITIZER=address \
161173 -e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \
162- -v "$(shell pwd)/build /fuzz/out":/out \
174+ -v "$(BUILD_DIR) /fuzz/out":/out \
163175 local-fuzzing:latest
164176
165177fuzz-smoketest : fuzz-build
166178 docker run --rm \
167- -v " $( shell pwd ) /build /fuzz/out" :/out \
179+ -v " $( BUILD_DIR ) /fuzz/out" :/out \
168180 -v " $( shell pwd) /tests/fuzz/oss_fuzz_run.sh" :/runner.sh \
169181 local-fuzzing:latest \
170182 bash -c " /runner.sh"
0 commit comments