Operator-sdk: Panic when generating api: invalid memory address or nil pointer dereference

Created on 14 Jul 2019  Â·  7Comments  Â·  Source: operator-framework/operator-sdk

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: 560208dc998de497bbf59fea1b63426aec430934

  • 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.

kinbug

Most helpful comment

@mogren I had similar problem.

Just make sure that you have properly set GOROOT env variable

All 7 comments

@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!

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!

@mogren I had similar problem.

Just make sure that you have properly set GOROOT env variable

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…

+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?

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).

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 https://github.com/operator-framework/operator-sdk/issues/1545#issuecomment-500982788

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flickerfly picture flickerfly  Â·  5Comments

camilamacedo86 picture camilamacedo86  Â·  4Comments

smiklosovic picture smiklosovic  Â·  4Comments

nrvnrvn picture nrvnrvn  Â·  5Comments

ffoysal picture ffoysal  Â·  3Comments