buehler/dotnet-operator-sdk

Go Templating

Closed this issue · 1 comments

So, this is more of a discussion topic. I am aware there is no easy answer for this.

There is a general pattern of developing Kubernetes operators that generate other objects using Golang templates embedded as strings within a CRD. An example is the 'ExternalSecret' type, which supports pulling values from Azure Keyvault, etc, into K8S Secrets.

The 'ExternalSecret' CRD, for example, allows you to simply put a Golang template into the body of a Spec property, and the operator executes that template against the external secret data, allowing you to format the contents of the external secret.

https://external-secrets.io/v0.4.4/guides-templating/

Since K8s is so go-y, this makes good sense. It fits nicely into the eco system.

However, this presents an issue when using The DotNet operator! We don't have access to Go-lang templates! What to do!

I happen to have a need for this currently in my operator. So my approach right now is going to be to include a Handlebars template, since there is a well-designed and maintained Handlebars.NET package. But this is unfortunate, as my CRDs won't fit into the overall K8s ecosystem as cleanly.

The proper solution would probably be a DotNet native implementation of Go templates.

A less good solution would be invoking the Go lang template engine from within a DotNet operator.