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

[controller-gen] invalid memory address or nil pointer dereference [recovered] #888

Closed
kerthcet opened this issue Mar 1, 2024 · 16 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/support Categorizes issue or PR as a support question.

Comments

@kerthcet
Copy link

kerthcet commented Mar 1, 2024

Error log here: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_lws/11/pull-lws-test-main/1763464055189671936

This is my command:

CMD

/home/prow/go/src/sigs.k8s.io/lws/bin/controller-gen \
	rbac:roleName=manager-role output:rbac:artifacts:config=config/rbac \
	crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/crd/bases \
	webhook output:webhook:artifacts:config=config/webhook \
	paths="./..."

Output(error):

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=0xa0e4be]

However, if I add -h to controller-gen, everything goes well:
CMD:

/home/prow/go/src/sigs.k8s.io/lws/bin/controller-gen -h \
	rbac:roleName=manager-role output:rbac:artifacts:config=config/rbac \
	crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/crd/bases \
	webhook output:webhook:artifacts:config=config/webhook \
	paths="./..."

Output:

/home/prow/go/src/sigs.k8s.io/lws/bin/controller-gen -h \
	rbac:roleName=manager-role output:rbac:artifacts:config=config/rbac \
	crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/crd/bases \
	webhook output:webhook:artifacts:config=config/webhook \
	paths="./..."
Usage:
  controller-gen [flags]
Examples:
	# Generate RBAC manifests and crds for all types under apis/,
	# outputting crds to /tmp/crds and everything else to stdout
	controller-gen rbac:roleName=<role name> crd paths=./apis/... output:crd:dir=/tmp/crds output:stdout
	# Generate deepcopy/runtime.Object implementations for a particular file
	controller-gen object paths=./apis/v1beta1/some_types.go
	# Generate OpenAPI v3 schemas for API packages and merge them into existing CRD manifests
	controller-gen schemapatch:manifests=./manifests output:dir=./manifests paths=./pkg/apis/... 
	# Run all the generators for a given project
	controller-gen paths=./apis/...
	# Explain the markers for generating CRDs, and their arguments
	controller-gen crd -ww
        ...

Anyone can provide some advices?

/kind bug
/kind support

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. kind/support Categorizes issue or PR as a support question. labels Mar 1, 2024
@kerthcet
Copy link
Author

kerthcet commented Mar 2, 2024

This is happened with controller-gen v0.13.0, when I upgrade to v0.14.0, it disappears.

@zhaohuabing
Copy link

Still got this on 14.0

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa7ae32]

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedPackage(0xc0006bd860, 0x0)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:237 +0x52
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0006bd860, {0x0, {0xc001406254, 0x3}})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:170 +0x5a
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc00a6dcc90?, {0xc0001c28a0?, 0xc93f1a?}, {0xc001406254?, 0x3?})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107 +0xdb
sigs.k8s.io/controller-tools/pkg/crd.namedToSchema(0xc00a6dcc90, 0xc000013890)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:254 +0x1fb
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00a6dcc90, {0xdc9f80?, 0xc000013890})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:173 +0x5c
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc00907aa40, 0xc0000138a8)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:401 +0x7f2
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00907aa40, {0xdc9f20?, 0xc0000138a8})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:181 +0xc5
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0xc00907aa40)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:124 +0x112
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0006bd860, {0xc000f588c0, {0xc001105f3c, 0x4}})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:193 +0x2ae
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc0003ebb00?, {0x0?, 0xc93f1a?}, {0xc001105f3c?, 0x0?})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107 +0xdb
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc00907ae60, 0xc0017324e0)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:237 +0x18c
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00907ae60, {0xdc9f50?, 0xc0017324e0})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:171 +0x46
sigs.k8s.io/controller-tools/pkg/crd.arrayToSchema(0xc00a6dca50, 0xc001734090)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:275 +0x10a
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00a6dca50, {0xdc9fb0?, 0xc001734090})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:175 +0x72
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc00907b558, 0xc00172c4e0)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:401 +0x7f2
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00907b558, {0xdc9f20?, 0xc00172c4e0})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:181 +0xc5
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0xc00907b558)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:124 +0x112
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0006bd860, {0xc000f588c0, {0xc00012a168, 0x18}})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:193 +0x2ae
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0xc0003ebb00?, {0x0?, 0xc93f1a?}, {0xc00012a168?, 0x0?})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:107 +0xdb
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0xc00a6dc930, 0xc001732280)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:237 +0x18c
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00a6dc930, {0xdc9f50?, 0xc001732280})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:171 +0x46
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0xc00907bf98, 0xc00172c228)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:401 +0x7f2
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0xc00907bf98, {0xdc9f20?, 0xc00172c228})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:181 +0xc5
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0xc00907bf98)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/schema.go:124 +0x112
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0xc0006bd860, {0xc000f588c0, {0xc00012a138, 0x14}})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:193 +0x2ae
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0xc0006bd860, {0xc000f588c0, {0xc00012a138, 0x14}})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/parser.go:205 +0xcd
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0xc0006bd860, {{0xc001b880ce, 0x15}, {0xc00012a138, 0x14}}, 0x0)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/spec.go:93 +0x585
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate({0x0, 0xc00029e7c8, 0x0, {0x0, 0x0, 0x0}, 0x0, {0x0, 0x0}, {0x0, ...}}, ...)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/gen.go:150 +0x40b
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0xc00143d0e0)
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/genall/genall.go:272 +0x247
main.main.func1(0xc000282200?, {0xc0002d91a0?, 0x4?, 0xc92162?})
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:176 +0x6a
github.com/spf13/cobra.(*Command).execute(0xc000004300, {0xc000036090, 0x3, 0x3})
	/home/ubuntu/go/pkg/mod/github.com/spf13/[email protected]/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
	/home/ubuntu/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	/home/ubuntu/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039
