Open mnencia opened 1 month ago
Please check if the panic also occurs with the published controller-gen binaries from here: https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.16.3 (compiled with Go 1.22).
Trying to figure out if this is just another occurence of: https://github.com/kubernetes-sigs/controller-tools/issues/1053 which might be then fixed via: https://github.com/kubernetes-sigs/controller-tools/pull/1061
Hi @sbueringer I have tested it, and this issue still occurs in version 0.16.3
➜ ./bin/controller-gen --version
Version: v0.16.3
➜ ./bin/controller-gen rbac:roleName=manager-role crd webhook paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xd18e792]
goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedPackage(0xc000e8c000, 0x0)
/Users/huyantian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.16.3/pkg/crd/parser.go:237 +0x52
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc000e8c000, {0x0, {0xc0015fe660, 0x1e}})
/Users/huyantian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.16.3/pkg/crd/parser.go:170 +0x5a
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc004da4480?, {0xc00086eb40?, 0xd2758f5?}, {0xc0015fe660?, 0x1e?})
/Users/huyantian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.16.3/pkg/crd/schema.go:108 +0xdb
sigs.k8s.io/controller-tools/pkg/crd.namedToSchema(0xc004da4480, 0xc000fd54d0)
Thx for checking!
Then we'll need someone to investigate this
/help
@sbueringer: This request has been marked as needing help from a contributor.
Please ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met.
If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help
command.
Then we'll need someone to investigate this
/help
Here is some help
Trying to figure out if this is just another occurence of: #1053 which might be then fixed via: #1061
So I took a look since you mentioned that and it seems unrelated. It's not something that was broken by upgrading the Go version, and I tried to run the reproducer on older versions and the bug seems to be there as it produces a panic.
I took a look at it since it could have been as trivial to fix as my bug, but it seems more complicated and I think I lack context and would need to spend more time on this to understand.
The panic is happening here: https://github.com/kubernetes-sigs/controller-tools/blob/f79cfef8b62a3caca5e64e0e3b871f56d45ec315/pkg/crd/parser.go#L237
Because in this case pkg
is nil. NeedPackage
was called by NeedSchemaFor
with typ TypeIdent
equal to:
Package = *loader.Package nil
Name = "MyReproStruct"
And this is nil because in requestSchema
earlier in the call stack:
https://github.com/kubernetes-sigs/controller-tools/blob/f79cfef8b62a3caca5e64e0e3b871f56d45ec315/pkg/crd/schema.go#L103-L112
You have pkgPath being sigs.k8s.io/controller-tools/repro3
and pkg pointing to repro1
but for some reason the package is indeed missing from c.pkg.Imports()[pkgPath]
Now I don't really know how you parse and populate this imports part, I ended up in some visitImports
function but I didn't spend the time to completely how you retrieve the dependency graph. I would expect that something is failing here since you have a case of: depA import depB which imports depC and it seems you don't have depA dependent on depC in your imports map (unless you explicitly import it as mnencia showed).
So I guess maybe you can give me pointers or someone that has more knowledge over this can write a patch themselves!
Thx for taking a look and sharing your results. Unfortunately, I also don't know more (have been helping maintaining CT for a while now, but unfortunately I always have to research from almost scratch to figure out what's going on :))
Minimal repro:
Create the needed directories
mkdir repro1 repro2 repro3
and put the files insideThen run controller-gen with:
The result should be the following:
If you uncomment the anonymous import in the
repro1
directory, the generation succeeds.