kubernetes-sigs/controller-tools

Controller-gen panic when using go 1.22

IBMRob opened this issue · 7 comments

IBMRob commented

Previously we were using go 1.21 without issue. After upgrading to go 1.22 using controller-gen v0.9 it results in the following

rob@Robs-MBP ibm-appconnect % make generate
GOBIN=/Users/rob/Documents/operators/my-operator/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0
/Users/rob/Documents/operators/my-operator/bin/controller-gen rbac:roleName=operator crd paths="./..." output:crd:artifacts:config=config/crd/bases
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=0x2 addr=0x0 pc=0x101050bc0]

goroutine 1367 [running]:
go/types.(*Checker).handleBailout(0x14001855200, 0x14008e7bd18)
        /Users/rob/sdk/go1.22.0/src/go/types/check.go:367 +0x9c
panic({0x10131ba60?, 0x1018a7f30?})
        /Users/rob/sdk/go1.22.0/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x1013e4c70, 0x1018b0840})
        /Users/rob/sdk/go1.22.0/src/go/types/sizes.go:228 +0x320
go/types.(*Config).sizeof(...)
        /Users/rob/sdk/go1.22.0/src/go/types/sizes.go:333
go/types.representableConst.func1({0x1013e4c70?, 0x1018b0840?})
        /Users/rob/sdk/go1.22.0/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x1013eae58, 0x10187ca38}, 0x14001855200, 0x1018b0840, 0x14008e77ae8)
        /Users/rob/sdk/go1.22.0/src/go/types/const.go:106 +0x2b0
go/types.(*Checker).representation(0x14001855200, 0x1400a7510c0, 0x1018b0840)
        /Users/rob/sdk/go1.22.0/src/go/types/const.go:256 +0x68
go/types.(*Checker).representable(0x14001855200, 0x1400a7510c0, 0x1018b0840)
        /Users/rob/sdk/go1.22.0/src/go/types/const.go:239 +0x28
go/types.(*Checker).shift(0x14001855200, 0x1400a751040, 0x1400a7510c0, {0x1013e8cf0, 0x14008e5e450}, 0x14)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:650 +0x1d8
go/types.(*Checker).binary(0x14001855200, 0x1400a751040, {0x1013e8cf0, 0x14008e5e450}, {0x1013e9200, 0x14008e5aec0}, {0x1013e9200, 0x14008e5aee0}, 0x14, 0xd8a0e2)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:796 +0x100
go/types.(*Checker).exprInternal(0x14001855200, 0x0, 0x1400a751040, {0x1013e8cf0, 0x14008e5e450}, {0x0, 0x0})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1416 +0x1d4
go/types.(*Checker).rawExpr(0x14001855200, 0x0, 0x1400a751040, {0x1013e8cf0?, 0x14008e5e450?}, {0x0?, 0x0?}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).exprInternal(0x14001855200, 0x0, 0x1400a751040, {0x1013e8ba0, 0x14008e5af00}, {0x0, 0x0})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1320 +0x150
go/types.(*Checker).rawExpr(0x14001855200, 0x0, 0x1400a751040, {0x1013e8ba0?, 0x14008e5af00?}, {0x0?, 0x0?}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14001855200, 0x101b05d28?, 0x1400a751040, {0x1013e8ba0?, 0x14008e5af00?})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).binary(0x14001855200, 0x1400a751040, {0x1013e8cf0, 0x14008e5e480}, {0x1013e8ba0, 0x14008e5af00}, {0x1013e9200, 0x14008e5af20}, 0xd, 0xd8a0e7)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:783 +0x70
go/types.(*Checker).exprInternal(0x14001855200, 0x0, 0x1400a751040, {0x1013e8cf0, 0x14008e5e480}, {0x0, 0x0})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1416 +0x1d4
go/types.(*Checker).rawExpr(0x14001855200, 0x0, 0x1400a751040, {0x1013e8cf0?, 0x14008e5e480?}, {0x0?, 0x0?}, 0x1)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).use1(0x14001855200, {0x1013e8cf0, 0x14008e5e480}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/call.go:1043 +0x1c4
go/types.(*Checker).useN(...)
        /Users/rob/sdk/go1.22.0/src/go/types/call.go:1004
go/types.(*Checker).use(...)
        /Users/rob/sdk/go1.22.0/src/go/types/call.go:994
go/types.(*Checker).callExpr(0x14001855200, 0x1400a750f80, 0x14008e5c680)
        /Users/rob/sdk/go1.22.0/src/go/types/call.go:196 +0x12b0
go/types.(*Checker).exprInternal(0x14001855200, 0x0, 0x1400a750f80, {0x1013e92c0, 0x14008e5c680}, {0x0, 0x0})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1374 +0xd0
go/types.(*Checker).rawExpr(0x14001855200, 0x0, 0x1400a750f80, {0x1013e92c0?, 0x14008e5c680?}, {0x0?, 0x0?}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14001855200, 0x1400a3780e0?, 0x1400a750f80, {0x1013e92c0?, 0x14008e5c680?})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).exprInternal(0x14001855200, 0x0, 0x1400a750f80, {0x1013e8c60, 0x14008e5c6c0}, {0x0, 0x0})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1190 +0x1890
go/types.(*Checker).rawExpr(0x14001855200, 0x0, 0x1400a750f80, {0x1013e8c60?, 0x14008e5c6c0?}, {0x0?, 0x0?}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14001855200, 0x0?, 0x1400a750f80, {0x1013e8c60?, 0x14008e5c6c0?})
        /Users/rob/sdk/go1.22.0/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).varDecl(0x14001855200, 0x1400a367860, {0x140083b0698, 0x1, 0x1}, {0x0, 0x0}, {0x1013e8c60, 0x14008e5c6c0})
        /Users/rob/sdk/go1.22.0/src/go/types/decl.go:521 +0x140
go/types.(*Checker).objDecl(0x14001855200, {0x1013eff78, 0x1400a367860}, 0x0)
        /Users/rob/sdk/go1.22.0/src/go/types/decl.go:194 +0x7ec
go/types.(*Checker).packageObjects(0x14001855200)
        /Users/rob/sdk/go1.22.0/src/go/types/resolver.go:693 +0x468
go/types.(*Checker).checkFiles(0x14001855200, {0x140099e5680, 0x7, 0x7})
        /Users/rob/sdk/go1.22.0/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
        /Users/rob/sdk/go1.22.0/src/go/types/check.go:372
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0x140003e4ea0, 0x140099f49a0)
        /Users/rob/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.0/pkg/loader/loader.go:286 +0x2d8
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0x140099f49a0)
        /Users/rob/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.0/pkg/loader/loader.go:99 +0x44
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0x140099f8330, 0x140099f49a0)
        /Users/rob/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.0/pkg/loader/refs.go:268 +0x304
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x97?)
        /Users/rob/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.0/pkg/loader/refs.go:262 +0x58
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 1
        /Users/rob/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.0/pkg/loader/refs.go:260 +0x230
make: *** [manifests] Error 2

What happens if you use a recent version of controller-gen?

xrstf commented

FWIW, https://github.com/elastic/crd-ref-docs/blob/v0.0.10 panics as well and is using controller-tools 0.13.0 already. Not the latest, I know, but at least somewhat more recent than v0.9.0.

IBMRob commented

Looks like the very latest does work - Now I need to see if Operator-SDK support support using that version.

jFYI: I git bisect'ed Go and found that this is the commit causing the crash: golang/go@5fa4aac

Will likely open an upstream issue, didn't check check if a similar issue has been created.

We updated controller-tools to v0.14.0 in nifikop (linked above) and that avoided the panic. We'd tried v0.9.0 and v0.13.0 and they both crashed when generating CRDs.

Operator-SDK uses Kubebuilder
It just add things on top.

Kubebuilder does not support 1.22 yet
We are in 1.21

Also, see that this project needs to be upgraded
https://github.com/kubernetes-sigs/controller-tools/blob/master/go.mod#L3
For 1.21 and going on

Also, see that this project needs to be upgraded

Why? This is the minimal required Go version to compile controller-tools. That doesn't mean it can't be used with 1.21 or 1.22