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

quickstart does not work #6681

Open
richard-fairthorne opened this issue Feb 15, 2024 · 18 comments
Open

quickstart does not work #6681

richard-fairthorne opened this issue Feb 15, 2024 · 18 comments
Labels
language/go Issue is related to a Go operator project
Milestone

Comments

@richard-fairthorne
Copy link

Bug Report

What did you do?

I followed the quickstart documentation found at https://v1-33-x.sdk.operatorframework.io/docs/building-operators/golang/quickstart/

./trysdk.sh &> trysdk.log

#/bin/bash

set -o xtrace

operator-sdk version

cat /etc/os-release

go version

# EVERYTHING HERE IS COPIED *VERBATIM* FOR THE GO QUICKSTART LOCATED AT
# https://v1-33-x.sdk.operatorframework.io/docs/building-operators/golang/quickstart/

mkdir memcached-operator

cd memcached-operator

operator-sdk init --domain example.com --repo github.com/example/memcached-operator

operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller

make docker-build docker-push IMG="example.com/memcached-operator:v0.0.1"

What did you expect to see?

It's a quickstart. I expected to see an operator-sdk project start, quickly, preferably, without error.

What did you see instead? Under which circumstances?

I saw segfaults and puppy tears. Here is the output:

trysdk.log

++ operator-sdk version
operator-sdk version: "v1.33.0", commit: "542966812906456a8d67cf7284fc6410b104e118", kubernetes version: "1.27.0", go version: "go1.21.5", GOOS: "linux", GOARCH: "amd64"
++ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
++ go version
go version go1.22.0 linux/amd64
++ mkdir memcached-operator
++ cd memcached-operator
++ operator-sdk init --domain example.com --repo github.com/example/memcached-operator
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.15.0
Update dependencies:
$ go mod tidy
Next: define a resource with:
$ operator-sdk create api
++ operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
api/v1alpha1/memcached_types.go
api/v1alpha1/groupversion_info.go
internal/controller/suite_test.go
internal/controller/memcached_controller.go
Update dependencies:
$ go mod tidy
Running make:
$ make generate
mkdir -p /home/debian/memcached-operator/bin
test -s /home/debian/memcached-operator/bin/controller-gen && /home/debian/memcached-operator/bin/controller-gen --version | grep -q v0.12.0 || \
GOBIN=/home/debian/memcached-operator/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.12.0
/home/debian/memcached-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
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=0xa0ba3e]

goroutine 166 [running]:
go/types.(*Checker).handleBailout(0xc000b7fa00, 0xc000cb9d40)
	/usr/local/go/src/go/types/check.go:367 +0x88
panic({0xbc6180?, 0x12b0cc0?})
	/usr/local/go/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xdc1618, 0x12b9420})
	/usr/local/go/src/go/types/sizes.go:228 +0x31e
go/types.(*Config).sizeof(...)
	/usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0xdc1618?, 0x12b9420?})
	/usr/local/go/src/go/types/const.go:76 +0x9e
go/types.representableConst({0xdc79b0, 0x1285540}, 0xc000b7fa00, 0x12b9420, 0x0)
	/usr/local/go/src/go/types/const.go:92 +0x192
go/types.(*Checker).arrayLength(0xc000b7fa00, {0xdc5cc8, 0xc0014477e0?})
	/usr/local/go/src/go/types/typexpr.go:510 +0x2d3
go/types.(*Checker).typInternal(0xc000b7fa00, {0xdc42e8, 0xc001443b90}, 0x0)
	/usr/local/go/src/go/types/typexpr.go:299 +0x49d
go/types.(*Checker).definedType(0xc000b7fa00, {0xdc42e8, 0xc001443b90}, 0xc000cb9328?)
	/usr/local/go/src/go/types/typexpr.go:180 +0x37
go/types.(*Checker).varType(0xc000b7fa00, {0xdc42e8, 0xc001443b90})
	/usr/local/go/src/go/types/typexpr.go:145 +0x25
go/types.(*Checker).structType(0xc000b7fa00, 0xc00145b470, 0xc00145b470?)
	/usr/local/go/src/go/types/struct.go:113 +0x19f
go/types.(*Checker).typInternal(0xc000b7fa00, {0xdc4258, 0xc00143d9e0}, 0xc00145eff0)
	/usr/local/go/src/go/types/typexpr.go:316 +0x1345
go/types.(*Checker).definedType(0xc000b7fa00, {0xdc4258, 0xc00143d9e0}, 0xc8fd6b?)
	/usr/local/go/src/go/types/typexpr.go:180 +0x37
go/types.(*Checker).typeDecl(0xc000b7fa00, 0xc00145eff0, 0xc00144c700, 0x0)
	/usr/local/go/src/go/types/decl.go:615 +0x44d
