Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Modify the golang.mk to support go modules #74

Merged
merged 3 commits into from
Oct 7, 2019

Conversation

soorena776
Copy link
Contributor

Signed-off-by: soorena776 [email protected]

@soorena776
Copy link
Contributor Author

PTAL @jbw976 @negz

@negz
Copy link
Member

negz commented Sep 20, 2019

@soorena776 I like the direction, but I have to admit I'm fairly ignorant around how Go modules work (and also pretty bad at make). Can you provide some context around why this PR duplicates the existing library rather than updating or replacing it? I'm also curious what steps if any would be required to migrate our projects from dep to modules; my understanding is modules pick the oldest possible dependency while dep picks the newest possible?

@negz
Copy link
Member

negz commented Sep 20, 2019

Prior art: #63

@soorena776
Copy link
Contributor Author

soorena776 commented Sep 20, 2019

@negz Sorry about not providing an intro earlier! Please read below:

golang_with_modules.mk is a copy of the existing golang.mk, in which

  • go.vendor.check is renamed to go.vendor.verify, since dep check alternative is go mod verify
  • go.vendor and go.vendor.verify have been updated to use go mod instead of dep
  • go.vendor.lite has been deleted since its essentially the same as go.vendor when using go mod
  • @(DEP) target is deleted, since it's no longer needed

Since other projects are still using golang.mk, I created a new library and referenced it in the consuming project

@soorena776 soorena776 force-pushed the add_go_modules_library branch 4 times, most recently from 78e6950 to c4752a3 Compare September 25, 2019 05:49
@soorena776 soorena776 self-assigned this Sep 25, 2019
@bassam
Copy link
Member

bassam commented Sep 25, 2019

I don't think its ideal to have two golang.mk files. Any way to combine the two?

@soorena776
Copy link
Contributor Author

@bassam I can definitely combine this with the current one. The only concern there is if other repositories still want to stick with dep, and need changes in this repo

@soorena776
Copy link
Contributor Author

@bassam modified the existing golang.mk instead

Copy link
Contributor

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some work done on this in #63 that addressed modules and maintained support for dep as well. Do you believe it is insufficient for this issue? If you want to sync up on anything I did there feel free to let me know! Thanks for driving this :)

makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Show resolved Hide resolved
@soorena776
Copy link
Contributor Author

soorena776 commented Sep 26, 2019

@hasheddan Thanks for the pointer to #63. I wasn't aware of this effort (my bad in not searching existing related work) when I started this. The main difference seems to be that you tried to maintain the support for dep, whereas I am not fully convinced if it's necessary.
In addition, there are a few gotchas when using go modules that I addressed:

  • the ~/go/pkg/mod folder is created by go modules and is read only, which causes issues with the current clean up targets. this was tackled by go.writeable.mod.folder target
  • supporting manifest and code generation after removing vendor folder
  • undoing the change in go.mod when running go get command, which happens when installing tools

Please let me know what you think

@bassam
Copy link
Member

bassam commented Sep 26, 2019

I'm not sure we can switch all projects using this project all together. It might be prudent to leave dep as the default, and and support for go modules as an option GO_MODULES=1. the Crossplane projects can start with that turned on, and we can migrate other projects over time.

@soorena776
Copy link
Contributor Author

soorena776 commented Sep 26, 2019

@bassam I agree, and that is why I initially created a separate file.
I thought about adding a switch to enable go mod. The problem is that this will make the already hard-to-read golang.mk even more convoluted with conditions and an additional switch for dep. Given that once we migrate from dep we will never switch back, and there is no reason to alternate between the two in a single project over time, do you still think adding a switch makes sense? The alternative is to create a separate golang_with_modules.mk (see the first commit in this PR) and once all projects are switched just simply delete the older file.

@bassam
Copy link
Member

bassam commented Sep 26, 2019

I took a quick look at the diff and I'm not sure its that bad to support go modules and dep. I think you can contain the changes in different flavors of targets and using variables for command line switches.

I worry about the two file approach. I think it will be a a while before everyone switches to go modules, and that in the meantime we have two files to maintain.

@soorena776 soorena776 force-pushed the add_go_modules_library branch 6 times, most recently from 265bb7f to de6fd80 Compare September 26, 2019 21:38
@soorena776 soorena776 force-pushed the add_go_modules_library branch from de6fd80 to f8bd82d Compare September 26, 2019 21:55
@soorena776 soorena776 force-pushed the add_go_modules_library branch from c2bf4c2 to 7b2e1e3 Compare October 1, 2019 20:40
makelib/kubebuilder.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/kubebuilder.mk Outdated Show resolved Hide resolved
makelib/golang.mk Show resolved Hide resolved
@soorena776 soorena776 force-pushed the add_go_modules_library branch 9 times, most recently from b505f63 to e7aa21b Compare October 4, 2019 05:02
@soorena776 soorena776 requested review from bassam and muvaf October 4, 2019 17:06
makelib/golang.mk Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
makelib/golang.mk Outdated Show resolved Hide resolved
@cd $(TOOLS_HOST_DIR)/tmp-controllergen; GOPATH=$(abspath $(GO_PKG_DIR)) GO111MODULE=on GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) || $(FAIL)
@rm -fr $(TOOLS_HOST_DIR)/tmp-controllergen

@$(OK) installing controller-gen @$(CONTROLLER_GEN_VERSION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you not use the same @GO111MODULE=off approach as in golang.mk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as the comment above mentions versioned go packages do need GO111MODULE=on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about downloading the binary directly, but there is no binary distribution for this tool: https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.2.1

so we do need to build the go src and install it, by using go get

makelib/golang.mk Outdated Show resolved Hide resolved
@soorena776 soorena776 force-pushed the add_go_modules_library branch 2 times, most recently from ec7ebe5 to 106ac5d Compare October 4, 2019 19:13
@soorena776 soorena776 requested a review from bassam October 4, 2019 19:24
Copy link
Member

@bassam bassam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to test this for Multiplatform builds (try make build.all)

@soorena776 soorena776 force-pushed the add_go_modules_library branch from b169d16 to f6742d7 Compare October 4, 2019 21:08
@soorena776 soorena776 force-pushed the add_go_modules_library branch from f6742d7 to e9e0aa4 Compare October 4, 2019 21:23
@jbw976
Copy link
Member

jbw976 commented Oct 7, 2019

awesome, thank you for working through everything to make this a complete and robust solution @soorena776!

@jbw976 jbw976 merged commit a1d803f into upbound:master Oct 7, 2019
@arturrez arturrez mentioned this pull request Nov 21, 2019
@tnthornton tnthornton mentioned this pull request Jul 27, 2022
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants