longhorn / longhorn

Cloud-Native distributed storage built on and for Kubernetes
https://longhorn.io
Apache License 2.0
6.17k stars 604 forks source link

[BUG] controller-gen panic while generating crds.yaml #8901

Closed derekbit closed 4 months ago

derekbit commented 4 months ago

Describe the bug

# bash k8s/generate_code.sh 
/root/go/src/k8s.io/code-generator is missing
Prepare to install code-generator
~/go/src/k8s.io ~/go/src/github.com/longhorn/longhorn-manager
~/go/src/github.com/longhorn/longhorn-manager
controller-gen is missing
Prepare to install controller-gen
kustomize is missing
Prepare to install kustomize
~/go/src/github.com/kubernetes-sigs ~/go/src/github.com/longhorn/longhorn-manager
~/go/src/github.com/longhorn/longhorn-manager
Generating deepcopy funcs
Generating clientset for longhorn:v1beta1,v1beta2 at github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset
Generating listers for longhorn:v1beta1,v1beta2 at github.com/longhorn/longhorn-manager/k8s/pkg/client/listers
Generating informers for longhorn:v1beta1,v1beta2 at github.com/longhorn/longhorn-manager/k8s/pkg/client/informers
Generating CRD
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9ef96f]

goroutine 15 [running]:
go/types.(*Checker).handleBailout(0xc000fc0200, 0xc000ba1d40)
        /usr/local/go/src/go/types/check.go:367 +0x88
panic({0xb9b6c0?, 0x125fad0?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xd895d8, 0x1268360})
        /usr/local/go/src/go/types/sizes.go:228 +0x30f
go/types.(*Config).sizeof(...)
        /usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0xd895d8?, 0x1268360?})
        /usr/local/go/src/go/types/const.go:76 +0x9e
go/types.representableConst({0xd8f9e0, 0x1234420}, 0xc000fc0200, 0x1268360, 0xc000ba14b0)
        /usr/local/go/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc000fc0200, 0xc0006d5740, 0x1268360)
        /usr/local/go/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc000fc0200, 0xc0006d5740, {0xd89600, 0xc000166bd0})
        /usr/local/go/src/go/types/expr.go:375 +0x2d7
go/types.(*Checker).assignment(0xc000fc0200, 0xc0006d5740, {0xd89600, 0xc000166bd0}, {0xc65907, 0x14})
        /usr/local/go/src/go/types/assignments.go:52 +0x2e5
go/types.(*Checker).initConst(0xc000fc0200, 0xc000a9cd20, 0xc0006d5740)
        /usr/local/go/src/go/types/assignments.go:126 +0x2c5
go/types.(*Checker).constDecl(0xc000fc0200, 0xc000a9cd20, {0xd8c298, 0xc000b50480}, {0xd8c298, 0xc000b504a0}, 0x0)
        /usr/local/go/src/go/types/decl.go:490 +0x311
go/types.(*Checker).objDecl(0xc000fc0200, {0xd95040, 0xc000a9cd20}, 0x0)
        /usr/local/go/src/go/types/decl.go:191 +0xa49
go/types.(*Checker).packageObjects(0xc000fc0200)
        /usr/local/go/src/go/types/resolver.go:693 +0x4dd
go/types.(*Checker).checkFiles(0xc000fc0200, {0xc000c804b0, 0x5, 0x5})
        /usr/local/go/src/go/types/check.go:408 +0x1a5
go/types.(*Checker).Files(...)
        /usr/local/go/src/go/types/check.go:372
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0xc00023d0b0, 0xc000636cc0)
        /root/go/pkg/mod/sigs.k8s.io/controller-tools@v0.7.0/pkg/loader/loader.go:283 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc000636cc0)
        /root/go/pkg/mod/sigs.k8s.io/controller-tools@v0.7.0/pkg/loader/loader.go:96 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc0005f56e0, 0xc000636cc0)
        /root/go/pkg/mod/sigs.k8s.io/controller-tools@v0.7.0/pkg/loader/refs.go:263 +0x2b7
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x69?)
        /root/go/pkg/mod/sigs.k8s.io/controller-tools@v0.7.0/pkg/loader/refs.go:257 +0x53
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 82
        /root/go/pkg/mod/sigs.k8s.io/controller-tools@v0.7.0/pkg/loader/refs.go:255 +0x1c5

Related to https://github.com/kubernetes-sigs/controller-tools/issues/888#issuecomment-2046073715. The controller-gen used in longhorn-manager is v0.7.0. It will cause panic when working with golang v1.22.

To Reproduce

Expected behavior

Support bundle for troubleshooting

Environment

Additional context

longhorn-io-github-bot commented 4 months ago

Pre Ready-For-Testing Checklist

  1. Check fresh installation works well
  2. Check regression test works well
  3. Check upgrade works well

https://github.com/longhorn/longhorn/pull/8902

https://github.com/longhorn/longhorn-manager/pull/2948

chriscchien commented 4 months ago

Verified pass on longhorn master(longhorn-manager 58da0f)