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

operator-sdk generate crds command fails with panic: runtime error: invalid memory address or nil pointer dereference #3336

Closed
shevchyk-aa opened this issue Jul 2, 2020 · 2 comments

Comments

@shevchyk-aa
Copy link

Bug Report

What did you do?
operator-sdk new test-op
cd test-op/
operator-sdk add api --api-version=some.org/v1 --kind=SomeApp
operator-sdk add controller --api-version=some.org/v1 --kind=SomeApp

vi pkg/apis/some/v1/someapp_types.go

Replace definition of SomeAppSpec with following
type SomeAppSpec struct {
Parent struct {
Child string `json:"child"`
} `json:"parent"`
}

operator-sdk generate crds

What did you expect to see?
Updated CRD with struct like:
parent:
child: "some_value"

What did you see instead? Under which circumstances?
Panic with stack trace:

$ operator-sdk generate crds
INFO[0000] Running CRD generator.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x18e8f5c]

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc000bdef00, 0xc0008b2620, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:322 +0x9c
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc000bdef00, 0x2642ee0, 0xc0008b2620, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc0013278b0, 0xc0008b2660, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:375 +0x491
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc0013278b0, 0x2642ee0, 0xc0008b2660, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc00024a0a0, 0xc0008b2200, 0xc00089c080, 0xb)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:174 +0x321
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc000bdeae0, 0x0, 0x0, 0xc00089c080, 0xb)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:99 +0x9e
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc000bdeae0, 0xc0008b29e0, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:220 +0x1b1
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc000bdeae0, 0x2642aa0, 0xc0008b29e0, 0x1f)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:154 +0x2e9
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc0013282a8, 0xc0008b2aa0, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:375 +0x491
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc0013282a8, 0x2642ee0, 0xc0008b2aa0, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc00024a0a0, 0xc0008b2200, 0xc00089c120, 0x7)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:174 +0x321
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0xc00024a0a0, 0xc0008b2200, 0xc00089c120, 0x7)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:186 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0xc00024a0a0, 0xc00054e3ae, 0x8, 0xc00089c120, 0x7, 0x0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/spec.go:85 +0x615
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate(0x0, 0x0, 0x0, 0xc000376a80, 0x1, 0x1, 0xc00024a050, 0x2603d00, 0x2605ae0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/gen.go:108 +0x356
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0xc000410680, 0xc00064fce0)
pkg/mod/sigs.k8s.io/[email protected]/pkg/genall/genall.go:171 +0x15e
github.com/operator-framework/operator-sdk/internal/generate/gen.(*cachedRunner).Run(0xc00064fda0, 0xc00064fce0, 0x3, 0x3, 0x383e160, 0xc00054f220)
src/github.com/operator-framework/operator-sdk/internal/generate/gen/generator.go:150 +0x86
github.com/operator-framework/operator-sdk/internal/generate/crd.Generator.generateGo(0x0, 0x0, 0x224d339, 0xb, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
src/github.com/operator-framework/operator-sdk/internal/generate/crd/crd.go:149 +0x53f
github.com/operator-framework/operator-sdk/internal/generate/crd.Generator.Generate(0x0, 0x0, 0x224d339, 0xb, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
src/github.com/operator-framework/operator-sdk/internal/generate/crd/crd.go:111 +0x1b5
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.CRDGen(0x22361f3, 0x2, 0x2238100, 0x4)
src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil/crds.go:38 +0x11e
github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate.crdsFunc(0xc000617b80, 0x383c3a8, 0x0, 0x0, 0x0, 0x0)
src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate/crds.go:60 +0x4b
github.com/spf13/cobra.(*Command).execute(0xc000617b80, 0x383c3a8, 0x0, 0x0, 0xc000617b80, 0x383c3a8)
pkg/mod/github.com/spf13/[email protected]/command.go:842 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc000608000, 0x2603f60, 0xc0004df700, 0x0)
pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli.RunLegacy(0xc0000a4000, 0x0)
src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli/legacy.go:49 +0x11b
main.main()
src/github.com/operator-framework/operator-sdk/cmd/operator-sdk/main.go:43 +0x92

Environment

  • operator-sdk version:

$ operator-sdk version
operator-sdk version: "v0.18.2", commit: "f059b5e17447b0bbcef50846859519340c17ffad", kubernetes version: "v1.18.2", go version: "go1.13.10 linux/amd64"

  • go version:

"go1.13.10 linux/amd64"

  • Kubernetes version information:

kubernetes version: "v1.18.2"

  • Kubernetes cluster kind:

Local, created with kubeadm

  • Are you writing your operator in ansible, helm, or go?
    Go
@joelanford
Copy link
Member

@shevchyk-aa That appears to be an issue with how controller-tools handles the anonymous parent struct.

As a workaround, you can get the desired behavior by declaring parent as a separate struct:

type SomeAppSpec struct {
    Parent Parent `json:"parent"`
}

type Parent struct {
    Child string `json:"child"`
}

@joelanford
Copy link
Member

It appears anonymous structs are specifically not allowed, and the logic currently panics.

This PR (still open) will help clarify the issue by ensuring a proper error message is returned in this situation: kubernetes-sigs/controller-tools#415

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

2 participants