go/types.(*Checker).objDecl(0xc000b7fa00, {0xdcceb8, 0xc00145eff0}, 0x0)
	/usr/local/go/src/go/types/decl.go:197 +0xa7f
go/types.(*Checker).packageObjects(0xc000b7fa00)
	/usr/local/go/src/go/types/resolver.go:681 +0x425
go/types.(*Checker).checkFiles(0xc000b7fa00, {0xc000fe4a50, 0x3, 0x3})
	/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(0xc000229380, 0xc00052a460)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/loader.go:286 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc00052a460)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/loader.go:99 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc0006726f0, 0xc00052a460)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:268 +0x2b7
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x0?)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:262 +0x53
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 20
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:260 +0x1c5
make: *** [Makefile:104: generate] Error 2
Error: failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v4": exit status 2
Usage:
  operator-sdk create api [flags]

Examples:
  # Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate
  operator-sdk create api --group ship --version v1beta1 --kind Frigate

  # Edit the API Scheme

  nano api/v1beta1/frigate_types.go

  # Edit the Controller
  nano internal/controller/frigate/frigate_controller.go

  # Edit the Controller Test
  nano internal/controller/frigate/frigate_controller_test.go

  # Generate the manifests
  make manifests

  # Install CRDs into the Kubernetes cluster using kubectl apply
  make install

  # Regenerate code and run against the Kubernetes cluster configured by ~/.kube/config
  make run


Flags:
      --controller           if set, generate the controller without prompting the user (default true)
      --force                attempt to create resource even if it already exists
      --group string         resource Group
  -h, --help                 help for api
      --kind string          resource Kind
      --make make generate   if true, run make generate after generating files (default true)
      --namespaced           resource is namespaced (default true)
      --plural string        resource irregular plural form
      --resource             if set, generate the resource without prompting the user (default true)
      --version string       resource Version

Global Flags:
      --plugins strings   plugin keys to be used for this subcommand execution
      --verbose           Enable verbose logging

time="2024-02-15T19:54:48Z" level=fatal msg="failed to create API: unable to run post-scaffold tasks of \"base.go.kubebuilder.io/v4\": exit status 2"
++ make docker-build docker-push IMG=example.com/memcached-operator:v0.0.1
/home/debian/memcached-operator/bin/controller-gen rbac:roleName=manager-role crd webhook 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=0x1 addr=0x0 pc=0xa0ba3e]

goroutine 93 [running]:
go/types.(*Checker).handleBailout(0xc000805800, 0xc00052dd40)
	/usr/local/go/src/go/types/check.go:367 +0x88
panic({0xbc6180?, 0x12b0cc0?})
	/usr/local/go/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xdc1618, 0x12b9420})
	/usr/local/go/src/go/types/sizes.go:228 +0x31e
go/types.(*Config).sizeof(...)
	/usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0xdc1618?, 0x12b9420?})
	/usr/local/go/src/go/types/const.go:76 +0x9e
go/types.representableConst({0xdc79b0, 0x1285540}, 0xc000805800, 0x12b9420, 0xc00052d4b0)
	/usr/local/go/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc000805800, 0xc000f9e780, 0x12b9420)
	/usr/local/go/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc000805800, 0xc000f9e780, {0xdc1640, 0xc000132620})
	/usr/local/go/src/go/types/expr.go:375 +0x30d
go/types.(*Checker).assignment(0xc000805800, 0xc000f9e780, {0xdc1640, 0xc000132620}, {0xc93832, 0x14})
	/usr/local/go/src/go/types/assignments.go:52 +0x2e5
go/types.(*Checker).initConst(0xc000805800, 0xc000bfe900, 0xc000f9e780)
	/usr/local/go/src/go/types/assignments.go:126 +0x336
go/types.(*Checker).constDecl(0xc000805800, 0xc000bfe900, {0xdc4288, 0xc000a19ec0}, {0xdc4288, 0xc000a19ee0}, 0x0)
	/usr/local/go/src/go/types/decl.go:490 +0x348
go/types.(*Checker).objDecl(0xc000805800, {0xdcd098, 0xc000bfe900}, 0x0)
	/usr/local/go/src/go/types/decl.go:191 +0xa49
go/types.(*Checker).packageObjects(0xc000805800)
	/usr/local/go/src/go/types/resolver.go:693 +0x4dd
go/types.(*Checker).checkFiles(0xc000805800, {0xc0006aa4b0, 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(0xc000253440, 0xc000892220)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/loader.go:286 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc000892220)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/loader.go:99 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc0007cba40, 0xc000892220)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:268 +0x2b7
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x57?)
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:262 +0x53
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 71
	/home/debian/go/pkg/mod/sigs.k8s.io/controller-tools@v0.12.0/pkg/loader/refs.go:260 +0x1c5
make: *** [Makefile:100: manifests] Error 2

Environment

Operator type:

/language go

Kubernetes cluster type:

Didn't get far enough to talk to a cluster, but minikube was running.

$ operator-sdk version

operator-sdk version: "v1.33.0", commit: "542966812906456a8d67cf7284fc6410b104e118", kubernetes version: "1.27.0", go version: "go1.21.5", GOOS: "linux", GOARCH: "amd64"

$ go version (if language is Go)

go version go1.22.0 linux/amd64

$ kubectl version

Client Version: v1.29.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3

Possible Solution

Additional context

These logs are from amd64 hardware. The exact same thing happens on apple silicon, docker desktop on apple silicon, and docker desktop amd64-rosetta on Apple silicon.

@openshift-ci openshift-ci bot added the language/go Issue is related to a Go operator project label Feb 15, 2024
@krutsko
Copy link

krutsko commented Feb 17, 2024

downgrade Go to 1.21 works for me

@richard-fairthorne
Copy link
Author

richard-fairthorne commented Feb 18, 2024

Downgrade to Go 1.21 Works for me as well, on all platforms.

Go 1.22 is stable. This could be:

  • a bug in Go 1.22
  • a breaking change in Go 1.22
  • a bug in operator-sdk exposed by a non-breaking change to Go

Potential fixes could include:

  • documenting it
  • fixing it
  • fixing go 1.22

Does anyone have the skills and availability to spearhead this?

@olivercodes
Copy link

After fighting with this for a couple of days, I came across this thread. I can confirm the same issue with go 1.22 on both a Mac M1 (ARM64) and on Linux amd64.

Downgrading to 1.21 on both systems resolved the problem.

@s3rj1k
Copy link

s3rj1k commented Feb 19, 2024

Would be nice to have official operator-sdk Docker image updated, so that it would have Go 1.21 compiler in it and binary compiled with the same version. Had to manually rebuild image with version change in here https://github.com/operator-framework/operator-sdk/blob/master/images/operator-sdk/Dockerfile#L22.

Having a working Docker image can at least be considered a quick workaround without needing to downgrade the local Golang runtime version.

@richard-fairthorne
Copy link
Author

Would be nice to have official operator-sdk Docker image updated, so that it would have Go 1.21 compiler in it and binary compiled with the same version.

This could probably be useful. If you think you have strong use-case support, you should consider opening a ticket for it.

@shanduur
Copy link

shanduur commented Feb 19, 2024

Looks like might be related to kubernetes-sigs/controller-tools#851 ?


Edit: On go1.22 and controller-tools@v0.12.1 the issue is present (running go test ./...), while running tests on latest release does not fail.

@richard-fairthorne
Copy link
Author

Edit: On go1.22 and controller-tools@v0.12.1 the issue is present (running go test ./...), while running tests on latest release does not fail.

For clarity, does that rule out kubernetes-sigs/controller-tools#851 as the culprit?

@shanduur
Copy link

@richard-fairthorne other way around. The panic is caused by the version of controller-tools currently used in operator-sdk. Updating it probably should fix the issue.

@Hayden-Chang
Copy link

Upgrading go from 1.21.1 to 1.21.7 works for me

@harshvijaythakkar
Copy link

harshvijaythakkar commented Mar 7, 2024

For MAC darwin/arm64 users following will work:

  1. Your go version should be 1.27
go version go1.21.7 darwin/arm64
  1. No need to pass --plugins=go/v4-alpha argument because kubebuilder documentation has made go/v4 as default plugin and it supports MAC darwin/arm64
operator-sdk init --domain example.com --repo <your_repo_url>
  1. Create API
operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller
  1. Generate CRD
make generate

@mkfdoherty
Copy link

mkfdoherty commented Mar 15, 2024

This error appears connected to the controller-gen binary. A similar panic was documented in an issue on the controller-tools repo:

This happened with controller-gen v0.13.0. When I upgraded to v0.14.0, it disappeared.

kubernetes-sigs/controller-tools#888

The fix involves updating the CONTROLLER_TOOLS_VERSION in your Makefile from v0.13.0 to v0.14.0. This will rebuild a working controller-gen binary even with the latest Go version (v1.22.1). Ensure you rm ./bin/controller-gen so that the make will build a new binary when you make generate.

@jberkhahn
Copy link
Contributor

We discussed this and we need to bump several dependencies in several places in our end to fix this. We'll be targeting this for our next release. Until then, our recommendation is to stick to go 1.21.

@acornett21
Copy link
Contributor

acornett21 commented Apr 8, 2024

@alejandrojnm
Copy link

Yes with controller-gen v0.14.0 work the last version of operator-sdk with v0.13.0 fail

controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
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=0x1033ec604]

goroutine 117 [running]:
go/types.(*Checker).handleBailout(0x1400062e200, 0x14000861d18)
        /usr/local/go/src/go/types/check.go:367 +0x9c
panic({0x1036c5a60?, 0x103c5caf0?})
        /usr/local/go/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x103790990, 0x103c65300})
        /usr/local/go/src/go/types/sizes.go:228 +0x314
go/types.(*Config).sizeof(...)
        /usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0x103790990?, 0x103c65300?})
        /usr/local/go/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x103796c30, 0x103c30240}, 0x1400062e200, 0x103c65300, 0x0)
        /usr/local/go/src/go/types/const.go:92 +0x138
go/types.(*Checker).arrayLength(0x1400062e200, {0x103794f78, 0x14000e243a0?})
        /usr/local/go/src/go/types/typexpr.go:510 +0x238
go/types.(*Checker).typInternal(0x1400062e200, {0x103793598, 0x14000c45980}, 0x0)
        /usr/local/go/src/go/types/typexpr.go:299 +0x3bc
go/types.(*Checker).definedType(0x1400062e200, {0x103793598, 0x14000c45980}, 0x102e64bac?)
        /usr/local/go/src/go/types/typexpr.go:180 +0x2c
go/types.(*Checker).varType(0x1400062e200, {0x103793598, 0x14000c45980})
        /usr/local/go/src/go/types/typexpr.go:145 +0x2c
go/types.(*Checker).structType(0x1400062e200, 0x140012ca090, 0x140012ca090?)
        /usr/local/go/src/go/types/struct.go:113 +0x128
go/types.(*Checker).typInternal(0x1400062e200, {0x103793508, 0x140010e5860}, 0x14001232410)
        /usr/local/go/src/go/types/typexpr.go:316 +0xed0
go/types.(*Checker).definedType(0x1400062e200, {0x103793508, 0x140010e5860}, 0x103500528?)
        /usr/local/go/src/go/types/typexpr.go:180 +0x2c
go/types.(*Checker).typeDecl(0x1400062e200, 0x14001232410, 0x14000c42940, 0x0)
        /usr/local/go/src/go/types/decl.go:615 +0x39c
go/types.(*Checker).objDecl(0x1400062e200, {0x10379bb40, 0x14001232410}, 0x0)
        /usr/local/go/src/go/types/decl.go:197 +0x880
go/types.(*Checker).packageObjects(0x1400062e200)
        /usr/local/go/src/go/types/resolver.go:681 +0x3c0
go/types.(*Checker).checkFiles(0x1400062e200, {0x14000ea8738, 0x3, 0x3})
        /usr/local/go/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
        /usr/local/go/src/go/types/check.go:372
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0x140002713b0, 0x140001f6e80)
        /Users/alejandrojnm/Project/go/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/pkg/loader/loader.go:286 +0x2d8
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0x140001f6e80)
        /Users/alejandrojnm/Project/go/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/pkg/loader/loader.go:99 +0x44
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0x140007c0570, 0x140001f6e80)
        /Users/alejandrojnm/Project/go/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/pkg/loader/refs.go:268 +0x304
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x22?)
        /Users/alejandrojnm/Project/go/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/pkg/loader/refs.go:262 +0x58
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 103
        /Users/alejandrojnm/Project/go/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/pkg/loader/refs.go:260 +0x230
make: *** [generate] Error 2
Error: failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v4": exit status 2

@franciscoprin
Copy link

I'm having this problem with go1.21.9

$ go version               
go version go1.21.9 darwin/arm64

@harshitsinghvi22
Copy link

i have the below go version and it works fine when I UPDATED THE CONTROLLER-GEN VERSION in the Makefile to >=0.14.0
go version go1.22.3 darwin/amd64

@qfaure
Copy link

qfaure commented May 21, 2024

i have the below go version and it works fine when I UPDATED THE CONTROLLER-GEN VERSION in the Makefile to >=0.14.0 go version go1.22.3 darwin/amd64

Work for me. Thanks @harshitsinghvi22
CONTROLLER_TOOLS_VERSION ?= v0.14.0
Don't forget to delete binary in /bin if you previously launch make with versin 0.13.0

@cabrinha
Copy link

CONTROLLER_TOOLS_VERSION ?= v0.14.0 # also tried v0.15.0

go version go1.22.3 darwin/arm64

operator-sdk version: "v1.34.2", commit: "81dd3cb24b8744de03d312c1ba23bfc617044005", kubernetes version: "v1.28.0", go version: "go1.21.10", GOOS: "darwin", GOARCH: "arm64"

make generate works fine, but make manifests:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x100c2da64]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/go Issue is related to a Go operator project
Projects
None yet
Development

No branches or pull requests