main.main()
	/home/ubuntu/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:200 +0x2d2

@sebglon
Copy link

sebglon commented Mar 25, 2024

I have the same with the latest version on alpine docker image 1.22-alpine and 1.21-alpine

evadnoob added a commit to getoutreach/stencil-golang that referenced this issue Mar 27, 2024
controller-gen panics on some of our repos now, specifically found this
in database-credential-operator.

```
go run sigs.k8s.io/controller-tools/cmd/[email protected] object paths=./api/k8s/database/v1
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=0x103280e80]

```

kubernetes-sigs/controller-tools#888
evadnoob added a commit to getoutreach/stencil-golang that referenced this issue Mar 27, 2024
controller-gen panics on some of our repos now, specifically found this
in database-credential-operator.

```
go run sigs.k8s.io/controller-tools/cmd/[email protected] object paths=./api/k8s/database/v1
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=0x103280e80]

```

kubernetes-sigs/controller-tools#888
evadnoob added a commit to getoutreach/stencil-golang that referenced this issue Mar 27, 2024
controller-gen panics on some of our repos now, specifically found this
in database-credential-operator.

```
go run sigs.k8s.io/controller-tools/cmd/[email protected] object paths=./api/k8s/database/v1
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=0x103280e80]

```

kubernetes-sigs/controller-tools#888
@sbueringer
Copy link
Member

sbueringer commented Apr 3, 2024

Is anyone able to provide a minimal repo to reproduce this issue with the latest release?

(alternatively a PR with a fix and unit test which triggers the panic without the fix would also work)

@shanduur
Copy link
Member

shanduur commented Apr 4, 2024

@sbueringer this is not present on v0.14.0. (go1.22.1/darwin/arm64).

@sbueringer
Copy link
Member

sbueringer commented Apr 4, 2024

@shanduur Thx for the confirmation for your case. There seem to be other cases though: #888 (comment)

No idea if that is the same panic though as the issue description doesn't show a full stacktrace.

@b1gb4by
Copy link

b1gb4by commented Apr 8, 2024

I have an older version, but a similar error occurred in v0.9.0. (go version go1.22.2 linux/amd64)

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=0xa00acf]

