Skip to content

Commit a15698c

Browse files
committed
Add go.work to Makefile to deal with multi module dependencies
This patch aligns the cinder-operator to the work already done in both glance and openstack operators where go.work is added to deal with multi module dependencies and run linters on API module. Signed-off-by: Francesco Pantano <[email protected]>
1 parent 6240496 commit a15698c

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ config/manager/kustomization.yaml
3030

3131
# Common CI tools repository
3232
CI_TOOLS_REPO
33+
34+
# generated workspace file
35+
go.work
36+
go.work.sum

Makefile

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
4040

4141
VERIFY_TLS ?= true
4242

43+
# GOWORK
44+
GOWORK ?= off
45+
4346
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
4447
# You can enable this value if you would like to use SHA Based Digests
4548
# To enable set flag to true
@@ -108,20 +111,21 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
108111

109112

110113
.PHONY: generate
111-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
114+
generate: gowork controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
112115
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
113116

114117
.PHONY: fmt
115118
fmt: ## Run go fmt against code.
116119
go fmt ./...
117120

118121
.PHONY: vet
119-
vet: ## Run go vet against code.
122+
vet: gowork ## Run go vet against code.
120123
go vet ./...
124+
go vet ./... ./api/...
121125

122126
.PHONY: test
123127
test: manifests generate fmt vet envtest ## Run tests.
124-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
128+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... ./api/... -coverprofile cover.out
125129

126130
##@ Build
127131

@@ -272,20 +276,31 @@ get-ci-tools:
272276

273277
# Run go fmt against code
274278
gofmt: get-ci-tools
275-
$(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
279+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
280+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh ./api
276281

277282
# Run go vet against code
278283
govet: get-ci-tools
279-
$(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
284+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
285+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh ./api
280286

281287
# Run go test against code
282288
gotest: get-ci-tools
283-
$(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh
289+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh
290+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh ./api
284291

285292
# Run golangci-lint test against code
286293
golangci: get-ci-tools
287-
$(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
294+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
295+
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh ./api
288296

289297
# Run go lint against code
290298
golint: get-ci-tools
291-
PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
299+
GOWORK=$(GOWORK) PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
300+
GOWORK=$(GOWORK) PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh ./api
301+
302+
.PHONY: gowork
303+
gowork: ## Generate go.work file to support our multi module repository
304+
test -f go.work || go work init
305+
go work use .
306+
go work use ./api

0 commit comments

Comments
 (0)