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

panic: interface conversion: types.Type is *types.Alias, not *types.Named #1076

Closed
markussiebert opened this issue Oct 17, 2024 · 8 comments · Fixed by #1079
Closed

panic: interface conversion: types.Type is *types.Alias, not *types.Named #1076

markussiebert opened this issue Oct 17, 2024 · 8 comments · Fixed by #1079

Comments

@markussiebert
Copy link

markussiebert commented Oct 17, 2024

Hi,

just experiencing this issue (#1053) again:

panic: interface conversion: types.Type is *types.Alias, not *types.Named
// Generate deepcopy methodsets and CRD manifests
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../hack/boilerplate.go.txt paths=./... crd:crdVersions=v1 output:artifacts:config=../package/crds

Version:

go run sigs.k8s.io/controller-tools/cmd/controller-gen --version                                                                                                                                       
Version: v0.16.4

We are on go 1.23.1

@sbueringer
Copy link
Member

Can you please provide the entire panic stack trace?

(cc @mtardy fyi)

@markussiebert
Copy link
Author

Just tried out locally,

https://github.com/kubernetes-sigs/controller-tools/blob/main/pkg/crd/schema.go#L277

changing this line to

typeInfo := typeInfoRaw.(interface{ Obj() *types.TypeName })

fixes it

@markussiebert
Copy link
Author

15:16:12 [ .. ] go generate linux_arm64
panic: interface conversion: types.Type is *types.Alias, not *types.Named

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.namedToSchema(0x1400563c360, 0x14005704810)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:277 +0x2d4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400563c360, {0x102efc8a8, 0x14005704810})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:199 +0xec
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x1400880b638, 0x14005704828)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:435 +0x7d8
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400880b638, {0x102efc848, 0x14005704828})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:207 +0x90
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x1400880b638)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:125 +0xcc
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x140089c3d40, {0x1400038c920, {0x14005716240, 0x13}})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/parser.go:193 +0x1e8
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0x1400033b810?, {0x0?, 0x102c270f2?}, {0x14005716240?, 0x0?})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:108 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0x1400563c210, 0x1400570f720)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:263 +0x2e8
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400563c210, {0x102efc878, 0x1400570f720})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:197 +0xd0
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x1400880be18, 0x140057048e8)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:435 +0x7d8
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400880be18, {0x102efc848, 0x140057048e8})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:207 +0x90
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x1400880be18)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:125 +0xcc
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x140089c3d40, {0x1400038c920, {0x140057064a0, 0xe}})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/parser.go:193 +0x1e8
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0x1400033b810?, {0x0?, 0x102c270f2?}, {0x140057064a0?, 0x0?})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:108 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0x140027fb800, 0x1400570f900)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:263 +0x2e8
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x140027fb800, {0x102efc878, 0x1400570f900})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:197 +0xd0
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x1400880c5f8, 0x14005704a20)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:435 +0x7d8
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x1400880c5f8, {0x102efc848, 0x14005704a20})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:207 +0x90
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x1400880c5f8)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go:125 +0xcc
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x140089c3d40, {0x1400038c920, {0x140057064f0, 0x8}})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/parser.go:193 +0x1e8
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0x140089c3d40, {0x1400038c920, {0x140057064f0, 0x8}})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/parser.go:205 +0x9c
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0x140089c3d40, {{0x14003932f9e, 0x16}, {0x140057064f0, 0x8}}, 0x0)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/spec.go:93 +0x3d8
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate({0x0, 0x0, 0x0, {0x1400004e170, 0x1, 0x1}, 0x0, {0x0, 0x0}, {0x0, ...}, ...}, ...)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/crd/gen.go:182 +0x464
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0x14000169b90)
        /..some..provider../vendor/sigs.k8s.io/controller-tools/pkg/genall/genall.go:272 +0x21c
main.main.func1(0x1400017c300?, {0x140002e20c0?, 0x4?, 0x102c252d7?})
        /..some..provider../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go:176 +0x64
github.com/spf13/cobra.(*Command).execute(0x1400029ac08, {0x14000116060, 0x4, 0x4})
        /..some..provider../vendor/github.com/spf13/cobra/command.go:985 +0x834
github.com/spf13/cobra.(*Command).ExecuteC(0x1400029ac08)
        /..some..provider../vendor/github.com/spf13/cobra/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
        /..some..provider../vendor/github.com/spf13/cobra/command.go:1041
main.main()
        /..some..provider../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go:200 +0x290
exit status 2
apis/generate.go:26: running "go": exit status 1
15:16:16 [FAIL]
make: *** [go.generate] Error 1

@mtardy
Copy link
Contributor

mtardy commented Oct 17, 2024

Just tried out locally,

https://github.com/kubernetes-sigs/controller-tools/blob/main/pkg/crd/schema.go#L277

changing this line to

typeInfo := typeInfoRaw.(interface{ Obj() *types.TypeName })

fixes it

Oh it seems I didn’t hit that indeed. Maybe you can add a test for it and fix it similarly that in #1061 :)

@mtardy
Copy link
Contributor

mtardy commented Oct 17, 2024

I’ll do grep on (*types.Named) when I’m in front of a computer maybe there are some lefts that we can hit.

@mtardy
Copy link
Contributor

mtardy commented Oct 21, 2024

I’ll do grep on (*types.Named) when I’m in front of a computer maybe there are some lefts that we can hit.

After fixing this one:

$ git grep '(*types.Named)'
pkg/crd/gen.go:                 namedField, isNamed := fieldType.(*types.Named)
pkg/deepcopy/traverse.go:       if asPtr, isPtr := typeInfo.(*types.Named).Underlying().(*types.Pointer); isPtr {
pkg/deepcopy/traverse.go:       if _, isNamed := typeInfo.(*types.Named); isNamed {

Those should be not panicking as in two cases they are checking isNamed. The other maybe should be replaced with (interface { Underlying() types.Type }) since it's shared between both Named and Alias. But I'm unsure we could hit that since I'm not familiar with that area.

@sbueringer
Copy link
Member

Thx @mtardy for investigating and fixing this!

@markussiebert Can you please test if controller-gen compiled from the main branch works for you now?

@ma-ble
Copy link

ma-ble commented Oct 29, 2024

controller-gen compiles from the main branch as expected.

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

Successfully merging a pull request may close this issue.

4 participants