简体   繁体   English

如何使用代码生成器为自定义资源定义生成代码

[英]How to generate code using the code generator for the custom resource definition

I want to use serving api which is the part of the knative serving repo to create serving application.我想使用服务 api,它是 knative 服务仓库的一部分来创建服务应用程序。 Since i'm writing a custom controller, i need to make use of Go client.由于我正在编写自定义控制器,因此我需要使用 Go 客户端。 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 https://insujang.github.io/2020-02-13/programming-kubernetes-crd/#write-template-code
  2. https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/ https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/

But i couldn't achieve it.但我无法实现。 Any help is appreciated.任何帮助表示赞赏。

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 .要开始编写带有代码生成功能的控制器,我建议使用 Kubebuilder 并遵循Kubebuilder 指南 And perhaps do custom things when that is understood.也许在理解后做一些定制的事情。

The Kubebuilder guide includes chapters on how to generate CRD code using controller-gen . Kubebuilder 指南包括有关如何使用controller-gen生成 CRD 代码的章节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM