tazjin/kontemplate

Templating in imported YAML and JSON files

xanonid opened this issue · 3 comments

It would be nice if additional YAML and JSON files that are imported using the import statement to add global values support also templating.
This would allow to use e.g. passLookup only in some contexts without adding much logic into the resource files or using variables of the global: section of the Cluster configuration file to be re-used easily.

Hey, thanks for the suggestion.

You mean they should support variables and be templated before loading the contained variables? It's technically possible (and not that difficult to implement) but sounds a bit odd to me.

The thing is that they're loaded at the top-level, so the templating wouldn't necessarily contain any variables (except maybe the global section) - so it would be purely for static data transformation or side effects like passLookup.

Could you describe what you'd use this for exactly?

The reason I'm asking is mostly that I want to avoid adding features that complicate the conceptual model unless absolutely necessary.

Cheers!

Yes, exactly - thanks for your fast response. Static data transformations and side effects are exactly what I would need.

The current setup I am working on has two contexts. Due to specialties in the build pipeline, passLookup is only needed and available in one context, but not in the other.
Currently I have to do to something like:

#### settings_contextA.yaml:
 app: 
   password: myunsafepassword

#### settings_contextB.yaml:
 app: 
   password: ''

#### a resource file:
[...]
kind: Secret
data:
  password: {{if .app.password}}{{.app_password }}{{else}}{{passLookup "app/password"}}{{end}}

If templating is available at top-level, this would be much easier, as the logic can be moved to the context settings files (and does not need to be repeated in the resource files if it is used more than once).

With the proposed templating, the solution would be:

#### settings_contextA.yaml:
 app: 
   password: myunsafepassword

#### settings_contextB.yaml:
 app: 
   password: {{ passLookup "app/password" }}

#### a resource file:
[...]
kind: Secret
data:
  password: {{.app.password}}

If variables from the global section are also available, more logic can be already "templated" in the import files, e.g. calculations based on the replication factor.

The source of kontemplate is moving to git.tazj.in and I've moved this issue to the depot@tazj.in mailing list over here.