Skip to content
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

Update gengo to use go mod. #178

Merged
merged 5 commits into from
May 18, 2020
Merged

Conversation

n3wscott
Copy link
Contributor

@n3wscott n3wscott commented May 5, 2020

As a replacement for lavalamp#1 and #144.

Fixes #143

The move to go 1.13 seems to have solved the previous issues found in go mod 1.12.

Signed-off-by: Scott Nichols [email protected]

Signed-off-by: Scott Nichols <[email protected]>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 5, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @n3wscott!

It looks like this is your first PR to kubernetes/gengo 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/gengo has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 5, 2020
@k8s-ci-robot k8s-ci-robot requested review from sttts and wojtek-t May 5, 2020 20:45
@n3wscott
Copy link
Contributor Author

n3wscott commented May 5, 2020

/retest

not sure how to get travis to run again.

@k8s-ci-robot
Copy link
Contributor

@n3wscott: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

not sure how to get travis to run again.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@n3wscott n3wscott closed this May 5, 2020
@n3wscott n3wscott reopened this May 5, 2020
Signed-off-by: Scott Nichols <[email protected]>
@n3wscott n3wscott closed this May 5, 2020
@n3wscott n3wscott reopened this May 5, 2020
@n3wscott
Copy link
Contributor Author

n3wscott commented May 5, 2020

Looks ready for test (if there are prow tests), travis passed now.

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

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

I'd love to keep this repo 100% shell-free :/

Is there any alternative to adding this? @liggitt might have an idea?

Copy link
Member

Choose a reason for hiding this comment

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

I like the approach of super-minimal makefiles (e.g. one-line target definitions, no external file includes) that just call go commands, e.g.:

make test == go test ./…
make deps == go mod tidy && go mod vendor

It technically is still shell-adjacent, but with those two rules it tends to be less of a dumping ground for crazy stuff.

Also, is it necessary to vendor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed to vendor but I think it was originally, I can double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a fake vendor directory does not work in go 1.14, it confuses go mod to only look in vendor and not the cache. I moved the fake package to testdata.

go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
hack/tools.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 7, 2020
@liggitt
Copy link
Member

liggitt commented May 7, 2020

I got it to work! I added a replace directive to allow it to find the sub-module.

This should get trimmed off when something deps on this package.

That still seems like it shouldn't be necessary. I'd expect test data to be completely isolated from the dependencies of the module.

See https://github.com/kubernetes-sigs/clientgofix/blob/v0.3.0/pkg/fix_test.go#L38-L42 for an example of exercising various $GOPATH/module vendor/no-vendor scenarios in test cases

@n3wscott
Copy link
Contributor Author

n3wscott commented May 7, 2020

I got it to work! I added a replace directive to allow it to find the sub-module.
This should get trimmed off when something deps on this package.

That still seems like it shouldn't be necessary. I'd expect test data to be completely isolated from the dependencies of the module.

See https://github.com/kubernetes-sigs/clientgofix/blob/v0.3.0/pkg/fix_test.go#L38-L42 for an example of exercising various $GOPATH/module vendor/no-vendor scenarios in test cases

but the point of this test is that there is a package that is out of tree that the test is solving for, so go mod needs to know where to look. Previously it looked in vendor as that is a magic extension of $GOPATH, but that option is not available for go 1.14 as the existence of a vendor dir will limit the $GOPATH to only ./vendor by default. The replace directly allows go mod to locate the package in ./testdata.

@n3wscott
Copy link
Contributor Author

n3wscott commented May 7, 2020

Here is the test that uses the package fake/dep

if _, err := b.importBuildPackage("fake/dep"); err != nil {

go mod also does not see this as an import because package fake/dep is not used in the go code, only this test call. So this means it only needs to replace to point to a local go.mod file.

Without the replace line, the test fails:

    TestImportBuildPackage: local_parse_test.go:26: unable to import "fake/dep": package fake/dep is not in GOROOT (/usr/local/Cellar/go/1.14.2_1/libexec/src/fake/dep)
--- FAIL: TestImportBuildPackage (0.04s)

This is expected because of the vendor gotchyas with go 1.14

@n3wscott
Copy link
Contributor Author

Ping on this. RFAL

@lavalamp
Copy link
Member

I'm OK with this. fake is only in the replace directives, not in the e.g. go.sum file. Not vendoring makes this much more palatable :)

Jordan, any more thoughts?

@liggitt
Copy link
Member

liggitt commented May 12, 2020

I really don't want fake test modules or dependencies expressed in the go.mod file downstreams of this repo will be consuming. I added a commit to https://github.com/liggitt/kubernetes-gengo/commits/move-go-mod which lets us run this test scenario without a replace in the actual go.mod

@lavalamp
Copy link
Member

lavalamp commented May 12, 2020 via email

@n3wscott
Copy link
Contributor Author

ok thanks @liggitt I merged your update into this PR to drop the replace.

@lavalamp
Copy link
Member

/lgtm
/approve

Thanks!!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 18, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, n3wscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 18, 2020
@k8s-ci-robot k8s-ci-robot merged commit fb547a1 into kubernetes:master May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update for go modules
4 participants