What did you do?
(ps: sw, pc and chan are note the real used names, the names I worked with have more than 5 char
)
I followed the quick start guide
operator-sdk add api --api-version=sw.pc/v1alpha1 --kind=Chan --verbose
What did you expect to see?
creation of api and crd manifests
What did you see instead? Under which circumstances?
Sometimes I get:
INFO[0000] Generating api version sw.pc/v1alpha1 for kind Chan.
Error: scaffold group file:
other times I get:
INFO[0000] Generating api version sw.pc/v1alpha1 for kind Cha.
INFO[0000] Created pkg/apis/sw/v1alpha1/chan_types.go
INFO[0000] Created pkg/apis/addtoscheme_sw_v1alpha1.go
INFO[0000] Created deploy/crds/sw.pwc_v1alpha1_chan_cr.yaml
INFO[0000] Running deepcopy code-generation for Custom Resource group versions: [sw:[v1alpha1], ]
INFO[0013] Code-generation complete.
INFO[0013] Running CRD generator.
-: pkg/apis/sw/group.go:1:1: expected 'package', found 'EOF'
Error: error generating CRDs from APIs in pkg/apis: error generating CRD manifests: error running CRD generator: not all generators ran successfully
and the file group.go is empty
Environment
go version go1.13.8 darwin/amd64
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:16:51Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:07:57Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Kubernetes cluster kind: local using docker for mac
Are you writing your operator in ansible, helm, or go?
go
Possible Solution
Additional context
Add any other context about the problem here.
Hi @zanoubia,
I am unable to reproduce your scenario using the Go Memcached samples. See:
$ operator-sdk add api --api-version=sw.pc/v1alpha1 --kind=Chan --verbose
DEBU[0000] Debug logging is set
INFO[0000] Generating api version sw.pc/v1alpha1 for kind Chan.
INFO[0000] Created pkg/apis/sw/group.go
INFO[0002] Created pkg/apis/sw/v1alpha1/chan_types.go
INFO[0002] Created pkg/apis/addtoscheme_sw_v1alpha1.go
INFO[0002] Created pkg/apis/sw/v1alpha1/register.go
INFO[0002] Created pkg/apis/sw/v1alpha1/doc.go
INFO[0002] Created deploy/crds/sw.pc_v1alpha1_chan_cr.yaml
INFO[0002] Running deepcopy code-generation for Custom Resource group versions: [cache:[v1alpha1], sw:[v1alpha1], ]
INFO[0017] Code-generation complete.
INFO[0017] Running CRD generator.
INFO[0018] CRD generation complete.
INFO[0018] API generation complete.
So, following some questions in order to help you with.
Could we check if you are running it from the root directory of your project?
If you perform the following steps and then, run this command are you able to check the same issue?
# Create an app-operator project that defines the App CR.
$ mkdir -p $HOME/projects/example-inc/
# Create a new app-operator project
$ cd $HOME/projects/example-inc/
$ operator-sdk new app-operator --repo github.com/example-inc/app-operator
$ cd app-operator
# Add a new API for the custom resource AppService
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
We are looking for your feedback.
Thank you for your prompt reply
It's a new project
Now I have doubts on the flag --repo github.com/example-inc/app-operator . I'm not sure I do really understand it
Here are the steps I performed and got the error
mkdir pc-operator
cd pc-operator
operator-sdk new pc-operator --repo pc-operator/operator
cd pc-operator
operator-sdk add api --api-version=sw.pc/v1alpha1 --kind=Chan
@zanoubia --repo can be used at any time, but is required if not in $GOPATH/src since the value passed is used to configure go mod init. However setting the repo shouldn't cause your issue. Looks like operator-sdk is trying to scaffold an invalid Go file. I can't reproduce this either.
any ideas of workarounds ? should I use a different sdk version ?
Hi again,
I tried to make it work inside container using the golang latest docker images. I worked in src directory so no --repo flag.
operator-sdk version: "v0.15.2", commit: "ffaf278993c8fcb00c6f527c9f20091eb8dd3352", go version: "go1.13.3 linux/amd64"
I get the same errors as previous error :s :s
https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525206318
as suggested in the comment of the issue above, GOROOT in go env is not enough, it should also be exported as linux env var.
However, I still get this error when i run the command the first time:
operator-sdk add api --api-version=sw.pc/v1alpha1 --kind=Chan
INFO[0000] Generating api version sw.pc/v1alpha1 for kind Chan.
Error: scaffold group file: my-operator/pkg/apis/sw/group.go:6:9: expected 'IDENT', found 'sw'
I run the second time, now it succeed on the first step and also in deepcopy but i have this:
INFO[0002] Running deepcopy code-generation for Custom Resource group versions: [sw:[v1alpha1], ]
INFO[0007] Code-generation complete.
INFO[0007] Running CRD generator.
-: pkg/apis/sw/group.go:1:1: expected 'package', found 'EOF'
Error: error generating CRDs from APIs in pkg/apis: error generating CRD manifests: error running CRD generator: not all generators ran successfully
I'm still working on the golang container, if anyone can reproduce the errors
Hi @zanoubia,
I'd recommend to you:
$ export GO111MODULE=off
$ go clean --modcache
$ go clean
Note that the error faced shows that your local project has some errors in the file and we are not able to reproduce your issue and all lead to some error in the local env.
Hi @camilamacedo86 ,
I restarted from scratch. I created an empty brand new golang container from the golang official image. I made sure the env variables are good. Installed the sdk from the latest release (followed the install guide).
Still having the first error:
Error: scaffold group file: my-operator/pkg/apis/sw/group.go:6:9: expected 'IDENT', found 'sw'
then the latest error :
INFO[0049] Code-generation complete.
INFO[0049] Running CRD generator.
-: pkg/apis/sw/group.go:1:1: expected 'package', found 'EOF'
Error: error generating CRDs from APIs in pkg/apis: error generating CRD manifests: error running CRD generator: not all generators ran successfully
Hi @zanoubia,
Could you please let me know if you are able to follow the Quick Start and/or Getting Started instructions as asked in https://github.com/operator-framework/operator-sdk/issues/2596#issuecomment-593562274 or are you facing the same issue?
# Create an app-operator project that defines the App CR.
$ mkdir -p $HOME/projects/example-inc/
# Create a new app-operator project
$ cd $HOME/projects/example-inc/
$ operator-sdk new app-operator --repo github.com/example-inc/app-operator
$ cd app-operator
# Add a new API for the custom resource AppService
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
Note the above test is out of $GOPATH.
Also, let us know the result of :
# Create an app-operator project that defines the App CR.
$ ce $GOPATH/src/
$ operator-sdk new app-operator2 -
$ cd app-operator2
# Add a new API for the custom resource AppService
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService2
Also, could you please provide your Go env (Result of go env).
Hi @camilamacedo86 ,
Using your example, it works perfectly when I export GOROOT as env var in linux . However when using my API and Kind custom names it doesn't.
Is there any naming restriction or syntax to follow when naming the APIs and Kinds ?? That's the only thing that could explain this weird behaviour.
Using your example, it works perfectly when I export GOROOT as env var in linux . However when using my API and Kind custom names it doesn't.
What do you mean with Using your example, it works perfectly when I export GOROOT as env var in linux? Are you doing export GOROOT=$(go env GOROOT)? Is it? If yes, it will fix your GOROOT.
Is there any naming restriction or syntax to follow when naming the APIs and Kinds ?? That's the only thing that could explain this weird behaviour.
The APIs and Kinds will need to respect the K8S api restrictions.
Note that we are doing as you described and we are unable to reproduce the issue and all lead us to a local env setup issue. See
Hi,
What do you mean with
Using your example, it works perfectly when I export GOROOT as env var in linux? Are you doingexport GOROOT=$(go env GOROOT)? Is it? If yes, it will fix your GOROOT.
Yes That's what I did
The APIs and Kinds will need to respect the K8S api restrictions.
Note that we are doing as you described and we are unable to reproduce the issue and all lead us to a local env setup issue
When I use --api-version=app.example.com/v1alpha1 --kind=AppService , it works. When I use our own names it doesn't work. The tests for both cases were done in clean golang docker containers with the same go env.
I'm closing the issue since you can't reproduce the errors. I'll dig further and keep you updated.
The api version can't start with any of the reserved words of go ( like select, range ....) so if the api name is like select.example.com it will give the same errors as above, and the error is not clear.
Maybe a check on the api version before running must be included in the sdk
Hi @zanoubia,
Regards to :
The api version can't start with any of the reserved words of go ( like select, range ....) so if the api name is like select.example.com it will give the same errors as above, and the error is not clear.
Maybe a check on the api version before running must be included in the sdk.
It shows another scenario. Could you please track a new issue for that?
@camilamacedo86 , yes sure ;)
Most helpful comment
@camilamacedo86 , yes sure ;)