code-generator: 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”
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 57 (13 by maintainers)
@droslean I have solved this problem, add ”-v 10“ flag, and the following errors were found:
so copy api/crd.k8s.xxx.com/v1 to ./vendor
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…
Hello,there. I have the problem something similar. I use the shell script to generate code, but I got only one clientset folder and which is almost empty. There is no any Errors or Warnings.The code I used is just the same as the sample-controller.
My project is just like this:
the shell script to generate code:
My go.mod file:
The response is no Erroers
And the generated folder only has a clientset folder in it, and its just almost empty:
I don’t realy know what’s the problem is.
workdir:
./vendor/k8s.io/code-generator/generate-groups.sh “all” “./pkg/generated” “./pkg/apis” “samplecrd:v1” -o “./” --go-header-file “./hack/boilerplate.go.txt”
this is ok for me
@harryyann I was facing a similar issue. Mine was because the tags were not set correctly in types.go. i had a few empty lines between the comment and the struct definition. The gengo parser was skipping this saying the doesn’t need a client code generation
The below is what is had initially.
I change it as follows to get it working
There were some issues with the directory structure also. I felt instead of ironing out the supported directory structure it is easier to make a directory structure which the generator expect.
I have the structure as follows from the workspace root
The tree is mimicking the module name github.com/user/repo
The generator is executed from the module directory github.com/user/repo
I have uploaded a sample code here incase needed https://github.com/naduvat/k8s-codegen-basic
@harryyann I have the same problem.Only clientset was generated.
This issue is till there for me, can anyone help?
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@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:
go.modstarts with the linemodule github.com/onkarbanerjee/crd-code@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
Thank you @antoineco I indeed added that parameter and now it works.