kubernetes / sample-controller

Repository for sample controller. Complements sample-apiserver
Apache License 2.0
3.14k stars 1.08k forks source link

Cluster scoped crd not working? #69

Closed toonsevrin closed 4 years ago

toonsevrin commented 4 years ago

Hi guys I tried to create a cluster scoped crd from this but the code-generator does not seem to recognize this, what am I doing wrong?

Reproduction:

git clone https://github.com/kubernetes/sample-controller
cd sample-controller

now I add // +genclient:nonNamespaced in the Foo section of the types.go file.

go mod vendor
./hack/update-codegen.sh

Now the code is still generated as if it is a namespaced resource (eg. exampleInformerFactory.Samplecontroller().V1alpha1().Foos().Lister().Foos() still takes namespace argument.

toonsevrin commented 4 years ago

All right, so this was a dependency problem: Because I was automatically populating go.mod, it pulled the latest version of my own project from github.

[https://wiki.tcbv.be/en/ict/kubernetes/developing_on_kubernetes](I've also documented my solution here). This resource may be handy if you're developing a CRD.

Updating my go.mod solved this issue:

module kuberdon

go 1.13

require (
    github.com/kuberty/kuberdon v0.0.0
    k8s.io/apimachinery v0.17.3
    k8s.io/client-go v11.0.0+incompatible
    k8s.io/code-generator v0.17.3
)

replace github.com/kuberty/kuberdon v0.0.0 => ./