operator-framework / operator-sdk

SDK for building Kubernetes applications. Provides high level APIs, useful abstractions, and project scaffolding.
https://sdk.operatorframework.io
Apache License 2.0
7.25k stars 1.75k forks source link

Fails with "deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from" out of the box #2288

Closed mangelajo closed 4 years ago

mangelajo commented 4 years ago

Bug Report

What did you do?

operator-sdk new submariner-operator
cd submariner-operator/
operator-sdk add api --api-version=submariner.io/v1alpha1 --kind=Submariner

What did you expect to see? Working add api

What did you see instead? Under which circumstances?

F1203 10:14:34.573020    3109 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from github.com/submariner-io/submariner-operator/pkg/apis/submariner/v1alpha1.Submariner
goroutine 1 [running]:
k8s.io/klog.stacks(0xc000d13e00, 0xc000a0f0e0, 0xc1, 0x111)
        /home/joe/go/pkg/mod/k8s.io/klog@v0.3.3/klog.go:855 +0xb8
k8s.io/klog.(*loggingT).output(0x335c940, 0xc000000003, 0xc000270c40, 0x3146640, 0xb, 0x375, 0x0)
        /home/joe/go/pkg/mod/k8s.io/klog@v0.3.3/klog.go:806 +0x351
k8s.io/klog.(*loggingT).printf(0x335c940, 0x3, 0x1ee9b04, 0x2a, 0xc001154d18, 0x3, 0x3)
        /home/joe/go/pkg/mod/k8s.io/klog@v0.3.3/klog.go:705 +0x14b
k8s.io/klog.Fatalf(...)
        /home/joe/go/pkg/mod/k8s.io/klog@v0.3.3/klog.go:1256
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).doStruct(0xc000cb0800, 0xc0000ebef0, 0xc00074e6e0)
        /home/joe/go/pkg/mod/k8s.io/gengo@v0.0.0-20191010091904-7fa3014cb28f/examples/deepcopy-gen/generators/deepcopy.go:885 +0x7bd
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).generateFor(0xc000cb0800, 0xc0000ebef0, 0xc00074e6e0)
        /home/joe/go/pkg/mod/k8s.io/gengo@v0.0.0-20191010091904-7fa3014cb28f/examples/deepcopy-gen/generators/deepcopy.go:695 +0xc5
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).GenerateType(0xc000cb0800, 0xc0002709a0, 0xc0000ebef0, 0x21b7320, 0xc000e9ffa0, 0x0, 0x1eb9e33)
        /home/joe/go/pkg/mod/k8s.io/gengo@v0.0.0-20191010091904-7fa3014cb28f/examples/deepcopy-gen/generators/deepcopy.go:608 +0xe98
k8s.io/gengo/generator.(*Context).executeBody(0xc0002709a0, 0x21b42a0, 0xc000934750, 0x222f9c0, 0xc000cb0800, 0x60, 0xc0011550c8)

Environment

mangelajo commented 4 years ago

More hints on the issue:

# operator-sdk generate openapi
INFO[0000] Running OpenAPI code-generation for Custom Resource group versions: [submariner:[v1alpha1], ] 
E1203 12:01:56.439922     272 openapi.go:304] Error when generating: TypeMeta, TypeMeta invalid type
Error: openapi-gen generator error: Failed executing generator: some packages had errors:
cannot generate spec for type invalid type
camilamacedo86 commented 4 years ago

Hi @mangelajo,

The go version compatible with SDK 0.12 is the 1.13+. Are you with the project created inside of $GOPATH? Also, what is the path of the project? It shows the same scenario of https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525132306.

See that you need to be in the $GOPATH and the dir paths need to match with the project. E.g for https://github.com/operator-framework/operator-sdk/ the dir path needs to be $GOPATH /github.com/operator-framework/operator-sdk/

If the above information do not help you sort it out, could you share your code/project?

mangelajo commented 4 years ago

Thank you Camila!

I tested with go 1.13+ too, I updated the bug report,

It's not on $GOPATH since we are using GO111MODULES in the project, let me test with that, and I'll look at #1853 to see if that sheds some light.

