Skip to content

Commit f27ee96

Browse files
Merge branch 'main' into refactor-lint
2 parents 4e9926e + a427d50 commit f27ee96

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

Makefile

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
4141
IMG ?= controller:latest
4242
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
4343
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
44+
45+
# Go command to use, enables using different Go versions
46+
GO_CMD ?= go
47+
48+
49+
PROJECT_DIR := $(shell pwd)
50+
51+
# directory to store all binaries used during tests
52+
TESTBIN_DIR := $(PROJECT_DIR)/testbin/bin
4453

4554
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
46-
ifeq (,$(shell go env GOBIN))
47-
GOBIN=$(shell go env GOPATH)/bin
55+
ifeq (,$(shell $(GO_CMD) env GOBIN))
56+
GOBIN=$(shell $(GO_CMD) env GOPATH)/bin
4857
else
49-
GOBIN=$(shell go env GOBIN)
58+
GOBIN=$(shell $(GO_CMD) env GOBIN)
5059
endif
5160

5261
# Setting SHELL to bash allows bash commands to be executed by recipes.
@@ -97,22 +106,21 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
97106
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
98107

99108
fmt: ## Run go fmt against code.
100-
go fmt ./...
109+
$(GO_CMD) fmt ./...
101110

102111
vet: ## Run go vet against code.
103-
go vet ./...
104-
112+
$(GO_CMD) vet ./...
105113

106-
ENVTEST = $(shell pwd)/testbin/bin/setup-envtest
114+
ENVTEST = $(TESTBIN_DIR)/setup-envtest
107115
envtest: ## Download envtest-setup locally if necessary.
108116
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@d0396a3d6f9fb554ef2da382a3d0bf05f7565e65)
109117

110118
test: manifests envtest generate fmt vet
111-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
119+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO_CMD) test ./... -coverprofile cover.out
112120

113121
# gotestsum is used to generate xml for the tests. Embedded in the Dockerfile.pr
114122
junit: gotestsum manifests envtest generate fmt vet
115-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(PROJECT_DIR)/testbin/bin/gotestsum --junitfile artifacts/junit-ginko.xml -- ./... -coverprofile cover.out
123+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(TESTBIN_DIR)/gotestsum --junitfile artifacts/junit-ginko.xml -- ./... -coverprofile cover.out
116124

117125
# entry point for testing kuttl with kind
118126
kuttl: manifests envtest generate fmt vet
@@ -121,10 +129,10 @@ kuttl: manifests envtest generate fmt vet
121129
##@ Build
122130

123131
build: generate fmt vet ## Build manager binary.
124-
go build -o bin/manager main.go
132+
$(GO_CMD) build -o bin/manager main.go
125133

126134
run: manifests generate fmt vet ## Run a controller from your host.
127-
go run ./main.go
135+
$(GO_CMD) run ./main.go
128136

129137
docker-build: test ## Build docker image with the manager.
130138
docker build -t ${IMG} .
@@ -146,7 +154,7 @@ install-resources:
146154
oc apply -f examples/chrome.yaml -n boot
147155

148156
run-local:
149-
go run ./main.go --metrics-bind-address :9090 --health-probe-bind-address :9091
157+
$(GO_CMD) run ./main.go --metrics-bind-address :9090 --health-probe-bind-address :9091
150158

151159
##@ Deployment
152160

@@ -164,24 +172,23 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
164172
$(KUSTOMIZE) build config/default | kubectl delete -f -
165173

166174

167-
CONTROLLER_GEN = $(shell pwd)/testbin/bin/controller-gen
175+
CONTROLLER_GEN = $(TESTBIN_DIR)/controller-gen
168176
controller-gen: ## Download controller-gen locally if necessary.
169177
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
170178

171-
KUSTOMIZE = $(shell pwd)/testbin/bin/kustomize
179+
KUSTOMIZE = $(TESTBIN_DIR)/kustomize
172180
kustomize: ## Download kustomize locally if necessary.
173181
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
174182

175-
GOTESTSUM = $(shell pwd)/testbin/bin/gotestsum
183+
GOTESTSUM = $(TESTBIN_DIR)/gotestsum
176184
gotestsum: ## Download if necessary
177185
$(call go-get-tool,$(GOTESTSUM),gotest.tools/[email protected])
178186

179187
# go-get-tool will 'go get' any package $2 and install it to $1.
180-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
181188
define go-get-tool
182189
@[ -f $(1) ] || { \
183190
set -e ;\
184-
GOBIN=$(PROJECT_DIR)/testbin/bin go install $(2) ;\
191+
GOBIN=$(TESTBIN_DIR) $(GO_CMD) install $(2) ;\
185192
}
186193
endef
187194

@@ -208,7 +215,7 @@ ifeq (,$(shell which opm 2>/dev/null))
208215
@{ \
209216
set -e ;\
210217
mkdir -p $(dir $(OPM)) ;\
211-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
218+
OS=$(shell $(GO_CMD) env GOOS) && ARCH=$(shell $(GO_CMD) env GOARCH) && \
212219
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
213220
chmod +x $(OPM) ;\
214221
}
@@ -242,4 +249,7 @@ catalog-push: ## Push a catalog image.
242249
$(MAKE) docker-push IMG=$(CATALOG_IMG)
243250

244251
lint:
245-
golangci-lint run
252+
golangci-lint run
253+
254+
clean:
255+
rm -r $(TESTBIN_DIR)

0 commit comments

Comments
 (0)