sample-controller: The update-codegen script does not automatically generate files & directories
To quote the README:
The update-codegen script will automatically generate the following files & directories:
- pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go
- pkg/generated/
But:
$ git clone https://github.com/kubernetes/sample-controller.git
$ cd sample-controller
$ rm -f pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go
$ ./hack/update-codegen.sh
Generating deepcopy funcs
Generating clientset for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/clientset
Generating listers for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/listers
Generating informers for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/informers
$ ls pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go
ls: pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go: No such file or directory
Am I misunderstanding how this is supposed to work?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (10 by maintainers)
Here’s what I’ve figured out from a couple of hours of faffing around with this:
The first problem is “how do you run generate-groups.sh”? There are two answers. One was pointed out by @farah : populate the vendor directory. The other is to clone the code-generator project so that it’s a sibling of sample-controller (which is where it lives in the kubernetes/kubernetes repo). You can look in hack/update-codegen.sh and you’ll see that the script looks in the vendor directory and then falls back to …/code-generator.
The second problem is “where does generate-groups.sh put the files that it generates”? Remember how this repo is a mirror of a small part of kubernetes/kubernetes? Well, generate-groups.sh assumes and requires that everything is laid out exactly like it is in the kubernetes project. In that project, sample-controller is in k8s.io/sample-controller, i.e. {parent}/{project}. You’ll see in generate-groups.sh that it goes up three directories, then uses the module path as a directory path which means that it doesn’t work properly if your project’s module isn’t {parent}/{project}. You can hack update-codegen.sh to use a different output-base but you might still end up having to move the files after they’re generated. I did.
This smells like it was written before Go modules and never updated to work with modules since it just so happens to work with the directory structure in the kubernetes/kubernetes project.
HTH
This works for me:
hey @max-rocket-internet, just realised that the fix is actually in the read me. Run
go mod vendorand you should be good.Reopened for @vadasambar but I moved on from this topic a long time ago 🙂
TBH I think this code generation thing adds more headache/complexity than it solves, especially when you’re just beginning to write a controller using this repo as a start.