controller-tools: controller-gen crashes in structToSchema
If RawSpec
is not set on the schemaContext
’s info *markers.TypeInfo
member, then structToSchema
will crash here.
I think the fix is probably that:
if ctx.info.RawSpec.Type != structType {
Should become:
if ctx.info.RawSpec == nil || ctx.info.RawSpec.Type != structType {
Another option is that RawSpec
should be preserved every time a new context is created with ctx.ForInfo
.
Example stacktrace:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xab448c]
goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc008d5e5a0, 0xc008b82be0, 0xc004b16fe0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:322 +0x9c
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc008d5e5a0, 0xe03480, 0xc008b82be0, 0x4f0e88)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:164 +0x374
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc008d5e5a0, 0xe03440, 0xc008b82c00, 0x1f)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:162 +0x32a
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc004b17638, 0xc008b83e20, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:375 +0x484
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc004b17638, 0xe03480, 0xc008b83e20, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:164 +0x374
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0001840f0, 0xc0001dc260, 0xc007b5fe80, 0x1a)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/parser.go:174 +0x321
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc008d5e510, 0x0, 0x0, 0xc007b5fe80, 0x1a)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:99 +0x9e
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc008d5e510, 0xc008b82480, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:220 +0x1b4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc008d5e510, 0xe03040, 0xc008b82480, 0x1f)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:154 +0x194
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc004b18030, 0xc008b82560, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:375 +0x484
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc004b18030, 0xe03480, 0xc008b82560, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:164 +0x374
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0001840f0, 0xc0001dc260, 0xc007b5fcc0, 0x14)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/parser.go:174 +0x321
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc008d5e420, 0x0, 0x0, 0xc007b5fcc0, 0x14)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:99 +0x9e
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc008d5e420, 0xc008b82720, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:220 +0x1b4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc008d5e420, 0xe03040, 0xc008b82720, 0x1f)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:154 +0x194
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc004b18a28, 0xc008b82780, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:375 +0x484
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc004b18a28, 0xe03480, 0xc008b82780, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:164 +0x374
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0001840f0, 0xc0001dc260, 0xc007b747e0, 0x10)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/parser.go:174 +0x321
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0xc0001840f0, 0xc0001dc260, 0xc007b747e0, 0x10)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/parser.go:186 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0xc0001840f0, 0xc008c0438e, 0x2a, 0xc007b747e0, 0x10, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/spec.go:85 +0x60e
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate(0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001840a0, 0xdf32c0, 0xdf32c0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/crd/gen.go:108 +0x35b
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0xc000b53200, 0xc000252ed0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/pkg/genall/genall.go:171 +0x15e
main.main.func1(0xc000171b80, 0xc000252ed0, 0x3, 0x3, 0x0, 0x0)
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/cmd/controller-gen/main.go:176 +0xa6
github.com/spf13/cobra.(*Command).execute(0xc000171b80, 0xc0000320d0, 0x3, 0x3, 0xc000171b80, 0xc0000320d0)
/home/george/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826 +0x453
github.com/spf13/cobra.(*Command).ExecuteC(0xc000171b80, 0xc0002502c0, 0x4, 0x0)
/home/george/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
/home/george/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main()
/home/george/go/pkg/mod/sigs.k8s.io/controller-tools@v0.3.0/cmd/controller-gen/main.go:200 +0x34a
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 27 (8 by maintainers)
I suspect that your approach needs re-evaluation. Hard to tell about your project specifics, yet…
I, as a Kubernetes Operator developer, publish CRD which is my own type. I do not publish external (nested) types.
While the desire to reuse third-party API definitions as opaque pass-thru objects in the operator is understandable and might work, I would step back once again to review the decision.
Inline struct type crashes latest controller-gen as of Oct-30: