在操作员中使用模板/覆盖库

发布于 2025-02-04 20:30:58 字数 572 浏览 2 评论 0 原文

当使用 operatorsdk构建运营商:GO 框架时,我们最终创建了Kubernetes资源,例如部署服务等,通过利用K8S模块/软件包的结构来编程。与以YAML/JSON格式创建这些清单相比,这很麻烦,需要大量编码。对清单的任何更改都需要更改代码,并且需要推出操作员的新版本。

我想知道现有的模板/覆盖工具(例如Helm或Kustomize)是否可以用于在操作员代码中构建这些K8S资源。这也将使您可以将清单/模板文件与操作员代码外部化。我找不到任何很好的例子,说明如何将这些工具用作GO程序中的模块/库。请提供任何指示,建议或替代方法。

相关问题: kubernetes操作员使用yaml Template创建部署 您可以读取YAML文件并将其删除到部署对象中。在这里,我仍然需要在操作员内编码模板/覆盖逻辑。

While building operators using OperatorSDK: Go framework, we end up creating Kubernetes resources such Deployments, Services etc programmatically by leveraging structs from k8s modules/packages. Compared to creating these manifests in yaml/json formats, this is quite cumbersome and requires quite a bit of coding. And any changes to the manifest would require code changes and the new version of the operator needs to be rolled out.

I am wondering whether existing templating/overlay tools such as Helm or Kustomize can be used for building these k8s resources within the operator code. This would also enable you to externalise the manifest/template files from the operator code. I couldn't find any good examples of how these tools can be used as modules/libraries within a Go program. Please provide any pointers, suggestions or alternate approaches.

Related question: Kubernetes operator create Deployment using yaml template

This talks about how you can read a yaml file and unmarshal it into a Deployment object. Here, I would still need to code templating/overlay logic within the operator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2025-02-11 20:30:58

您可以通过编程使用掌舵发动机,通过调用

func Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) 

You can use the helm engine programmatically, by calling engine.Render.

func Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文