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

Invalid memory generating openapi #1480

Closed
eguzki opened this issue May 23, 2019 · 8 comments
Closed

Invalid memory generating openapi #1480

eguzki opened this issue May 23, 2019 · 8 comments
Assignees

Comments

@eguzki
Copy link

eguzki commented May 23, 2019

Bug Report

What did you do?
Trying to generate openapi validation of CRD's, with GO111MODULE env var set to on, then I got invalid memory error:

$ pwd
/home/eguzki/data/work/redhat/git/3scale-operator3/src/github.com/3scale/3scale-operator
$ echo $GOPATH
/home/eguzki/data/work/redhat/git/3scale-operator3
$ export GO111MODULE=on
$ operator-sdk version
operator-sdk version: v0.8.0, commit: 78c472461e75e6c64589cfadf577a2004b8a26b3
$ operator-sdk generate openapi
INFO[0000] Running OpenAPI code-generation for Custom Resource group versions: [apps:[v1alpha1], capabilities:[v1alpha1], ] 
2019/05/23 15:48:18 Code for OpenAPI definitions generated
2019/05/23 15:48:30 Code for OpenAPI definitions generated
W0523 15:48:30.466793   28614 parse.go:224] Ignoring directory github.com/3scale/3scale-operator/pkg/apis: unable to import "github.com/3scale/3scale-operator/pkg/apis": go/build: importGo github.com/3scale/3scale-operator/pkg/apis: exit status 2
go: cannot find GOROOT directory: /usr/lib/golang

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

goroutine 1 [running]:
github.com/operator-framework/operator-sdk/vendor/k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc0000d6a50, 0xc0006f2090, 0x2a, 0x2, 0x2)
	src/github.com/operator-framework/operator-sdk/vendor/k8s.io/gengo/parser/parse.go:229 +0xb5
github.com/operator-framework/operator-sdk/vendor/sigs.k8s.io/controller-tools/pkg/crd/generator.(*Generator).Do(0xc00090f5b0, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/vendor/sigs.k8s.io/controller-tools/pkg/crd/generator/generator.go:126 +0x3ac
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*CRD).CustomRender(0xc0001f1a20, 0x20ca420, 0x35d3b08, 0x7f84c339d0d8, 0xc0001f1a20, 0x1)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/crd.go:122 +0x868
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doRender(0xc00090fc90, 0xc0006f2030, 0x2d, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0003c4e41, 0x21, ...)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:228 +0x16c
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doFile(0xc00090fc90, 0x204f260, 0xc0001f1a20, 0x40c0b8, 0xb0)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:198 +0x230
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).Execute(0xc00090fc90, 0xc00090fbc0, 0xc00090fad0, 0x1, 0x1, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:163 +0x103
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.OpenAPIGen(0xc0003be300, 0x1d32bcb)
	src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil/openapi.go:86 +0xa21
github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate.openAPIFunc(0xc00055cc80, 0x35d3b08, 0x0, 0x0, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate/openapi.go:55 +0x11f
github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra.(*Command).execute(0xc00055cc80, 0x35d3b08, 0x0, 0x0, 0xc00055cc80, 0x35d3b08)
	src/github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra/command.go:762 +0x465
github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000028a00, 0x20535e0, 0xc0003ab700, 0x0)
	src/github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra/command.go:852 +0x2ec
github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra.(*Command).Execute(...)
	src/github.com/operator-framework/operator-sdk/vendor/github.com/spf13/cobra/command.go:800
main.main()
	src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/main.go:80 +0x4ce

Unsetting GO111MODULE, then command works

$ unset GO111MODULE
$ operator-sdk generate openapi
INFO[0000] Running OpenAPI code-generation for Custom Resource group versions: [apps:[v1alpha1], capabilities:[v1alpha1], ] 
2019/05/23 15:51:59 Code for OpenAPI definitions generated
2019/05/23 15:52:00 Code for OpenAPI definitions generated
W0523 15:52:01.436063   30232 parse.go:239] Ignoring child directory github.com/3scale/3scale-operator/pkg/apis/capabilities: No files for pkg "github.com/3scale/3scale-operator/pkg/apis/capabilities"
INFO[0004] Created deploy/crds/apps_v1alpha1_apimanager_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_api_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_binding_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_limit_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_mappingrule_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_metric_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_plan_crd.yaml 
INFO[0004] Created deploy/crds/capabilities_v1alpha1_tenant_crd.yaml 
INFO[0004] Code-generation complete.

