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

go modules support #57

Closed
tcolgate opened this issue Oct 3, 2018 · 22 comments
Closed

go modules support #57

tcolgate opened this issue Oct 3, 2018 · 22 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@tcolgate
Copy link

tcolgate commented Oct 3, 2018

The generators insist on putting generated code into the GOPATH, rather than relative to the local directory the tool is running in.

For the simplest use case of generating code for a single controller, it seems like it should be possible to support building/generating outsisde of a GOPATH, using go modules. It's not clear to me what other use cases this tool supports, and/or if using it outside of GOPATH makes sense (hopefully it can, as I think GOPATH's long term support is in question)

@nikhita
Copy link
Member

nikhita commented Dec 12, 2018

/cc @sttts

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 12, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 11, 2019
@nikhita
Copy link
Member

nikhita commented Apr 11, 2019

Go modules support is now in.

/close

@k8s-ci-robot
Copy link

@nikhita: Closing this issue.

In response to this:

Go modules support is now in.

/close

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.

@christopherhein
Copy link
Member

@nikhita is there a specific way to use this with gomodules… noticed sample-controller doesn't work out of the box with it… see kubernetes/sample-controller#47

@parhamdoustdar
Copy link

Hi @nikhita, are there any instructions for using the code-generator package when installed as a module?

Right now, i've done go get -m k8s.io/code-generator, but I'm not sure how to proceed.

@sttts
Copy link
Contributor

sttts commented Jun 3, 2019

Compare https://github.com/kubernetes/sample-apiserver#when-using-go-111-modules. go mod vendor downloads what you need.

@parhamdoustdar
Copy link

Thanks a lot for referring me to that page, I figured what I was doing wrong. I needed to create a tools.go file which would import the k8s.io/code-generator package, so that it would end up in my vendor directory when I did go mod vendor.

Thanks for the help!

@mkmik
Copy link

mkmik commented Jul 16, 2019

@parhamdoustdar I tried but it doesn't vendor the hack directory (because they don't contain .go files?)

F0716 10:59:28.908622   89340 deepcopy.go:131] Failed loading boilerplate: open /Users/mkm/go/src/k8s.io/code-generator/hack/boilerplate.go.txt: no such file or directory
$ ls -d vendor/k8s.io/code-generator
vendor/k8s.io/code-generator
$ ls -d vendor/k8s.io/code-generator/hack
ls: cannot access 'vendor/k8s.io/code-generator/hack': No such file or directory

any idea how to trick go mod vendor to also include that dir?

@mkmik
Copy link

mkmik commented Jul 16, 2019

hmm, apparently even if I make that dir available in the vendor dir, the scripts will try to use the one in the GOPATH

@parhamdoustdar
Copy link

I also don't have the vendor/k8s.io/code-generator/hack directory. However, I copied the update-codegen.sh and verify-codegen.sh into my project's hack directory. You can see the directory here.

@sttts
Copy link
Contributor

sttts commented Jul 16, 2019

Those scripts in the hack dir are not for consumers, but developers of k8s.io/code-generator. You only need those at the root package.

@mkmik
Copy link

mkmik commented Jul 16, 2019

then I guess I'm calling generate-groups.sh wrong because it fails if those files can't be found.

In all fairness, I have no idea what I'm doing, I inherited a project that was calling:

//go:generate ../../../../vendor/k8s.io/code-generator/generate-groups.sh all github.com/bitnami-labs/sealed-secrets/pkg/client github.com/bitnami-labs/sealed-secrets/pkg/apis sealed-secrets:v1alpha1

and it fails with F0716 10:59:28.908622 89340 deepcopy.go:131] Failed loading boilerplate: open /Users/mkm/go/src/k8s.io/code-generator/hack/boilerplate.go.txt: no such file or directory

@sttts should I do something differently?

@sttts
Copy link
Contributor

sttts commented Jul 16, 2019

@mkmik pass your own boilerplate with --go-header-file "some/other/boilerplate.go.txt

@sttts
Copy link
Contributor

sttts commented Jul 16, 2019

@mkmik
Copy link

mkmik commented Jul 16, 2019

@stts thanks! I didn't realize that template was the responsibility of the user; it seems obvious in retrospect.

would it make sense to just make the --go-header-file flag mandatory so people don't fall in the trap of ignoring this step (which accidentally works if the code-generator dep is present in the GOPATH)?

@nikhita
Copy link
Member

nikhita commented Jul 16, 2019

which accidentally works if the code-generator dep is present in the GOPATH

We intentionally default it that way, so that people won't have to use the --go-header-file unless necessary. 😬

would it make sense to just make the --go-header-file flag mandatory so people don't fall in the trap of ignoring this step

Instead of making this mandatory, I think we could improve the error message and documentation around this. As a side-note, we intend to make code-generation more module-friendly, so this problem should go away then - kubernetes/publishing-bot#196 (comment).

@mkmik
Copy link

mkmik commented Jul 16, 2019

@nikhita, thanks; yeah using module aware functions to locate the default file would do the trick.

bors bot added a commit to bitnami-labs/sealed-secrets that referenced this issue Jul 16, 2019
184: Ensure k8s.io/code-generator is vendored r=mkmik a=mkmik

and implements a hack until I figure out how to use code-generator properly (or an upstream issue is fixed), see kubernetes/code-generator#57 .

Closes #153

Co-authored-by: Marko Mikulicic <mkm@bitnami.com>
@marccarre
Copy link

@nikhita, @sttts, what is the recommended way to vendor code-generator via Go modules to also pull non-Go files, e.g. generate-groups.sh? (Apologies if already documented elsewhere, I couldn't find this.)

@alexellis
Copy link

@marccarre I noticed that you haven't had an answer on this. What did you settle on?

@marccarre
Copy link

@alexellis, sorry, this was almost two years ago and I'm afraid I can no longer remember. 😔
(Especially as I moved on to something else in the meantime.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

10 participants