Skip to content

Shared API types: Hit an unsupported type invalid type for invalid type #2619

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

Closed
german-muzquiz opened this issue Mar 3, 2020 · 7 comments
Closed
Assignees
Labels
triage/support Indicates an issue that is a support question.

Comments

@german-muzquiz
Copy link

Bug Report

What did you do?
I have an existing project using operator-sdk that is working fine. Now I plan to add a new version of the API, and there are some custom types that need to be shared between all APIs. I'm following this guide: https://github.com/operator-framework/operator-sdk/blob/9a32696a3b68dc9f94acca29dd4878df0baddf9e/doc/user/migrating-existing-apis.md#copying-shared-type-definitions-and-functions-to-a-separate-package

When running operator-sdk generate k8s, I face the "Hit an unsupported type invalid type for invalid type" error.

What did you expect to see?
Code generation completed successfully.

What did you see instead? Under which circumstances?

INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [spinnaker:[shared v1alpha2], ]
F0303 10:19:06.026830   74499 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from github.com/armory/spinnaker-operator/pkg/apis/spinnaker/v1alpha2.SpinnakerAccountSpec
goroutine 1 [running]:
k8s.io/klog.stacks(0xc0115a6100, 0xc011582120, 0xc1, 0x111)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/klog.go:855 +0xb8
k8s.io/klog.(*loggingT).output(0x2b4ab00, 0xc000000003, 0xc000136f50, 0x2ac0c6c, 0xb, 0x375, 0x0)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/klog.go:806 +0x351
k8s.io/klog.(*loggingT).printf(0x2b4ab00, 0x3, 0x2046f53, 0x2a, 0xc00e004ef0, 0x3, 0x3)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/klog.go:705 +0x14b
k8s.io/klog.Fatalf(...)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/klog.go:1256
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).doStruct(0xc011411100, 0xc0113cfb80, 0xc011401810)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/examples/deepcopy-gen/generators/deepcopy.go:885 +0x7bd
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).generateFor(0xc011411100, 0xc0113cfb80, 0xc011401810)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/examples/deepcopy-gen/generators/deepcopy.go:695 +0xc5
k8s.io/gengo/examples/deepcopy-gen/generators.(*genDeepCopy).GenerateType(0xc011411100, 0xc0113ff9e0, 0xc0113cfb80, 0x21e57a0, 0xc011428360, 0x0, 0x0)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/examples/deepcopy-gen/generators/deepcopy.go:608 +0xe98
k8s.io/gengo/generator.(*Context).executeBody(0xc0113ff9e0, 0x21e45a0, 0xc0113cdaa0, 0x2235440, 0xc011411100, 0x60, 0xffffffffffffffff)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/generator/execute.go:304 +0x11c
k8s.io/gengo/generator.(*Context).ExecutePackage(0xc0113fe000, 0xc00737cc90, 0x21, 0x2220020, 0xc011411000, 0x0, 0x0)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/generator/execute.go:265 +0xb25
k8s.io/gengo/generator.(*Context).ExecutePackages(0xc0113fe000, 0xc00737cc90, 0x21, 0xc011414720, 0x1, 0x1, 0x0, 0x30)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/generator/execute.go:51 +0xbf
k8s.io/gengo/args.(*GeneratorArgs).Execute(0xc0065a8960, 0xc00e0057a8, 0x200664a, 0x6, 0x20b9c48, 0xc006909780, 0x1d)
        /Users/german/Projects/armory/pkg/mod/k8s.io/[email protected]/args/args.go:194 +0x1e4
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.deepcopyGen(0xc0000d1d40, 0x3a, 0xc0000cb140, 0x2, 0x2, 0x0, 0xc000576948)
        /Users/german/Projects/armory/pkg/mod/github.com/operator-framework/[email protected]/cmd/operator-sdk/internal/genutil/k8s.go:95 +0x4d9
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.K8sCodegen.func1(0xc0000d1d40, 0x3a, 0x0, 0x0)
        /Users/german/Projects/armory/pkg/mod/github.com/operator-framework/[email protected]/cmd/operator-sdk/internal/genutil/k8s.go:54 +0x50
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.generateWithHeaderFile(0xc000029bf8, 0x0, 0x0)
        /Users/german/Projects/armory/pkg/mod/github.com/operator-framework/[email protected]/cmd/operator-sdk/internal/genutil/genutil.go:46 +0x175
