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

Can not generate projects that uses go module #12

Closed
StrongMonkey opened this issue Aug 21, 2019 · 6 comments
Closed

Can not generate projects that uses go module #12

StrongMonkey opened this issue Aug 21, 2019 · 6 comments

Comments

@StrongMonkey
Copy link

It used to work with a project that set GOPATH properly. But now if a project has enabled go module, generating doc will fail.

Step to reproduce:

  1. git clone https://github.com/rancher/rio
  2. refdocs -config ./apidocs/doc-config.json -api-dir "github.com/rancher/rio/pkg/apis/" -out-file ./api-docs.md --template-dir ./apidocs

It will fail

I0821 13:39:55.847585   13796 main.go:123] parsing go packages in directory github.com/rancher/rio/pkg/apis/
W0821 13:39:57.522517   13796 parse.go:224] Ignoring directory github.com/rancher/rio/pkg/apis/: unable to import "github.com/rancher/rio/pkg/apis/": go/build: importGo github.com/rancher/rio/pkg/apis/: exit status 1
go: finding github.com/rancher/rio/pkg/apis latest
go: finding github.com/rancher/rio/pkg latest
can't load package: package github.com/rancher/rio/pkg/apis: unknown import path "github.com/rancher/rio/pkg/apis": cannot find module providing package github.com/rancher/rio/pkg/apis

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x809875]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc0000df590, 0x7ffd46914291, 0x20, 0x6d, 0xc1)
	/home/daishan/go/pkg/mod/k8s.io/[email protected]/parser/parse.go:229 +0xb5
main.parseAPIPackages(0x7ffd46914291, 0x20, 0x91e136, 0x23, 0xc000145f58, 0x1, 0x1)
	/home/daishan/goprojects/gen-crd-api-reference-docs/main.go:197 +0x60
main.main()
	/home/daishan/goprojects/gen-crd-api-reference-docs/main.go:124 +0x2bb

This workflow used to work when we weren't switched to go module.

@munnerz
Copy link
Contributor

munnerz commented Nov 15, 2019

To work around this, we construct a 'fake gopath' using go mod vendor in cert-manager: https://github.com/cert-manager/website/blob/172648ac48c09c2004b5ba3049346c84b5462722/scripts/gendocs/generate

It'd be great to skip this step 😄

@StrongMonkey
Copy link
Author

Yeah, end up with the same hack...

@zhenghuiwang
Copy link

I tried to generate docs for Kubeflow Notebook Controller, but failed because it uses go module with replace statement. Tried the above work around, but it doesn't work in this case:

go.mod is

https://github.com/kubeflow/kubeflow/blob/master/components/notebook-controller/go.mod

gen-crd-api-reference-docs master !1 ?1 ❯ ./gen-crd-api-reference-docs -config="example-config.json" -api-dir="github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1" -out-file=doc.html
I0113 16:14:07.681060   13420 main.go:127] parsing go packages in directory github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1
W0113 16:14:08.137690   13420 parse.go:224] Ignoring directory github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1: unable to import "github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1": go/build: importGo github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1: exit status 1
go: finding github.com/kubeflow/kubeflow/components/notebook-controller latest
go: github.com/kubeflow/kubeflow/components/[email protected] requires
	github.com/kubeflow/kubeflow/components/[email protected]: reading https://proxy.golang.org/github.com/kubeflow/kubeflow/components/common/@v/v0.0.0-00010101000000-000000000000.mod: 410 Gone

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1422a65]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc0001cc000, 0x7ffeefbff802, 0x47, 0x94, 0xe8)
	/Users/zhenghui/go/pkg/mod/k8s.io/[email protected]/parser/parse.go:229 +0xb5
main.parseAPIPackages(0x7ffeefbff802, 0x47, 0x15427cf, 0x23, 0xc000171f10, 0x1, 0x1)
	/Users/zhenghui/github.com/ahmetb/gen-crd-api-reference-docs/main.go:201 +0x60
main.main()
	/Users/zhenghui/github.com/ahmetb/gen-crd-api-reference-docs/main.go:128 +0x2ca

@StrongMonkey
Copy link
Author

FYI, I fixed this issue by specifying the full package name in the command line.

For example,:
$ refdocs -config ./docs/doc-config.json -api-dir "github.com/rancher/gitjob/pkg/apis/gitjob.cattle.io/v1" -out-file ./api-docs.md --template-dir ./docs

I think this is how k8s.io gengo and go package works, you have to put into a path that is being imported somewhere.

@ahmetb
Copy link
Owner

ahmetb commented Dec 9, 2020

Sorry for the silence here, turns out I wasn't watching the repo. /facepalm

Yes, your $PWD has to be within the go module, and you should use the Go module path as the package name (I think). Nothing we can fix here. That's how gengo works.

@delthas
Copy link

delthas commented Jan 19, 2021

Using the full import path also works on my end. This issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants