2

I want to use serving api which is the part of the knative serving repo to create serving application. Since i'm writing a custom controller, i need to make use of Go client. I'm finding it difficult to generate boiler plate code using the code-generator. I'm following the below mentioned blog on how to do it.

  1. https://insujang.github.io/2020-02-13/programming-kubernetes-crd/#write-template-code
  2. https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/

But i couldn't achieve it. Any help is appreciated.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
coders
  • 719
  • 1
  • 11
  • 35
  • You should probably include the code that you've tried and be more precise about what went wrong, like what errors you encountered, or what was the expected output vs what was the actual output. – mkopriva Oct 06 '20 at 14:36
  • i couldn't achieve it, its like a dead end with no proper blogs from the official developers itself forget about executing. – coders Oct 06 '20 at 15:38

1 Answers1

3

Yes, code generation for controllers is not the most easy thing. And it has changed over the years.

To start writing a controller with code generation, I would recommend to use Kubebuilder and follow the Kubebuilder guide. And perhaps do custom things when that is understood.

The Kubebuilder guide includes chapters on how to generate CRD code using controller-gen.

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Yes i totally agree. No proper guide as well. kind of stuck now.. – coders Oct 06 '20 at 15:43
  • @coders have you tried the kubebuilder guide that I linked to? It is an easier way to create a controller in Go. – Jonas Oct 06 '20 at 15:46
  • do you any idea on how is this https://github.com/knative-sandbox/sample-controller is generated? – coders Oct 06 '20 at 18:13
  • you can see in the `hack/` directory, it is using the older `code-generator` https://github.com/knative-sandbox/sample-controller/tree/master/hack – Jonas Oct 06 '20 at 18:34
  • You can also look at [operator-sdk](https://github.com/operator-framework/operator-sdk) which builds on top of controller runtime and kubebuilder to make developer life easier. Specifically things like CRD and K8S API code generation – ashu Oct 06 '20 at 19:19
  • To be honest, Kubebuilder / Operator-SDK (they're moving towards merging the projects) are probably the easiest way to bootstrap a controller. If you're looking for a lower-level approach, check out this blog post: https://insujang.github.io/2020-02-13/programming-kubernetes-crd . Just keep in mind that this uses pre-GOMODULE tools and needs a hacky workaround to work. The Knative team has more or less written their own version of controller-runtime (the backbone of Kubebuilder), so using Knative's framework would just be a less documented way to the same goal – Chase Walden Oct 23 '20 at 02:10