github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil.K8sCodegen(0xc000398c80, 0x0)
        /Users/german/Projects/armory/pkg/mod/github.com/operator-framework/[email protected]/cmd/operator-sdk/internal/genutil/k8s.go:55 +0x48d
github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate.k8sFunc(0xc000398c80, 0x2b67e30, 0x0, 0x0, 0x0, 0x0)
        /Users/german/Projects/armory/pkg/mod/github.com/operator-framework/[email protected]/cmd/operator-sdk/generate/k8s.go:56 +0x64
github.com/spf13/cobra.(*Command).execute(0xc000398c80, 0x2b67e30, 0x0, 0x0, 0xc000398c80, 0x2b67e30)
        /Users/german/Projects/armory/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc000398780, 0xc0002175c0, 0x1, 0x1)
        /Users/german/Projects/armory/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/german/Projects/armory/pkg/mod/github.com/spf13/[email protected]/command.go:864
main.main()
        /Users/german/Projects/armory/src/github.com/armory/spinnaker-operator/tools/generate.go:22 +0x138
exit status 255
make: *** [k8s] Error 1

Environment

  • operator-sdk version:

v0.12.0

  • go version:

go version go1.13.4 darwin/amd64

  • Kubernetes version information:
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.10-eks-aae39f", GitCommit:"aae39f4697508697bf16c0de4a5687d464f4da81", GitTreeState:"clean", BuildDate:"2019-12-23T08:19:12Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
  • Kubernetes cluster kind:

  • Are you writing your operator in ansible, helm, or go?

go

Additional context
Add any other context about the problem here.

german@tarsonis ~/.../github.com/armory/spinnaker-operator % go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/german/Library/Caches/go-build"
GOENV="/Users/german/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/german/Projects/armory"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/german/Projects/armory/src/github.com/armory/spinnaker-operator/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gm/gz51q2y15rlb_z9h6fp14n040000gn/T/go-build361337593=/tmp/go-build -gno-record
-gcc-switches -fno-common"
german@tarsonis ~/.../github.com/armory/spinnaker-operator %
german@tarsonis ~/.../github.com/armory/spinnaker-operator % env | grep GO
GO111MODULE=on
GOPATH=/Users/german/Projects/armory
GOROOT=/usr/local/Cellar/go/1.13.4/libexec

Basically I just moved a custom type from _types.go to a separate package:

pkg/apis/spinnaker/
  shared/
    doc.go
    shared.go
  v1alpha2/
    _types.go
   ...

Returning that custom type to v1alpha2 fixes the error.

@camilamacedo86
Copy link
Contributor

it is caused because of an error in your local env. You need to set the go env GOROOT.
Run export GOROOT=$(go env GOROOT)

See:

The GOROOT environment variable point to the directory where the go which should be used is installed. In this way, I understand that usually, you don’t need to set $GOROOT variable. However, you may face issues in some scenarios. For example; if you have more than one go version installed locally, or if you installed it in different locally from where was recommend or if you use homebrew to install. Just to illustrate the homebrew scenario see, for example, https://coderwall.com/p/c00m1g/set-goroot-variable-with-homebre

Duplication of many:

Closing as sorted out.

@camilamacedo86 camilamacedo86 self-assigned this Mar 3, 2020
@camilamacedo86 camilamacedo86 added the triage/support Indicates an issue that is a support question. label Mar 3, 2020
@german-muzquiz
Copy link
Author

Could this have a different cause than those other issues? GOROOT is already set as I showed above:

german@tarsonis ~/.../github.com/armory/spinnaker-operator % env | grep GO
GO111MODULE=on
GOPATH=/Users/german/Projects/armory
GOROOT=/usr/local/Cellar/go/1.13.4/libexec

I also tried running export GOROOT=$(go env GOROOT) and still see the same error. What is strange is that moving the shared type to the v1alpha2 package makes it work, but having it in the shared package makes it fail.

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Mar 3, 2020

Are you able to create a new project from scratch as described in the docs?
Following the commands.

$ mkdir -p $GOPATH/src/github.com/example-inc/
$ cd $GOPATH/src/github.com/example-inc/
$ export GO111MODULE=on
$ operator-sdk new memcached-operator
$ cd memcached-operator
$ operator-sdk add api --api-version=cache.example.com/v1alpha1 --kind=Memcached

if yes, then the problem is in the implementation of your _type.go which has an invalid type defined. Please, let us know if it worked for you.

F0303 10:19:06.026830 74499 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from github.com/armory/spinnaker-operator/pkg/apis/spinnaker/v1alpha2.SpinnakerAccountSpec

If you still unable to check what is invalid could you please add here this spec definition? Also, see that SDK latest version is 0.15.2 and I'd like to recommend you upgrade your project and local env to use it.

If not, then the problem is in your local env. Note that if you used the brew formula you will probably need to do some setups manually in your env.

@camilamacedo86 camilamacedo86 reopened this Mar 3, 2020
@german-muzquiz
Copy link
Author

Following your instructions I was able to pinpoint the problem.
In the shared package I had a reference to a versioned type:

package shared

import (
 	"github.com/example-inc/memcached-operator/pkg/apis/cache/v1alpha1"
)
...
type Factory struct{}


func (f * Factory) GetGroupVersion(v Version) schema.GroupVersion {
	switch v {
	case latestVersion:
		return v1alpha1.SchemeGroupVersion
	default:
		return v1alpha1.SchemeGroupVersion
	}
}

This makes it fail using latest operator-sdk 0.15.2 and go 1.14, but as soon as I delete that import, code generation works.

So it seems that cyclic imports between versioned and non-versioned sibling packages is causing the problem.

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Mar 3, 2020

Hi @german-muzquiz,

Thank you for you let us know that you find the issue in your code impl. Btw, the go 1.14 is not supported. In order to work with SDK, you will need to use the version 1.13+ < 1.14 and it properly set in the GOROOT.

So, please, let us know if we can close this one or if you are still needing help with your impl. If yes, could you please let us know what is your scenario and what you are trying to achieve with? Why ar are you adding it in the _types?

@german-muzquiz
Copy link
Author

The goal is to be able to add new CRD versions in a maintainable way (v1beta1, v1beta2, etc.). In the current implementation, all the code is importing versioned packages:

import (
     "github.com/armory/spinnaker-operator/pkg/apis/spinnaker/v1alpha2"
)

Every time we increase the version, a lot of code would be impacted. To avoid this, I'm trying to create a set of version agnostic interfaces in a shared package, and make all the _types.go implement these interfaces. Then the rest of the code will depend only on those interfaces, and increasing the CRD version will have much less impacts in the code base.

I tried to make a factory struct in the shared package to instantiate versioned types, but I can achieve a similar goal just making the types register themselves into the shared package, so I can workaround the error. I'd love to have better error messages though, or better documentation on what can or cannot be done regarding shared packages. So far I can workaround the issue.

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Mar 9, 2020

HI @german-muzquiz,

I am not sure if I properly follow up your solution. Anyway, shows that we could identify that it is related to invalid type/definitions implemented in the code.

Also, I'd like to recommend you check the k8s doc Versions in CustomResourceDefinitions as Migrating Existing Kubernetes APIs to understand how is recommend migrate the APIs. And then, in the case of you are using OLM the doc How do operator upgrades work in Operator Lifecycle Manager (OLM)?.

I hope that it helps you with. Also, not that each API will have one version and would be one import and then you might need to allow your project to be able to work with more than one version.

So, shows that all is sorted out and we can close this one. However, please feel free to ping and ask to re-open it if you see that something still required to be clarified over this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

2 participants