irc: ajo / mangelajo Miguel Angel Ajo Pelayo +34 636 52 25 69 skype: ajoajoajo

On Tue, Dec 3, 2019 at 1:05 PM Camila Macedo notifications@github.com wrote:

Hi @mangelajo https://github.com/mangelajo,

The go version compatible with SDK 0.12 is the 1.13+. Are you with the project created inside of $GOPATH? Also, what is the path of the project? It shows the same scenario of #1854 (comment) https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525132306 .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/operator-framework/operator-sdk/issues/2288?email_source=notifications&email_token=AAI7G4TD7QMGFPTQDAH543DQWZDSFA5CNFSM4JUVQW42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFZEXKA#issuecomment-561138600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI7G4VAS23RZNPO7FVBNUTQWZDSFANCNFSM4JUVQW4Q .

camilamacedo86 commented 4 years ago

HI @mangelajo,

Note that go do not work well with more than one version installed. So, ensure that you have locally just the 1.13+.

mangelajo commented 4 years ago

[root@68d43dc05cf5 submariner-operator]# echo $GOPATH /go [root@68d43dc05cf5 submariner-operator]# pwd /go/src/github.com/submariner-io/submariner-operator [root@68d43dc05cf5 submariner-operator]# echo $GOROOT

[root@68d43dc05cf5 submariner-operator]# export GOROOT=$GOPATH [root@68d43dc05cf5 submariner-operator]# operator-sdk generate k8s INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [submariner:[v1alpha1], ] INFO[0000] Code-generation complete.

This was the issue, as soon as GOROOT is set it will work.

I think we may detect this condition from operator-sdk and warn the user about it. What do you think ?

irc: ajo / mangelajo Miguel Angel Ajo Pelayo +34 636 52 25 69 skype: ajoajoajo

On Tue, Dec 3, 2019 at 1:42 PM Camila Macedo notifications@github.com wrote:

HI @mangelajo https://github.com/mangelajo,

Note that go do not work well with more than one version installed. So, ensure that you have locally just the 1.13+.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/operator-framework/operator-sdk/issues/2288?email_source=notifications&email_token=AAI7G4W2WSIH5FC276IDDO3QWZH5DA5CNFSM4JUVQW42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFZHVGY#issuecomment-561150619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI7G4XA7SPZZX3J444XQ33QWZH5DANCNFSM4JUVQW4Q .

mangelajo commented 4 years ago

Sorry, GOROOT must be /usr/lib/golang in my case.

It has to point to the golang installation, otherwise operator-sdk generate openapi won't work.


irc: ajo / mangelajo Miguel Angel Ajo Pelayo +34 636 52 25 69 skype: ajoajoajo

On Tue, Dec 3, 2019 at 1:56 PM Miguel Angel miguelangel@ajo.es wrote:

[root@68d43dc05cf5 submariner-operator]# echo $GOPATH /go [root@68d43dc05cf5 submariner-operator]# pwd /go/src/github.com/submariner-io/submariner-operator [root@68d43dc05cf5 submariner-operator]# echo $GOROOT

[root@68d43dc05cf5 submariner-operator]# export GOROOT=$GOPATH [root@68d43dc05cf5 submariner-operator]# operator-sdk generate k8s INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [submariner:[v1alpha1], ] INFO[0000] Code-generation complete.

This was the issue, as soon as GOROOT is set it will work.

I think we may detect this condition from operator-sdk and warn the user about it. What do you think ?

irc: ajo / mangelajo Miguel Angel Ajo Pelayo +34 636 52 25 69 skype: ajoajoajo

On Tue, Dec 3, 2019 at 1:42 PM Camila Macedo notifications@github.com wrote:

HI @mangelajo https://github.com/mangelajo,

Note that go do not work well with more than one version installed. So, ensure that you have locally just the 1.13+.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/operator-framework/operator-sdk/issues/2288?email_source=notifications&email_token=AAI7G4W2WSIH5FC276IDDO3QWZH5DA5CNFSM4JUVQW42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFZHVGY#issuecomment-561150619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI7G4XA7SPZZX3J444XQ33QWZH5DANCNFSM4JUVQW4Q .

camilamacedo86 commented 4 years ago

Hi @mangelajo,

I am not sure if I understood. Could you fix the local env with the info informed and see it worked or not?

camilamacedo86 commented 4 years ago

Hi @mangelajo,

I cloned your project locally to check it. See that I am running inside of the GOPATH and with the same path/dir of your project and all worked fine.

Please, let us know if you are ok to close this one or has anything else that you are expecting here.

mangelajo commented 4 years ago

Let me close this one.

I want to open a new one for better "no GOROOT" handling in some situations where the error message is left to the underlying generators and is very obscure.

mdbooth commented 4 years ago

I am still hitting this exact issue:

$ pwd
/home/mbooth/go/src/github.com/openstack-k8s-operators

$ operator-sdk new foo --verbose
DEBU[0000] Debug logging is set
INFO[0000] Creating new Go operator 'foo'.
INFO[0000] Created go.mod
INFO[0000] Created tools.go
INFO[0000] Created cmd/manager/main.go
INFO[0000] Created build/Dockerfile
INFO[0000] Created build/bin/entrypoint
INFO[0000] Created build/bin/user_setup
INFO[0000] Created deploy/service_account.yaml
INFO[0000] Created deploy/role.yaml
INFO[0000] Created deploy/role_binding.yaml
INFO[0000] Created deploy/operator.yaml
INFO[0000] Created pkg/apis/apis.go
INFO[0000] Created pkg/controller/controller.go
INFO[0000] Created version/version.go
INFO[0000] Created .gitignore
INFO[0000] Validating project
DEBU[0000] Running []string{"go", "build", "./..."}
INFO[0002] Project validation successful.
INFO[0002] Project creation complete.

$ cd foo

$ operator-sdk add api --api-version=foo.example.com/v1alpha1 --kind=Foo --verbose
DEBU[0000] Debug logging is set
INFO[0000] Generating api version foo.example.com/v1alpha1 for kind Foo.
INFO[0000] Created pkg/apis/foo/group.go
INFO[0000] Created pkg/apis/foo/v1alpha1/foo_types.go
INFO[0000] Created pkg/apis/addtoscheme_foo_v1alpha1.go
INFO[0000] Created pkg/apis/foo/v1alpha1/register.go
INFO[0000] Created pkg/apis/foo/v1alpha1/doc.go
INFO[0000] Created deploy/crds/foo.example.com_v1alpha1_foo_cr.yaml
DEBU[0000] Setting GOROOT=/usr/lib/golang
INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [foo:[v1alpha1], ]
F0506 12:04:45.607871   10761 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from github.com/openstack-k8s-operators/foo/pkg/apis/foo/v1alpha1.Foo

My environment:

$ go version
go version go1.13.10 linux/amd64

$ operator-sdk version
operator-sdk version: "v0.17.0", commit: "2fd7019f856cdb6f6618e2c3c80d15c3c79d1b6c", kubernetes version: "unknown", go version: "go1.13.10 linux/amd64"

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mbooth/.cache/go-build"
GOENV="/home/mbooth/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mbooth/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build274026007=/tmp/go-build -gno-record-gcc-switches"
iamkirkbater commented 3 years ago

I know this is an old one, but it's one of the first results that pops up when I'm googling this error.

I was getting this caused by GVM in my environment. For whatever reason it isn't setting the env vars per terminal session.

Running gvm use [whatever version] re-exports the correct env vars, so running that command (even if it's the same version) seemed to solve the issue for me.

jdheyburn commented 3 years ago

Like my fellow commenter above, posting my fix which was to set $GOROOT to the directory containing my go installation.

E.g. for a go installation at /usr/local/Cellar/go/1.16.4/libexec/bin/go I ran export GOROOT=/usr/local/Cellar/go/1.16.4/libexec/

Fixed pull from here: https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525132306

keskad commented 2 years ago

In my case an upgrade helped - v0.20.2 -> v0.25.3