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

make generate fails when type alias is used in <kind>_types.go #4170

Closed
dannyzaken opened this issue Nov 3, 2020 · 1 comment
Closed

make generate fails when type alias is used in <kind>_types.go #4170

dannyzaken opened this issue Nov 3, 2020 · 1 comment

Comments

@dannyzaken
Copy link

Bug Report

What did you do?

  • I am migrating noobaa-operator to operator-sdk v1.
  • after recreating the project and adding one of our APIs I ran make generate

What did you expect to see?

success

What did you see instead? Under which circumstances?

code generation failed with panic (see below).

After some investigation, I found out this is because of a type alias we had in the code:

type BackingStoreName = string

removing the = operator fixed the issue.

❱ make generate
/Users/dannyzaken/code/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
panic: interface conversion: types.Type is *types.Basic, not *types.Named

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/deepcopy.shouldBeCopied(0xc000813cc0, 0xc00396e2a0, 0x1004701)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/deepcopy/traverse.go:611 +0x358
sigs.k8s.io/controller-tools/pkg/deepcopy.(*ObjectGenCtx).GenerateForPackage.func2(0xc00396e2a0)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/deepcopy/gen.go:226 +0xaf
sigs.k8s.io/controller-tools/pkg/markers.EachType.func1(0xc0011c4200, 0xc0011b0880, 0xc0011aa510)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/markers/zip.go:179 +0x76e
sigs.k8s.io/controller-tools/pkg/loader.(*typeVisitor).Visit(0xc00463f880, 0x19da120, 0xc0011aa510, 0x0, 0x0)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/visit.go:64 +0x142
go/ast.Walk(0x19d4600, 0xc00463f880, 0x19da120, 0xc0011aa510)
	/usr/local/Cellar/go/1.15.2/libexec/src/go/ast/walk.go:52 +0x63
go/ast.Walk(0x19d4600, 0xc00463f880, 0x19d9b60, 0xc0011b0880)
	/usr/local/Cellar/go/1.15.2/libexec/src/go/ast/walk.go:331 +0xe65
go/ast.walkDeclList(0x19d4600, 0xc00463f880, 0xc0011c8200, 0xd, 0x10)
	/usr/local/Cellar/go/1.15.2/libexec/src/go/ast/walk.go:38 +0x9e
go/ast.Walk(0x19d4600, 0xc00463f880, 0x19d9a20, 0xc0011c4200)
	/usr/local/Cellar/go/1.15.2/libexec/src/go/ast/walk.go:353 +0x2346
sigs.k8s.io/controller-tools/pkg/loader.EachType(0xc000813cc0, 0xc00463f860)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/visit.go:38 +0xaa
sigs.k8s.io/controller-tools/pkg/markers.EachType(0xc000813e40, 0xc000813cc0, 0xc00331bf20, 0x8, 0xc0046d9708)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/markers/zip.go:155 +0xa5
sigs.k8s.io/controller-tools/pkg/deepcopy.(*ObjectGenCtx).GenerateForPackage(0xc00085bb50, 0xc000813cc0, 0x18ece6b, 0x5, 0x18ec188)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/deepcopy/gen.go:216 +0x1e5
sigs.k8s.io/controller-tools/pkg/deepcopy.Generator.Generate(0xc000216d8b, 0x17, 0x0, 0x0, 0xc0001c80f0, 0xc000254801, 0xc0001c80f0)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/deepcopy/gen.go:147 +0x1af
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0xc000a9ef00, 0xc0002803a0)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/genall/genall.go:171 +0x165
main.main.func1(0xc000229b80, 0xc0002803a0, 0x2, 0x2, 0x0, 0x0)
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:176 +0xb1
github.com/spf13/cobra.(*Command).execute(0xc000229b80, 0xc00019a190, 0x2, 0x2, 0xc000229b80, 0xc00019a190)
	/Users/dannyzaken/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000229b80, 0xc000280340, 0x4, 0x0)
	/Users/dannyzaken/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x30b
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/dannyzaken/code/go/pkg/mod/github.com/spf13/[email protected]/command.go:864
main.main()
	/Users/dannyzaken/code/go/pkg/mod/sigs.k8s.io/[email protected]/cmd/controller-gen/main.go:200 +0x34c
make: *** [generate] Error 2

Environment

Operator type:

language go

Kubernetes cluster type:

minikube 1.14.2

$ operator-sdk version

operator-sdk version: "v1.1.0", commit: "9d27e224efac78fcc9354ece4e43a50eb30ea968", kubernetes version: "v1.18.2", go version: "go1.15 darwin/amd64", GOOS: "darwin", GOARCH: "amd64"
<!-- Insert the output of `operator-sdk version` here. -->

$ go version (if language is Go)

go version go1.15.2 darwin/amd64

$ kubectl version

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-15T23:30:39Z", GoVersion:"go1.14.4", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07:13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}

Possible Solution

Additional context

running on macos Mojave 10.14.6

@joelanford
Copy link
Member

This is an issue with controller-gen. It looks related to kubernetes-sigs/controller-tools#492.

As far as I can tell, type aliases are not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants