2

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
dinup24
  • 1,652
  • 3
  • 16
  • 26

1 Answers1

0

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

func Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) 
The Fool
  • 16,715
  • 5
  • 52
  • 86