What did you expect to see?
Same output when GO111MODULE is unset

What did you see instead? Under which circumstances?

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

Environment

  • operator-sdk version:
$ operator-sdk version
operator-sdk version: v0.8.0, commit: 78c472461e75e6c64589cfadf577a2004b8a26b3
  • go version:
$ go version
go version go1.12.5 linux/amd64
  • Kubernetes version information:
$ oc version
oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth GSSAPI Kerberos SPNEGO
  • Kubernetes cluster kind: Openshift 3.11

  • Are you writing your operator in ansible, helm, or go?
    go

Possible Solution

Additional context

@joelanford
Copy link
Member

@eguzki This line in your output is suspicious:

go: cannot find GOROOT directory: /usr/lib/golang

What is the output of running which go?

@joelanford joelanford self-assigned this May 24, 2019
@eguzki
Copy link
Author

eguzki commented May 24, 2019

I installed Go following usual steps
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

$ which go
/usr/local/go/bin/go

I do not have GOROOT env variable set

$ [ -z "$GOROOT" ] && echo "Empty" || echo "Not empty"
Empty

However:

$ go env GOROOT
/usr/local/go

@eguzki
Copy link
Author

eguzki commented May 24, 2019

Setting up GOROOT, operator-sdk generate openapi command works

$ operator-sdk generate openapi
INFO[0000] Running OpenAPI code-generation for Custom Resource group versions: [apps:[v1alpha1], capabilities:[v1alpha1], ] 
2019/05/24 10:08:16 Code for OpenAPI definitions generated
2019/05/24 10:08:31 Code for OpenAPI definitions generated
W0524 10:08:51.565937   15130 parse.go:239] Ignoring child directory github.com/3scale/3scale-operator/pkg/apis/capabilities: unable to import "github.com/3scale/3scale-operator/pkg/apis/capabilities": go/build: importGo github.com/3scale/3scale-operator/pkg/apis/capabilities: exit status 1
go: finding github.com/3scale/3scale-operator/pkg/apis/capabilities latest
go: finding github.com/3scale/3scale-operator/pkg/apis latest
go: finding github.com/3scale/3scale-operator/pkg latest
can't load package: package github.com/3scale/3scale-operator/pkg/apis/capabilities: unknown import path "github.com/3scale/3scale-operator/pkg/apis/capabilities": cannot find module providing package github.com/3scale/3scale-operator/pkg/apis/capabilities

INFO[0040] Created deploy/crds/apps_v1alpha1_apimanager_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_api_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_binding_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_limit_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_mappingrule_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_metric_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_plan_crd.yaml 
INFO[0040] Created deploy/crds/capabilities_v1alpha1_tenant_crd.yaml 
INFO[0040] Code-generation complete.

With some weird warning, though, about can't load package: package github.com/3scale/3scale-operator/pkg/apis/capabilities, but that package exists

$ ls $GOPATH/src/github.com/3scale/3scale-operator/pkg/apis/capabilities
v1alpha1

anyway, this is fine because openapi validation yaml is generated for that package github.com/3scale/3scale-operator/pkg/apis/capabilities as well

@joelanford
Copy link
Member

@estroz Is the can't load package: package github.com/3scale/3scale-operator/pkg/apis/capabilities error related to #1401. If so, I think that warning can be safely ignored.

@eguzki It looks like you got things working? Was the fix to explicitly set GOROOT to /usr/local/go?

@estroz
Copy link
Member

estroz commented May 24, 2019

@joelanford yes this is the error #1401 fixes.

@estroz
Copy link
Member

estroz commented May 24, 2019

@eguzki that is quite strange, since you should not need to set GOROOT unless you're using multiple go versions. I don't think this is an SDK-related issue but I will test this with your go version.

@eguzki
Copy link
Author

eguzki commented May 27, 2019

The command is working if I any of these actions are performed, failing otherwise:

  • unset GO111MODULE en var
  • set GOROOT

I am not using multiple Go versions.

It is no longer a blocking issue. Just an issue for you to know.

Thanks @joelanford @estroz

@lilic
Copy link
Member

lilic commented May 27, 2019

@eguzki Closing as you found the solution and we haven't seen anyone else run into it. Feel free to open a new issue if you run into any other problems. Thanks!

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

4 participants