From 7e19f41f3527cf78c8bcb8e9169aae7aa8204fdd Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Fri, 25 Nov 2022 13:50:05 +0100 Subject: [PATCH] Add go.work to deal with multi module dependencies 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 --- .gitignore | 4 ++++ Dockerfile | 3 +++ Makefile | 22 +++++++++++++++++++--- go.work | 6 ++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 go.work diff --git a/.gitignore b/.gitignore index 183e6053..15cee214 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ config/manager/kustomization.yaml # Common CI tools repository CI_TOOLS_REPO + +# generated workspace file +go.work +go.work.sum diff --git a/Dockerfile b/Dockerfile index f978b4df..536f233a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,9 @@ ARG OPERATOR_BASE_IMAGE=gcr.io/distroless/static:nonroot # Build the manager binary FROM $GOLANG_BUILDER AS builder +ARG GOWORK=off +ENV GOWORK=$GOWORK + #Arguments required by OSBS build system ARG CACHITO_ENV_FILE=/remote-source/cachito.env diff --git a/Makefile b/Makefile index 7e2ab519..6061f60b 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,10 @@ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) VERIFY_TLS ?= true +# GOWORK +GOWORK ?= off +export GOWORK := $(GOWORK) + # 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 @@ -117,11 +121,17 @@ 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 + +.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 ##@ Build @@ -135,7 +145,7 @@ run: manifests generate fmt vet ## Run a controller from your host. .PHONY: docker-build docker-build: test ## Build docker image with the manager. - podman build -t ${IMG} . + podman build --build-arg GOWORK=$(GOWORK) -t ${IMG} . .PHONY: docker-push docker-push: ## Push docker image with the manager. @@ -273,19 +283,25 @@ get-ci-tools: # Run go fmt against code gofmt: get-ci-tools $(CI_TOOLS_REPO_DIR)/test-runner/gofmt.sh + $(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 + $(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 + $(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 + $(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 + PATH=$(GOBIN):$(PATH); $(CI_TOOLS_REPO_DIR)/test-runner/golint.sh ./api + diff --git a/go.work b/go.work new file mode 100644 index 00000000..7f8a91ea --- /dev/null +++ b/go.work @@ -0,0 +1,6 @@ +go 1.18 + +use ( + . + ./api +)