operator-sdk: panic: runtime error: index out of range, goroutine 89 [running]

Hello, I got this problem when I use operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService 1564563911787

I just follow the ReadMe, Quick Start. 1564564168590

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

Update: I can’t reproduce the above runtime error anymore.

$ operator-sdk version
operator-sdk version: v0.10.0, commit: ff80b17737a6a0aade663e4827e8af3ab5a21170

// Inside $GOPATH/src
$ pwd
/Users/haseeb/work/go-space/src/github.com/example-inc

$ GO111MODULE=on operator-sdk new app-operator
INFO[0000] Creating new Go operator 'app-operator'.
INFO[0000] Created go.mod
INFO[0000] Created tools.go
INFO[0000] Created cmd/manager/main.go
INFO[0000] Created build/Dockerfile
INFO[0000] Created build/bin/entrypoint
INFO[0000] Created build/bin/user_setup
INFO[0000] Created deploy/service_account.yaml
INFO[0000] Created deploy/role.yaml
INFO[0000] Created deploy/role_binding.yaml
INFO[0000] Created deploy/operator.yaml
INFO[0000] Created pkg/apis/apis.go
INFO[0000] Created pkg/controller/controller.go
INFO[0000] Created version/version.go
INFO[0000] Created .gitignore
INFO[0000] Validating project
go: finding github.com/operator-framework/operator-sdk master
INFO[0004] Project validation successful.
INFO[0004] Project creation complete.

// GO111MODULE=off inside $GOPATH now results in the correct error
$ cd app-operator/
$ GO111MODULE=off operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
FATA[0000] dependency manager "modules" requires working directory to be in $GOPATH/src and GO111MODULE=on, or outside of $GOPATH/src and GO111MODULE="on", "auto", or unset. More info: https://github.com/operator-framework/operator-sdk/blob/master/doc/user-guide.md#go-modules

$ GO111MODULE=on operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService.
INFO[0000] Created pkg/apis/app/group.go
INFO[0002] Created pkg/apis/app/v1alpha1/appservice_types.go
INFO[0002] Created pkg/apis/addtoscheme_app_v1alpha1.go
INFO[0002] Created pkg/apis/app/v1alpha1/register.go
INFO[0002] Created pkg/apis/app/v1alpha1/doc.go
INFO[0002] Created deploy/crds/app_v1alpha1_appservice_cr.yaml
INFO[0010] Created deploy/crds/app_v1alpha1_appservice_crd.yaml
INFO[0010] Running deepcopy code-generation for Custom Resource group versions: [app:[v1alpha1], ]
INFO[0018] Code-generation complete.
INFO[0018] Running OpenAPI code-generation for Custom Resource group versions: [app:[v1alpha1], ]
INFO[0034] Created deploy/crds/app_v1alpha1_appservice_crd.yaml
INFO[0034] Code-generation complete.
INFO[0034] API generation complete.

Same for the version that I initially tested out with operator-sdk version: v0.9.0-54-gabac23c8, commit: abac23c897b898e6fecfb2c02fe318843ae9347f.

Not entirely sure what I changed or how I managed to run add api inside $GOPATH/src with GO111MODULE=off before.

This might be a go modules related issue.

While I’m not getting the index out of range panic I do see the runtime error: invalid memory address or nil pointer dereference if I run the command inside $GOPATH/src with GO111MODULES=on:

$ operator-sdk version
operator-sdk version: v0.9.0-50-g4ca881a9, commit: 4ca881a92eb71b19d4689065ae9bf4dcf9b43331

$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService.
INFO[0000] Created pkg/apis/app/group.go
INFO[0005] Created pkg/apis/app/v1alpha1/appservice_types.go
INFO[0005] Created pkg/apis/addtoscheme_app_v1alpha1.go
INFO[0005] Created pkg/apis/app/v1alpha1/register.go
INFO[0005] Created pkg/apis/app/v1alpha1/doc.go
INFO[0005] Created deploy/crds/app_v1alpha1_appservice_cr.yaml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x18e98d5]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc0003a20a0, 0xc000542300, 0x32, 0x2, 0x2)
	pkg/mod/k8s.io/gengo@v0.0.0-20190327210449-e17681d19d3a/parser/parse.go:229 +0xb5
sigs.k8s.io/controller-tools/pkg/crd/generator.(*Generator).Do(0xc000729760, 0x0, 0x0)
	pkg/mod/sigs.k8s.io/controller-tools@v0.0.0-20190411181648-9d55346c2bde/pkg/crd/generator/generator.go:126 +0x3ac
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*CRD).CustomRender(0xc000268160, 0x2cff980, 0x4000ca0, 0x73f29d0, 0xc000268160, 0x1)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/crd.go:102 +0x27e
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doRender(0xc000729cf8, 0xc0000b2270, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000058211, 0x29, ...)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:222 +0x16c
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doFile(0xc000729cf8, 0x2c85720, 0xc000268160, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:192 +0x230
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).Execute(0xc000729cf8, 0xc000729c68, 0xc000729c98, 0x6, 0x6, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:157 +0x103
github.com/operator-framework/operator-sdk/cmd/operator-sdk/add.apiRun(0xc000570280, 0xc00000cc20, 0x0, 0x2, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/cmd/operator-sdk/add/api.go:118 +0x542
github.com/spf13/cobra.(*Command).execute(0xc000570280, 0xc00000cbc0, 0x2, 0x2, 0xc000570280, 0xc00000cbc0)
	pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:762 +0x465
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000f1b80, 0x2c88c00, 0xc000321e00, 0x0)
	pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
	pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:800
main.main()
	/Users/haseeb/work/module-projects/operator-sdk/cmd/operator-sdk/main.go:85 +0x50f

With GO111MODULES=off inside $GOPATH/src or running the command outside of $GOPATH/src there is no issue.

Debugging this a bit more with the master branch to confirm.