@@ -41,12 +41,21 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
41
41
IMG ?= controller:latest
42
42
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
43
43
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
44
53
45
54
# 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
48
57
else
49
- GOBIN =$(shell go env GOBIN)
58
+ GOBIN =$(shell $( GO_CMD ) env GOBIN)
50
59
endif
51
60
52
61
# 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
97
106
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
98
107
99
108
fmt : # # Run go fmt against code.
100
- go fmt ./...
109
+ $( GO_CMD ) fmt ./...
101
110
102
111
vet : # # Run go vet against code.
103
- go vet ./...
104
-
112
+ $(GO_CMD ) vet ./...
105
113
106
- ENVTEST = $(shell pwd) /testbin/bin /setup-envtest
114
+ ENVTEST = $(TESTBIN_DIR ) /setup-envtest
107
115
envtest : # # Download envtest-setup locally if necessary.
108
116
$(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@d0396a3d6f9fb554ef2da382a3d0bf05f7565e65)
109
117
110
118
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
112
120
113
121
# gotestsum is used to generate xml for the tests. Embedded in the Dockerfile.pr
114
122
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
116
124
117
125
# entry point for testing kuttl with kind
118
126
kuttl : manifests envtest generate fmt vet
@@ -121,10 +129,10 @@ kuttl: manifests envtest generate fmt vet
121
129
# #@ Build
122
130
123
131
build : generate fmt vet # # Build manager binary.
124
- go build -o bin/manager main.go
132
+ $( GO_CMD ) build -o bin/manager main.go
125
133
126
134
run : manifests generate fmt vet # # Run a controller from your host.
127
- go run ./main.go
135
+ $( GO_CMD ) run ./main.go
128
136
129
137
docker-build : test # # Build docker image with the manager.
130
138
docker build -t ${IMG} .
@@ -146,7 +154,7 @@ install-resources:
146
154
oc apply -f examples/chrome.yaml -n boot
147
155
148
156
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
150
158
151
159
# #@ Deployment
152
160
@@ -164,24 +172,23 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
164
172
$(KUSTOMIZE ) build config/default | kubectl delete -f -
165
173
166
174
167
- CONTROLLER_GEN = $(shell pwd) /testbin/bin /controller-gen
175
+ CONTROLLER_GEN = $(TESTBIN_DIR ) /controller-gen
168
176
controller-gen : # # Download controller-gen locally if necessary.
169
177
$(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
170
178
171
- KUSTOMIZE = $(shell pwd) /testbin/bin /kustomize
179
+ KUSTOMIZE = $(TESTBIN_DIR ) /kustomize
172
180
kustomize : # # Download kustomize locally if necessary.
173
181
$(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
174
182
175
- GOTESTSUM = $(shell pwd) /testbin/bin /gotestsum
183
+ GOTESTSUM = $(TESTBIN_DIR ) /gotestsum
176
184
gotestsum : # # Download if necessary
177
185
$(call go-get-tool,$(GOTESTSUM ) ,gotest.tools/[email protected] )
178
186
179
187
# go-get-tool will 'go get' any package $2 and install it to $1.
180
- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
181
188
define go-get-tool
182
189
@[ -f $(1 ) ] || { \
183
190
set -e ;\
184
- GOBIN=$(PROJECT_DIR ) /testbin/bin go install $(2 ) ;\
191
+ GOBIN=$(TESTBIN_DIR ) $( GO_CMD ) install $(2 ) ;\
185
192
}
186
193
endef
187
194
@@ -208,7 +215,7 @@ ifeq (,$(shell which opm 2>/dev/null))
208
215
@{ \
209
216
set -e ;\
210
217
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) && \
212
219
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
213
220
chmod +x $(OPM) ;\
214
221
}
@@ -242,4 +249,7 @@ catalog-push: ## Push a catalog image.
242
249
$(MAKE ) docker-push IMG=$(CATALOG_IMG )
243
250
244
251
lint :
245
- golangci-lint run
252
+ golangci-lint run
253
+
254
+ clean :
255
+ rm -r $(TESTBIN_DIR )
0 commit comments