Skip to content

Panic when generating api: invalid memory address or nil pointer dereference #1675

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

Closed
mogren opened this issue Jul 14, 2019 · 7 comments
Closed
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@mogren
Copy link

mogren commented Jul 14, 2019

Bug Report

What did you do?
Tried to generate a new API using the latest operator-framework sdk. The project was built using v0.0.7, so it's about time to update. Ran the following command in the root directory:

> operator-sdk add api --api-version=apiextensions.k8s.io/v1beta1 --kind=ENIConfig

What did you expect to see?
All files I need generated in pkg/apis/

What did you see instead? Under which circumstances?

IINFO[0000] Generating api version apiextensions.k8s.io/v1beta1 for kind ENIConfig.
INFO[0000] Created pkg/apis/apiextensions/group.go
INFO[0001] Created pkg/apis/apiextensions/v1beta1/eniconfig_types.go
INFO[0001] Created pkg/apis/addtoscheme_apiextensions_v1beta1.go
INFO[0001] Created pkg/apis/apiextensions/v1beta1/register.go
INFO[0001] Created pkg/apis/apiextensions/v1beta1/doc.go
INFO[0001] Created deploy/crds/apiextensions_v1beta1_eniconfig_cr.yaml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x18e62b5]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc000252410, 0xc0002c01b0, 0x2a, 0x2, 0x2)
	pkg/mod/k8s.io/[email protected]/parser/parse.go:229 +0xb5
sigs.k8s.io/controller-tools/pkg/crd/generator.(*Generator).Do(0xc0006dd760, 0x0, 0x0)
	pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/generator/generator.go:126 +0x3ac
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*CRD).CustomRender(0xc00015c420, 0x2d12400, 0x401bc80, 0x47488f8, 0xc00015c420, 0x1)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/crd.go:102 +0x27e
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doRender(0xc0006ddcf8, 0xc000671580, 0x34, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00034bf80, 0x21, ...)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:222 +0x16c
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doFile(0xc0006ddcf8, 0x2c97e00, 0xc00015c420, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:192 +0x230
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).Execute(0xc0006ddcf8, 0xc00067fc68, 0xc0006ddc98, 0x6, 0x6, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:157 +0x103
github.com/operator-framework/operator-sdk/cmd/operator-sdk/add.apiRun(0xc0003faf00, 0xc0004a6780, 0x0, 0x2, 0x0, 0x0)
	src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/add/api.go:118 +0x542
github.com/spf13/cobra.(*Command).execute(0xc0003faf00, 0xc0004a6700, 0x2, 0x2, 0xc0003faf00, 0xc0004a6700)
	pkg/mod/github.com/spf13/[email protected]/command.go:762 +0x465
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003faa00, 0x2c9b300, 0xc000315e00, 0x0)
	pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
	pkg/mod/github.com/spf13/[email protected]/command.go:800
main.main()
	src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/main.go:85 +0x50f

Environment

  • operator-sdk version:

operator-sdk version: v0.9.0, commit: 560208d

  • go version:

go version go1.12.6 darwin/amd64

  • Kubernetes version information:

Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-20T04:51:35Z", GoVersion:"go1.12.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.7-eks-c57ff8", GitCommit:"c57ff8e35590932c652433fab07988da79265d5b", GitTreeState:"clean", BuildDate:"2019-06-07T20:43:03Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}

  • Kubernetes cluster kind: EKS

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

In go.

Additional context

The project is in $GOPATH/src and has GO111MODULE=on set. The error looks similar to the one mentioned in #1480, but I thought go modules was supposed to work with v0.9.0? #1432 is also related.

eniconfigs_v1alpha1_eniconfig_cr.yaml content:

apiVersion: apiextensions.k8s.io/v1beta1
kind: ENIConfig
metadata:
  name: example-eniconfig
spec:
  # Add fields here
  size: 3

eniconfigs_v1alpha1_eniconfig_crd.yaml is empty.

@lilic lilic added the kind/bug Categorizes issue or PR as related to a bug. label Jul 15, 2019
@lilic
Copy link
Member

lilic commented Jul 15, 2019

@mogren thanks for reporting this, we will look into this. I can't seem to reproduce this locally, for me it works fine. Does this happen always, or under certain conditions? Thanks!

@lilic
Copy link
Member

lilic commented Jul 15, 2019

Things that are useful information are:

  • what steps did you execute before this
  • what path is your operator in
  • what did you use as dep manager

thanks!

@snowerem
Copy link

@mogren I had similar problem.

Just make sure that you have properly set GOROOT env variable

@slaperche-scality
Copy link