goroutine 178 [running]:
go/types.(*Checker).handleBailout(0xc000382a00, 0xc001271d40)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/check.go:367 +0x88
panic({0xbb0600?, 0x128fd00?})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xda2d78, 0x1298560})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/sizes.go:228 +0x30f
go/types.(*Config).sizeof(...)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/sizes.go:333
go/types.representableConst.func1({0xda2d78?, 0x1298560?})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/const.go:76 +0x9e
go/types.representableConst({0xda90e0, 0x12645a0}, 0xc000382a00, 0x1298560, 0x0)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/const.go:92 +0x192
go/types.(*Checker).arrayLength(0xc000382a00, {0xda73a8, 0xc0018f84c0?})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:510 +0x2d3
go/types.(*Checker).typInternal(0xc000382a00, {0xda59f8, 0xc00121ccc0}, 0x0)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:299 +0x49d
go/types.(*Checker).definedType(0xc000382a00, {0xda59f8, 0xc00121ccc0}, 0xc001271328?)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:180 +0x37
go/types.(*Checker).varType(0xc000382a00, {0xda59f8, 0xc00121ccc0})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:145 +0x25
go/types.(*Checker).structType(0xc000382a00, 0xc001b123f0, 0xc001b123f0?)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/struct.go:113 +0x19f
go/types.(*Checker).typInternal(0xc000382a00, {0xda5968, 0xc001217320}, 0xc001b0b400)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:316 +0x1345
go/types.(*Checker).definedType(0xc000382a00, {0xda5968, 0xc001217320}, 0xc785e2?)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/typexpr.go:180 +0x37
go/types.(*Checker).typeDecl(0xc000382a00, 0xc001b0b400, 0xc001219040, 0x0)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/decl.go:615 +0x44d
go/types.(*Checker).objDecl(0xc000382a00, {0xdae620, 0xc001b0b400}, 0x0)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/decl.go:197 +0xa7f
go/types.(*Checker).packageObjects(0xc000382a00)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/resolver.go:681 +0x425
go/types.(*Checker).checkFiles(0xc000382a00, {0xc000c7ec78, 0x3, 0x3})
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/check.go:408 +0x1a5
go/types.(*Checker).Files(...)
        /home/linuxbrew/.linuxbrew/Cellar/go/1.22.2/libexec/src/go/types/check.go:372
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0xc000362e40, 0xc0005106e0)
        /home/xxx/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:286 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc0005106e0)
        /home/xxx/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:99 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc000ae6ed0, 0xc0005106e0)
        /home/xxx/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:268 +0x2b7
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x4a?)
        /home/xxx/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:262 +0x53
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 114
        /home/xxx/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:260 +0x1c5
make: *** [Makefile:132: generate] Error 2

Previously, no such error occurred.

@Nuckal777
Copy link

Is anyone able to provide a minimal repo to reproduce this issue with the latest release?

(alternatively a PR with a fix and unit test which triggers the panic without the fix would also work)

Not necessarily a minimal repo, but the GH actions for https://github.com/sapcc/maintenance-controller/actions/runs/8573915772/job/23499644206 fail consistently with go 1.22.

@agaudreault
Copy link

Using the package in https://github.com/argoproj/argo-cd, when the package (v0.4.1) is installed with 1.22, I get the same error as above.
After switching to go 1.21, performing a go install sigs.k8s.io/controller-tools/cmd/[email protected] again, everything works as expected.

@sbueringer
Copy link
Member

Have you considered upgrading controller-gen? Current version is now v0.14 (we're close to v0.15).

To be honest, not sure if anyone has time to look into why a release from November 2020 doesn't work with Go 1.22

@sbueringer
Copy link
Member

sbueringer commented Apr 9, 2024

Is anyone able to provide a minimal repo to reproduce this issue with the latest release?

Is anyone able to provide a minimal repo to reproduce this issue with the latest release (v0.14) :)

@sbueringer
Copy link
Member

I'm going to close this issue in the meantime. Feel free to reopen if we can reproduce it with the latest release.

For folks using older versions I would recommend upgrading :)

/close

e0ne added a commit to e0ne/sriov-network-operator that referenced this issue Apr 29, 2024
Update to the newer version to omit issue [1].

[1] kubernetes-sigs/controller-tools#888

Signed-off-by: Ivan Kolodiazhnyi <[email protected]>
akalenyu added a commit to akalenyu/containerized-data-importer that referenced this issue May 6, 2024
Avoid make generate panic:
kubernetes-sigs/controller-tools#888

Signed-off-by: Alex Kalenyuk <[email protected]>
akalenyu added a commit to akalenyu/containerized-data-importer that referenced this issue May 7, 2024
Avoid make generate panic:
kubernetes-sigs/controller-tools#888

Signed-off-by: Alex Kalenyuk <[email protected]>
kubevirt-bot pushed a commit to kubevirt/containerized-data-importer that referenced this issue May 8, 2024
* Update builder to use golang 1.22.3

Signed-off-by: Alex Kalenyuk <[email protected]>

* Update controller-gen to v0.14.0

Avoid make generate panic:
kubernetes-sigs/controller-tools#888

Signed-off-by: Alex Kalenyuk <[email protected]>

---------

Signed-off-by: Alex Kalenyuk <[email protected]>
@tuminoid
Copy link

Just noting that our finding is that controller-tools 0.13 onwards works with Go 1.22, but 0.12.1 and older fails. We have CAPM3 1.5 release branch now failing with Go 1.22 (using ct 0.12.1), but CAPM3 1.6 with ct 0.13.0 is green. (1.5 is EOS, so no worries)

yash97 added a commit to yash97/amazon-vpc-resource-controller-k8s that referenced this issue Aug 28, 2024
kasserater added a commit to IBM/ibm-block-csi-operator that referenced this issue Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants