From 58cac572dd79aa1dbcc21e8b02c3b0ddd83955d0 Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Fri, 10 May 2024 09:08:32 -0700 Subject: [PATCH 1/2] build: Make module-relative "go list -m" compatible with GOWORK When GOWORK is enabled, "go list -m" always lists all modules in the workspace. To list the module for the current working directory, we disable GOWORK. --- make/apis.mk | 2 +- make/clusterctl.mk | 10 +++++----- make/go.mk | 4 ++-- test/helpers/envtest.go | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/make/apis.mk b/make/apis.mk index ffe5d5e5f..f1ca971e1 100644 --- a/make/apis.mk +++ b/make/apis.mk @@ -51,7 +51,7 @@ api.sync.%: ; $(info $(M) syncing external API: $(PROVIDER_MODULE_$*)/$(PROVIDER --exclude='*webhook*.go' \ --exclude='*test.go' \ --exclude='s3bucket.go' \ - $$(cd $(PROVIDER_MODULE_DIR) && go list -m -f '{{ .Dir }}' $(PROVIDER_MODULE_$*))/$(PROVIDER_API_PATH_$*)/$(PROVIDER_API_VERSION_$*)/*.go \ + $$(cd $(PROVIDER_MODULE_DIR) && GOWORK=off go list -m -f '{{ .Dir }}' $(PROVIDER_MODULE_$*))/$(PROVIDER_API_PATH_$*)/$(PROVIDER_API_VERSION_$*)/*.go \ $(PROVIDER_API_DIR) find $(PROVIDER_API_DIR) -type d -exec chmod 0755 {} \; find $(PROVIDER_API_DIR) -type f -exec chmod 0644 {} \; diff --git a/make/clusterctl.mk b/make/clusterctl.mk index d50788311..263e42da5 100644 --- a/make/clusterctl.mk +++ b/make/clusterctl.mk @@ -1,11 +1,11 @@ # Copyright 2023 Nutanix. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -export CAPI_VERSION := $(shell go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api) -export CAPD_VERSION := $(shell go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api/test) -export CAPA_VERSION := $(shell cd hack/third-party/capa && go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api-provider-aws/v2) -export CAPX_VERSION := $(shell cd hack/third-party/capx && go list -m -f '{{ .Version }}' github.com/nutanix-cloud-native/cluster-api-provider-nutanix) -export CAAPH_VERSION := $(shell cd hack/third-party/caaph && go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api-addon-provider-helm) +export CAPI_VERSION := $(shell GOWORK=off go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api) +export CAPD_VERSION := $(shell GOWORK=off go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api/test) +export CAPA_VERSION := $(shell cd hack/third-party/capa && GOWORK=off go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api-provider-aws/v2) +export CAPX_VERSION := $(shell cd hack/third-party/capx && GOWORK=off go list -m -f '{{ .Version }}' github.com/nutanix-cloud-native/cluster-api-provider-nutanix) +export CAAPH_VERSION := $(shell cd hack/third-party/caaph && GOWORK=off go list -m -f '{{ .Version }}' sigs.k8s.io/cluster-api-addon-provider-helm) # Leave Nutanix credentials empty here and set it when creating the clusters .PHONY: clusterctl.init diff --git a/make/go.mk b/make/go.mk index 4caa37116..fb6d63e51 100644 --- a/make/go.mk +++ b/make/go.mk @@ -137,9 +137,9 @@ endif .PHONY: lint.% lint.%: ## Runs golangci-lint for a specific module lint.%: ; $(info $(M) linting $* module) - $(if $(filter-out root,$*),cd $* && )golines -w $$(go list -tags e2e ./... | grep -v external | sed "s|^$$(go list -m)|.|") + $(if $(filter-out root,$*),cd $* && )golines -w $$(GOWORK=off go list -tags e2e ./... | grep -v external | sed "s|^$$(GOWORK=off go list -m)|.|") $(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE) - $(if $(filter-out root,$*),cd $* && )golines -w $$(go list -tags e2e ./... | grep -v external | sed "s|^$$(go list -m)|.|") + $(if $(filter-out root,$*),cd $* && )golines -w $$(GOWORK=off go list -tags e2e ./... | grep -v external | sed "s|^$$(GOWORK=off go list -m)|.|") .PHONY: mod-tidy mod-tidy: ## Run go mod tidy for all modules diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index a0c015425..7014627df 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -200,6 +200,7 @@ func getFilePathsToCAPICRDs() []string { func getModulePath(moduleDir, moduleName string) string { cmd := exec.Command("go", "list", "-m", "-f", "{{ .Dir }}", moduleName) cmd.Dir = moduleDir + cmd.Env = append(cmd.Env, "GOWORK=off") out, err := cmd.CombinedOutput() if err != nil { // We include the combined output because the error is usually From 33be768366de6bf04a7165ae858d38c68b65564c Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Fri, 10 May 2024 09:57:29 -0700 Subject: [PATCH 2/2] fixup! build: Make module-relative "go list -m" compatible with GOWORK Append to, rather than replace environment --- test/helpers/envtest.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 7014627df..70b44b087 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -8,6 +8,7 @@ import ( "context" "errors" "fmt" + "os" "os/exec" "path/filepath" goruntime "runtime" @@ -200,7 +201,7 @@ func getFilePathsToCAPICRDs() []string { func getModulePath(moduleDir, moduleName string) string { cmd := exec.Command("go", "list", "-m", "-f", "{{ .Dir }}", moduleName) cmd.Dir = moduleDir - cmd.Env = append(cmd.Env, "GOWORK=off") + cmd.Env = append(os.Environ(), "GOWORK=off") out, err := cmd.CombinedOutput() if err != nil { // We include the combined output because the error is usually