Skip to content

Commit

Permalink
Add go.work to deal with multi module dependencies
Browse files Browse the repository at this point in the history
This patch aligns the cinder-operator to the work already done
in both glance and openstack operator where go.work is added
to deal with multi module dependencies and run linters on API
module.
A go.work default file has been added to the repository, and
the related target is created in the Makefile. However, both
vet and generate targets don't call gowork, and we rely on the
default go.work file.

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Nov 29, 2022
1 parent 6240496 commit ec4b175
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ config/manager/kustomization.yaml

# Common CI tools repository
CI_TOOLS_REPO

# generated workspace file
go.work
go.work.sum
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)

VERIFY_TLS ?= true

# GOWORK
GOWORK ?= off

# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
Expand Down Expand Up @@ -118,10 +121,11 @@ fmt: ## Run go fmt against code.
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
go vet ./... ./api/...

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

##@ Build

Expand Down Expand Up @@ -272,20 +276,31 @@ get-ci-tools:

# Run go fmt against code
gofmt: get-ci-tools
$(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh ./api

# Run go vet against code
govet: get-ci-tools
$(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/govet.sh ./api

# Run go test against code
gotest: get-ci-tools
$(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/gotest.sh ./api

# Run golangci-lint test against code
golangci: get-ci-tools
$(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh
GOWORK=$(GOWORK) $(CI_TOOLS_REPO_DIR)/test-runner/golangci.sh ./api

# Run go lint against code
golint: get-ci-tools
PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
GOWORK=$(GOWORK) PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh
GOWORK=$(GOWORK) PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh ./api

.PHONY: gowork
gowork: ## Generate go.work file to support our multi module repository
test -f go.work || go work init
go work use .
go work use ./api
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
./api
)

0 comments on commit ec4b175

Please sign in to comment.