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

Nested anonymous structs cause panic when generating CRDs #340

Closed
jameshochadel opened this issue Oct 11, 2019 · 4 comments
Closed

Nested anonymous structs cause panic when generating CRDs #340

jameshochadel opened this issue Oct 11, 2019 · 4 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@jameshochadel
Copy link

This issue was found while using controller-tools with Kubebuilder.

To reproduce:

Create a new Kubebuilder v2 project:

go mod init example.com/m
kubebuilder init --domain example.com --license apache2 --owner "Test Owner"
kubebuilder create api --group ship --version v1 --kind Frigate

In ./api/v1/frigate_types.go, modify FrigateSpec to be:

type FrigateSpec struct {
	NestedAnonymousStruct struct {
		SomeField string `json:"someField"`
	} `json:"nestedAnonymousStruct"`
}

And run make manifests.

Expected behavior: controller-get is fetched, and the CRDs are generated.
Actual behavior: I get the following panic:

go get sigs.k8s.io/controller-tools/cmd/[email protected]
go: finding sigs.k8s.io v0.2.1
go: finding sigs.k8s.io/controller-tools/cmd v0.2.1
go: finding sigs.k8s.io/controller-tools/cmd/controller-gen v0.2.1
/Users/james/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x15e6f4c]

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc000f9cfc0, 0xc0006d4200, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:322 +0x9c
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc000f9cfc0, 0x18f9420, 0xc0006d4200, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc0007ae1e8, 0xc0006d42a0, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:375 +0x491
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc0007ae1e8, 0x18f9420, 0xc0006d42a0, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0001ec0a0, 0xc00033a700, 0xc000974034, 0xb)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:169 +0x306
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc000f9cf30, 0x0, 0x0, 0xc000974034, 0xb)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:99 +0x9e
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc000f9cf30, 0xc0006d45c0, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:220 +0x1b1
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc000f9cf30, 0x18f8fe0, 0xc0006d45c0, 0x1f)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:154 +0x2e9
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc0007aeb38, 0xc0006d4680, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:375 +0x491
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc0007aeb38, 0x18f9420, 0xc0006d4680, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:164 +0x3a6
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(...)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0001ec0a0, 0xc00033a700, 0xc000974070, 0x7)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:169 +0x306
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0xc0001ec0a0, 0xc00033a700, 0xc000974070, 0x7)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:181 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0xc0001ec0a0, 0xc00096402e, 0x10, 0xc000974070, 0x7, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/spec.go:165 +0x61d
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate(0x5d18e4bfdb7c4c01, 0x0, 0xc0001ec050, 0x1d99100, 0xc00021aa20)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/gen.go:79 +0x1dc
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0xc0007b9080, 0xc0001ec140)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/genall/genall.go:167 +0x16f
main.main.func1(0xc000200500, 0xc0001ec140, 0x5, 0x5, 0x0, 0x0)
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:168 +0x99
github.com/spf13/cobra.(*Command).execute(0xc000200500, 0xc0000200d0, 0x5, 0x5, 0xc000200500, 0xc0000200d0)
        /Users/james/go/pkg/mod/github.com/spf13/[email protected]/command.go:762 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc000200500, 0xc0001c45c0, 0x4, 0x0)
        /Users/james/go/pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/james/go/pkg/mod/github.com/spf13/[email protected]/command.go:800
main.main()
        /Users/james/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:191 +0x2f5
make: *** [manifests] Error 2

The panic occurs whether or not the struct contains any fields. When the struct is removed, make manifests succeeds as expected.

For an example of nested anonymous structs in use, check out https://medium.com/@xcoulon/nested-structs-in-golang-2c750403a007.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 9, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 8, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants