Skip to content

Operator-SDK add api error #2490

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
sky-big opened this issue Feb 3, 2020 · 20 comments
Closed

Operator-SDK add api error #2490

sky-big opened this issue Feb 3, 2020 · 20 comments
Assignees
Labels
triage/support Indicates an issue that is a support question.

Comments

@sky-big
Copy link

sky-big commented Feb 3, 2020

$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService

INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService. 
INFO[0000] Created pkg/apis/app/group.go                
INFO[0000] Created pkg/apis/app/v1alpha1/appservice_types.go 
INFO[0000] Created pkg/apis/addtoscheme_app_v1alpha1.go 
INFO[0000] Created pkg/apis/app/v1alpha1/register.go    
INFO[0000] Created pkg/apis/app/v1alpha1/doc.go         
INFO[0000] Created deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml 
INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [app:[v1alpha1], ] 
F0203 10:54:29.486117    5946 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from app-operator/pkg/apis/app/v1alpha1.AppService

By @camilamacedo86 : Add info to centralized:

operator-sdk version:v0.15.1
go version:go1.13 linux/amd64
I'm writing operator in go
Operate System:Centos7.2

@camilamacedo86
Copy link
Contributor

Hi @sky-big,

Could you please provide the full information?

Environment

  • operator-sdk version:Insert the output of operator-sdk version here
  • go version: Insert the output of go version here
  • Kubernetes version information: Insert the output of kubectl versionhere
  • Kubernetes cluster kind:
  • Are you writing your operator in ansible, helm, or go?

@camilamacedo86 camilamacedo86 added triage/needs-information Indicates an issue needs more information in order to work on it. triage/support Indicates an issue that is a support question. labels Feb 3, 2020
@sky-big
Copy link
Author

sky-big commented Feb 3, 2020

Hi @camilamacedo86 ,
Environment

operator-sdk version:v0.15.1
go version:go1.13 linux/amd64
I'm writing operator in go

@sky-big
Copy link
Author

sky-big commented Feb 3, 2020

This isn't even talking to kubernetes yet

@sky-big
Copy link
Author

sky-big commented Feb 3, 2020

Operate System:Centos7.2

@camilamacedo86
Copy link
Contributor

Hi @sky-big,

Could you please let us know if you are following the quick start? Have you already change the specs of any type in the project before run this command? If yes, could you share snaps of the code?

@joelanford
Copy link
Member

@sky-big This is typically an issue with the fields added to your structs in _types.go files. Are there any interfaces in the hierarchy of your struct types? If so, those are the likely culprits. They will likely need to be removed or replaced with concrete implementations.

@sky-big
Copy link
Author

sky-big commented Feb 4, 2020

This is all I have to do, I failed in step 2, I haven't modified the *_types.go file yet @joelanford

[root@function-manager-vm-nat src]# operator-sdk new app-operator
INFO[0000] Creating new Go operator 'app-operator'.     
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                           
INFO[0003] Project validation successful.               
INFO[0003] Project creation complete.                   
[root@function-manager-vm-nat src]# cd app-operator/
[root@function-manager-vm-nat app-operator]# operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService. 
INFO[0000] Created pkg/apis/app/group.go                
INFO[0000] Created pkg/apis/app/v1alpha1/appservice_types.go 
INFO[0000] Created pkg/apis/addtoscheme_app_v1alpha1.go 
INFO[0000] Created pkg/apis/app/v1alpha1/register.go    
INFO[0000] Created pkg/apis/app/v1alpha1/doc.go         
INFO[0000] Created deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml 
INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [app:[v1alpha1], ] 
F0204 10:43:00.265834   17196 deepcopy.go:885] Hit an unsupported type invalid type for invalid type, from app-operator/pkg/apis/app/v1alpha1.AppService

[root@function-manager-vm-nat app-operator]# operator-sdk version
operator-sdk version: "v0.15.1", commit: "e35ec7b722ba095e6438f63fafb9e7326870b486", go version: "go1.13.6 linux/amd64"
[root@function-manager-vm-nat app-operator]# go version
go version go1.13 linux/amd64

@sky-big
Copy link
Author

sky-big commented Feb 4, 2020

I failed the second step by following quick start @camilamacedo86

@camilamacedo86
Copy link
Contributor

Hi @sky-big,

As @joelanford explained this error usually occurs because of wrong definitions in the _types files where you define the specs. Also, it is essential to highlight that these steps are fully tested and ensured automatically via the CI; besides, also, I am unable to reproduce your scenario manually. In this way, it shows that you have some issue with the scaffolded project and/or local env setup.

So, in order to help you with. Let's do it step by step and re-check/re-config all OK following my recommendation and suggestions.

  1. Remove all and start from the scratch
  2. Clean your $GOPATH/bin ( to re-install SDK and its modules )
  3. Clean you go cache as described here
  4. Re-install the SDK

Tips:

  • Ensure that you have NOT more than one go version installed. Keep just the go 1.13+ (Golang do not work well with many versions instaled )
  • Ensure that the GOROOT and GOPROXY are setups properly. ( you can check it by running go env. The GOPROXY should be GOPROXY="https://proxy.golang.org,direct" as the GOROOT should point to the go installation. E.g GOROOT="/usr/local/go" )
  • Ensure that you have installed SDK and its pre-requirements. ( run operator-sdk version to check if it is installed and its version )
  • Ensure that you are following the steps exacly as described in the doc. After each command executed, check its output to be sure that it was finished successfully.

Recommendations:

Also, if you are Getting Started with SDK and Go projects, I'd recommend you follow up the Getting Started instead of the Quick Started since it will provide a better context and example. And then, check the blog post Getting started with Golang Operators by using Operator SDK to have a further understatement over the example done in the Getting Started guide.

Please, let us know if it makes sense and if you could solve the issue with the information provided.

@camilamacedo86 camilamacedo86 removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Feb 4, 2020
@christophermaier
Copy link

@camilamacedo86 For what it's worth, I'm hitting the exact same situation as @sky-big, despite following the documentation (both Quick Start and Getting Started). I'm on Ubuntu 19.10, but otherwise it's exactly as @sky-big describes.

@joelanford
Copy link
Member

I'm not able to reproduce this either. We've seen issues with the code generators because they can sometimes rely on some Go environment variables being set, which are not usually necessary to set in normal Go installations (see #2426)

Can you run the following command and retry:

unset GOROOT
export GOROOT=$(go env GOROOT)

@christophermaier
Copy link

That actually worked! Thanks!

@sky-big
Copy link
Author

sky-big commented Feb 5, 2020

@joelanford Very good method

@grdryn
Copy link
Contributor

grdryn commented Feb 15, 2020

@joelanford I think I've got some additional information on this one that might be useful: this issue only appears on some of the linux (at least) binaries on the releases page, but not all. It seems like it might depend on the environment of the developer who built the binary.

For example, if I don't have GOROOT set in my shell (even though it shows up in go env GOROOT) like you demonstrated above, I experience the issue with the following versions (not a complete list):

  • v0.15.2
  • v0.15.1
  • v0.14.1
  • v0.14.0
  • v0.13.0
  • v0.12.0

Notably, v0.15.0 doesn't give me this behaviour, it just works. Maybe @jmccormick2001 has some magic?

Also, if I build the broken versions locally myself, they don't have the issue that the binaries on the GitHub releases page have.

@jmccormick2001
Copy link
Contributor

jmccormick2001 commented Feb 17, 2020

I did the 1.15.0 build on a Fedora 31 host. I'll re-open this one so that we can confirm this one.

@charles-d-burton
Copy link

I can replicate this issue on Ubuntu 18.04 very easily. The only solution I found is setting the GOROOT as described here.

@camilamacedo86
Copy link
Contributor

Hi @jmccormick2001,

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:

@camilamacedo86
Copy link
Contributor

HI as described above all shows sorted out here, so I am closing this one. However, please feel free to re-open if you see that something still required to be done regards this issue.

@loxley
Copy link

loxley commented Apr 9, 2020

I am also hitting this, only setting GOROOT as described by @joelanford works.

However operator-sdk v0.13.0 works without a problem(which was the version I used before testing the v0.16.0 version).

I am also pretty sure I never set GOROOT in my environment when using the v0.13.0. So what has changed?

@grdryn
Copy link
Contributor

grdryn commented Apr 9, 2020

@loxley the most bizarre thing is that for me it was v0.15.0 that worked fine, and for you it was v0.13.0. 🤷

I wonder if it's some similarity to the environment in which it was built -- e.g. I use Fedora 31, the same as jmccormick2001 built v0.15.0 on. Maybe your local environment is similar to that of whoever built v0.13.0?

In any case, explicitly setting GOROOT seems to be the only consistent fix.

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

8 participants