-
Notifications
You must be signed in to change notification settings - Fork 51
Add go.work to deal with multi module dependencies #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/... | ||
fmount marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| .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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still want this even though we don't use it anymore? (just checking, I don't have a strong opinion)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given it's an isolated target and we don't call it explicitly, for development purposes it's good to have it here in case you're fighting with the go dependencies model. I added it under "Development", so you can see it in the right column (see |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| go 1.18 | ||
|
|
||
| use ( | ||
| . | ||
| ./api | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use the Make
exportconstruct so that it is present in all the executions?That would save us from adding GOWORK everywhere in the
MakefileUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'm properly following you here, but as per [1] (if it lands) I can remove all the
GOWORK=$(GOWORK)occurrences in theMakefileand just haveGOWORK ?= offat the top of the file as you previously suggested.Then, if you run something like:
you end up seeing something like [2], but if you run:
(or just
make govet) you'll see something like [3].IMO this would simplify a lot the
Makefileand we don't have to deal w/ that variable unless we would like to set it toon.@Akrog does this make sense?
[1] openstack-k8s-operators/openstack-k8s-operators-ci#56
[2] https://paste.opendev.org/show/bLGg1Dx7D4ueNmqIT5kQ/
[3] https://paste.opendev.org/show/b48LCNwZFoOk3DdPKraI/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just add:
Then you don't need to add
GOWORK=$(GOWORK)anywhere in this file.And then we you want to use the go workspace you can do:
And it will use the current go workspace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only point here is that we can avoid
export GOWORK := $(GOWORK)if [1] lands.However, there isn't much change in how
govet.shand the other scripts are called, I guess the only thing we should take care is documenting you have toGOWORK= make build(before this change you didn't have to).If we combine this change with [1] we can't just avoid the
exportdirective (which defaults tooffbecause of the CI execution) and keep the user experience as it is (and in line with the other operators).[1] openstack-k8s-operators/openstack-k8s-operators-ci#56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think everything in
Makefileshould not use the go workspace by default, That way build and run also ignores it unless explicitly requested with theGOWORK=.I'm thinking about leftover
go.workreplaces after testing a PR and then forgetting about it and doingmake buildand getting all kinds of issues.I believe it is less likely to forget adding the
GOWORK=when we are working with dependencies than the other way around.The documentation PR already includes the
GOWORK=when using external dependencies.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, tbh I didn't have a strong opinion but as you mentioned, it's good making sure that people understand how to explicitly turn it on instead of messing with potential
go.workchanges (that would end up "working on the laptop").Being that said, I added the
exportdirective in the last iteration.Thank you, sounds good!