slaperche-scality commented Jul 15, 2019

Hi,

I'm able to reproduce the issue by following the README (just had to add --repo to the new command to avoid the Error: dependency manager "modules" requires the flag --repo to be set if the working directory is not in $GOPATH/src. See "operator-sdk new -h").

% mkdir -p $HOME/projects/example-inc/
% cd $HOME/projects/example-inc/
% export GO111MODULE=on
% operator-sdk new app-operator --repo=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.
% cd app-operator
% 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[0000] Created pkg/apis/app/v1alpha1/appservice_types.go
INFO[0000] Created pkg/apis/addtoscheme_app_v1alpha1.go
INFO[0000] Created pkg/apis/app/v1alpha1/register.go
INFO[0000] Created pkg/apis/app/v1alpha1/doc.go
INFO[0000] 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=0xce6865]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc000374a50, 0xc000735400, 0x15, 0x2, 0x2)
        pkg/mod/k8s.io/[email protected]/parser/parse.go:229 +0xb5
sigs.k8s.io/controller-tools/pkg/crd/generator.(*Generator).Do(0xc00079b760, 0x0, 0x0)
        pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/generator/generator.go:126 +0x3ac
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*CRD).CustomRender(0xc0000c9ad0, 0x21123c0, 0x3417f80, 0x7f491aba56f0, 0xc0000c9ad0, 0x1)
        src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/crd.go:102 +0x27e
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doRender(0xc00079bcf8, 0xc0003d36e0, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0005e3680, 0xc, ...)
        src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:222 +0x16c
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doFile(0xc00079bcf8, 0x20981c0, 0xc0000c9ad0, 0x0, 0x0)
        src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:192 +0x230
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).Execute(0xc00079bcf8, 0xc00079bc68, 0xc00079bc98, 0x6, 0x6, 0x0, 0x0)
        src/github.com/operator-framework/operator-sdk/internal/pkg/scaffold/scaffold.go:157 +0x103
github.com/operator-framework/operator-sdk/cmd/operator-sdk/add.apiRun(0xc00056f900, 0xc00000d1e0, 0x0, 0x2, 0x0, 0x0)
        src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/add/api.go:118 +0x542
github.com/spf13/cobra.(*Command).execute(0xc00056f900, 0xc00000d180, 0x2, 0x2, 0xc00056f900, 0xc00000d180)
        pkg/mod/github.com/spf13/[email protected]/command.go:762 +0x465
github.com/spf13/cobra.(*Command).ExecuteC(0xc00056ec80, 0x209b5e0, 0xc00025b100, 0x0)
        pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
        pkg/mod/github.com/spf13/[email protected]/command.go:800
main.main()
        src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/main.go:85 +0x50f

Some contextual info:

% go version
go version go1.12.7 linux/amd64
% operator-sdk version
operator-sdk version: v0.9.0, commit: 560208dc998de497bbf59fea1b63426aec430934
% echo $GOPATH
/home/sylvain/.golang
% pwd
/home/sylvain/projects/example-inc/app-operator

Edit: just saw the comment of snowerem: indeed setting GOROOT does the trick.
I installed Go from my Linux distribution repository, maybe there is a packaging bug here. Nevertheless, panic'ing on a missing environment variable seems a bit harsh…

@NicolasT
Copy link

+1, setting GOROOT to /usr/lib/golang on my Fedora system (Go installed from system packages) seems to resolve this. Even though I believe one isn't supposed to (be required to) set GOROOT at all?

@slaperche-scality
Copy link

slaperche-scality commented Jul 15, 2019

Using Archlinux here, and it seems like setting GOROOT was removed (see https://bugs.archlinux.org/task/38597), the issue was motivated by https://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really

And indeed:

% echo $GOROOT
% go env GOROOT
/usr/lib/go
% whereis go
go: /usr/bin/go /usr/lib/go

Seems like relying on the environment variable is not the way to go (no pun intended).

@lilic
Copy link
Member

lilic commented Jul 15, 2019

Even though I believe one isn't supposed to (be required to) set GOROOT at all?

this is due to a problem in gengo as described in issue #1545 (comment)

Closing as the issue was resolved, thanks @snowerem for the solution!

@lilic lilic closed this as completed Jul 15, 2019
johananl added a commit to johananl/dotfiles that referenced this issue Jul 29, 2019
operator-sdk breaks when this is not set.
operator-framework/operator-sdk#1675
skitt added a commit to skitt/submariner that referenced this issue Aug 9, 2019
This works around
operator-framework/operator-sdk#1675

Signed-off-by: Stephen Kitt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

5 participants