What did you do?
I followed the quick start guide, in the step of adding an api :
operator-sdk add api --api-version=range.myapp.com/v1alpha1 --kind=MyKind --verbose
What did you expect to see?
Creation of the new api
What did you see instead? Under which circumstances?
A clear and concise description of what you expected to happen (or insert a code snippet).
root@2f94211c5c15:/go/src/myapp-operator# operator-sdk add api --api-version=range.myapp.com/v1alpha1 --kind=Mykind --verbose
DEBU[0000] Debug logging is set
INFO[0000] Generating api version range.myapp.com/v1alpha1 for kind Mykind.
Error: scaffold group file: /go/src/myapp-operator/pkg/apis/range/group.go:6:9: expected 'IDENT', found 'range'
Usage:
operator-sdk add api [flags]
Flags:
--api-version string Kubernetes APIVersion that has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)
-h, --help help for api
--kind string Kubernetes resource Kind name. (e.g AppService)
--skip-generation Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs
Global Flags:
--verbose Enable verbose logging
root@2f94211c5c15:/go/src/myapp-operator# operator-sdk add api --api-version=range.myapp.com/v1alpha1 --kind=Mykind --verbose
DEBU[0000] Debug logging is set
INFO[0000] Generating api version range.myapp.com/v1alpha1 for kind Mykind.
INFO[0001] Created pkg/apis/range/v1alpha1/mykind_types.go
INFO[0001] Created pkg/apis/addtoscheme_range_v1alpha1.go
INFO[0001] Created pkg/apis/range/v1alpha1/register.go
INFO[0001] Created pkg/apis/range/v1alpha1/doc.go
INFO[0001] Created deploy/crds/range.myapp.com_v1alpha1_mykind_cr.yaml
INFO[0001] Running deepcopy code-generation for Custom Resource group versions: [range:[v1alpha1], ]
INFO[0008] Code-generation complete.
INFO[0008] Running CRD generator.
-: pkg/apis/range/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
Usage:
operator-sdk add api [flags]
Flags:
--api-version string Kubernetes APIVersion that has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)
-h, --help help for api
--kind string Kubernetes resource Kind name. (e.g AppService)
--skip-generation Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs
Global Flags:
--verbose Enable verbose logging
Environment
root@2f94211c5c15:/go/src/myapp-operator# operator-sdk version
operator-sdk version: "v0.15.2", commit: "ffaf278993c8fcb00c6f527c9f20091eb8dd3352", go version: "go1.13.3 linux/amd64"
root@2f94211c5c15:/go/src/myapp-operator# go version
go version go1.14 linux/amd64
Kubernetes cluster kind:
Are you writing your operator in ansible, helm, or go?
Go
Possible Solution
Workaround by user: choose different api name ... clean cache and recreate project directory
Solution: check the api name if it starts with a reserved go word and raise exception with meaningful error
Additional context
Working inside golang docker container
Tested apis names: select.myapp.com , switch.myapp.com, package.myapp.com ,range.myapp.com
HI @zanoubia,
I could reproduce this scenario. Then, I am flagging it as a bug for we are able to address it in a better way.
$ operator-sdk add api --api-version=range.myapp.com/v1alpha1 --kind=MyKind --verbose
DEBU[0000] Debug logging is set
INFO[0000] Generating api version range.myapp.com/v1alpha1 for kind MyKind.
Error: scaffold group file: /Users/camilamacedo/go/src/github.com/operator-framework/operator-sdk-samples/go/memcached-operator/pkg/apis/range/group.go:6:9: expected 'IDENT', found 'range'
Usage:
operator-sdk add api [flags]
Flags:
--api-version string Kubernetes APIVersion that has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)
-h, --help help for api
--kind string Kubernetes resource Kind name. (e.g AppService)
--skip-generation Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs
Global Flags:
--verbose Enable verbose logging
PS.: It shows an issue to scaffold the group file when the group has a reserved name.
@estroz @hasbro17 it is something that could be solved by the integration. So, IMO we should check it there instead of to do the fix in SDK. WDYT?
Following some info about this one discussed in the bug triaged:
pkg/apis/range/group.go file and add the import with the name of the group it will not work because the word is restrictive for GO language. So, what is required to do here:
Checked that this issue does not occur with the scaffold layout of Kubuilder. Following at the end the test done. Then, it will be solved with the integration with. So, IHMO we can close this one.
Any objection @jmrodri @hasbro17?
camilamacedo@Camilas-MacBook-Pro ~/go/src $ rm -rf mkdir $GOPATH/src/example
camilamacedo@Camilas-MacBook-Pro ~/go/src $ mkdir $GOPATH/src/example
camilamacedo@Camilas-MacBook-Pro ~/go/src $ cd $GOPATH/src/example
camilamacedo@Camilas-MacBook-Pro ~/go/src/example $ kubebuilder init --domain my.domain
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/[email protected]
Update go.mod:
$ go mod tidy
Running make:
$ make
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
Next: define a resource with:
$ kubebuilder create api
camilamacedo@Camilas-MacBook-Pro ~/go/src/example $ kubebuilder create api --group range.myapp.com --version v1 --kind Guestbook
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing scaffold for you to edit...
api/v1/guestbook_types.go
controllers/guestbook_controller.go
Running make:
$ make
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
camilamacedo@Camilas-MacBook-Pro ~/go/src/example $ make install
/Users/camilamacedo/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
kustomize build config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/guestbooks.range.myapp.com.my.domain created
camilamacedo@Camilas-MacBook-Pro ~/go/src/example $ make run
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
/Users/camilamacedo/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
go run ./main.go
2020-03-10T12:39:53.585Z INFO controller-runtime.metrics metrics server is starting to listen {"addr": ":8080"}
2020-03-10T12:39:53.585Z INFO setup starting manager
2020-03-10T12:39:53.585Z INFO controller-runtime.manager starting metrics server {"path": "/metrics"}
2020-03-10T12:39:53.689Z INFO controller-runtime.controller Starting EventSource {"controller": "guestbook", "source": "kind source: /, Kind="}
2020-03-10T12:39:53.790Z INFO controller-runtime.controller Starting Controller {"controller": "guestbook"}
2020-03-10T12:39:53.891Z INFO controller-runtime.controller Starting workers {"controller": "guestbook", "worker count": 1}
^Z
[4]+ Stopped make run
Hi @zanoubia,
The SDK is in the process to integrate with Kubebuilder, which means that the scaffold files will follow the same Kubebuilder structure and then, this issue will no longer be faced.
So, since it not critical and will be solved with the integration I am closing this one. However, please, feel free to ping us if you think that it should be re-opened.
Thank you @camilamacedo86 . I will test once the new version is out.
Would you please guide me to links to know more on SDK/kubebuilder integration ?
Hi @zanoubia,
The proposal doc can be checked here.
We have not an ETA for that but the plan is that it is ann requirement for the release of 1.0.0 which is not the next version.
Also, feel free to join us in the Community meetings too. See: https://github.com/operator-framework/community