code-generator
code-generator copied to clipboard
code-generator don't generate clientset, informer and lister
Question:
When I use code-generator try to generate the clienset, informer and lister, it does not tell me any issue, but when I check the generate folder, it only have clientset, and the content is almost empty
My *_type.go file as below: package v1beta1
import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" )
// +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true // +resource:path=containersets
// +kubebuilder:object:root=true
// Appmgmt is the Schema for the appmgmts API
type Appmgmt struct {
metav1.TypeMeta json:",inline"
metav1.ObjectMeta json:"metadata,omitempty"
Spec AppmgmtSpec `json:"spec,omitempty"`
Status AppmgmtStatus `json:"status,omitempty"`
}
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// AppmgmtSpec defines the desired state of Appmgmt type AppmgmtSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file
// Foo is an example field of Appmgmt. Edit Appmgmt_types.go to remove/update
// Foo string `json:"foo,omitempty"`
FindNamespace string `json:"findnamespace"`
Image string `json:"image"`
Env []Env `json:"env"`
Ports int `json:"ports"`
ImagePullSecret string `json:"imagePullSecret"`
}
type Env struct {
Name string json:"name"
}
// AppmgmtStatus defines the observed state of Appmgmt
type AppmgmtStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
TestStatus string json:"testStatus"
}
// +kubebuilder:object:root=true
// AppmgmtList contains a list of Appmgmt
type AppmgmtList struct {
metav1.TypeMeta json:",inline"
metav1.ListMeta json:"metadata,omitempty"
Items []Appmgmt json:"items"
}
var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "appmgmt", Version: "v1beta1"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion})
func init() { SchemeBuilder.Register(&Appmgmt{}, &AppmgmtList{}) }
Environment as below: $go version go version go1.13.8 linux/amd64
$ kubectl version Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.4", GitCommit:"224be7bdce5a9dd0c2fd0d46b83865648e2fe0ba", GitTreeState:"clean", BuildDate:"2019-12-11T12:47:40Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.7", GitCommit:"20c697423de11d4d5d08c6832a513217ca11a6aa", GitTreeState:"clean", BuildDate:"2020-02-21T10:47:45Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
$go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/root/workspace/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/root/installation/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/root/installation/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build867010754=/tmp/go-build -gno-record-gcc-switches"
This is what have been generate, it is very strange, and when I check file generated/clientset/versioned/clientset.go only have one word "package versioned"
Code generators write to a directory relative to $GOPATH/src
.
In your case:
-
$GOPATH/src/appmgmt-operator/generated/appmgmt-operator/api/clientset
-
$GOPATH/src/appmgmt-operator/generated/appmgmt-operator/api/listers
-
$GOPATH/src/appmgmt-operator/generated/appmgmt-operator/api/informers
I guess the question is integrate with the operator-sdk. If I only write a types.go and use the code-generate, that is success, the informer and lister and clientset generate correct.
Is your code available somewhere so I can try to reproduce?
I had the same problem, using an operator-sdk.
If you use operator-sdk, and use the code-generate to generate the clientset, informers, then you will get fail. But if you only write apis_types.go by yourself in a empty project, then you can use the code-generate to generate the clientset, informers and so on
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen
.
Mark the issue as fresh with /remove-lifecycle rotten
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close
@fejta-bot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity. Reopen the issue with
/reopen
. Mark the issue as fresh with/remove-lifecycle rotten
.Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
@gabrik because by default code generators try to read ${GOPATH}/src/k8s.io/code-generator/hack/boilerplate.go.txt
. Notice the $GOPATH in there. That means you have to manually clone the code-generator repository at this location on your machine.
There is a better and simpler approach though:
I see you have your own boilerplate file in the repo you linked. That means you have to reference it manually by passing --go-header-file hack/boilerplate.go.txt
at the end of this line.
Here is an example: https://github.com/knative-sandbox/eventing-gitlab/blob/602b94319985c830fa2a9ba978e3f3c5886a760b/hack/update-codegen.sh#L34-L37
Thank you @antoineco I indeed added that parameter and now it works.
/remove-lifecycle stale
/remove-lifecycle rotten
/open
/reopen
@chrislovecnm: Reopened this issue.
In response to this:
/reopen
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
@antoineco I am having the same problem. and I am using a custom template. Where is the shell script located that you are calling?
I am reopening this issue because it would be awesome if we can get some documentation around this. A lot of codebases are using the operator sdk and client-gen together. If I have time I am happy to document this problem, but I have no idea how to fix it yet.
/area documentation
@chrislovecnm: The label(s) area/documentation
cannot be applied, because the repository doesn't have them.
In response to this:
@antoineco I am having the same problem. and I am using a custom template. Where is the shell script located that you are calling?
I am reopening this issue because it would be awesome if we can get some documentation around this. A lot of codebases are using the operator sdk and client-gen together.
/area documentation
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/open
This issue is till there for me, can anyone help?
@onkarbanerjee yes, if you describe your issue I can try to help.
Please provide snippets of your scripts, the structure of your project, and the errors you're seeing.
@antoineco Thanks for your response. Here is what I am trying to do.
This is my code directory structure
This is my types.go
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Database struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DatabaseSpec `json:"spec"`
}
// DatabaseSpec is the spec for a Foo resource
type DatabaseSpec struct {
User string `json:"user"`
Password string `json:"password"`
Encoding string `json:"encoding,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DatabaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Database `json:"items"`
}
This is my doc.go
// +k8s:deepcopy-gen=package
// Package v1 is the v1 version of the API.
// +groupName=example.com
package v1
I am running the script like below:
I am not seeing any error as you can see above , but there are no files created ever
@onkarbanerjee chances are that your code was generated in $GOPATH/src/github.com/onkarbanerjee/crd-code
, and not in your current project's directory.
@antoineco No code generated.
Your screenshot doesn't show pkg/client
.
@antoineco It only has the clientset folder and the files in them are mostly empty.
append "-v 10" at the end of your command, it should tell where is wrong.
The tool would exit with success code when it has done nothing.......
@zq-david-wang It is unable to import the package it seems.
@onkarbanerjee this seems like a misconfigured Go project or Go toolchain to me. This goes beyond the topic of this discussion, but here are two ways to fix this:
- If your Go project uses modules, make sure
go.mod
starts with the linemodule github.com/onkarbanerjee/crd-code
- If it doesn't, please refer to Module-aware commands in the Go documentation