stefanprodan / timoni

Timoni is a package manager for Kubernetes, powered by CUE and inspired by Helm.
https://timoni.sh
Apache License 2.0
1.51k stars 67 forks source link

Creating a ConfigMap entry from a YAML file #275

Open mattfield opened 8 months ago

mattfield commented 8 months ago

Hello!

I might be thinking about this in the wrong way so please do correct me!

I'm creating a Timoni module that, before conversion to CUE, was using Kustomize to generate a ConfigMap from a config YAML file (which is a few hundred lines long). This config YAML is different depending on environment and region, so I had the option to override the default YAML built in the Kustomize base.

What's the most straightforward to replicate this kind of pattern with Timoni? I had originally thought to pass a path to the config YAML as a value and then have Timoni import that YAML and assign it to the correct key in the ConfigMap but I can't quite figure out how to do that, or even whether it'd be the correct approach. I'm also planning on using Bundles and Runtimes so I wonder if pre-storing that config in the ConfigMap and reading it into Timoni via a Runtime at apply time would be another viable option, though that would still require getting the ConfigMap created in the first place which is the part I'd like to keep in the Module itself.

I'm sure there's a much more idiomatic Timoni/CUE way of handling something like this, so any and all advice greatly appreciated! Thanks!

b4nst commented 8 months ago

There's multiple way of doing that. You could load your file in an environment variable and use --runtime-from-env if you want to keep it as a raw string.

Since CUE is YAML compatible, you can also put your content as a value:

#Config: {
  cmValue: _
 }

Then you would have to modify your yaml file to nest the content under values: cmValue and pass it directly to your bundle/module apply. This way also enables you to type your config (by being more restrictive than just the _ I used here).

And in your ConfigMap definition, you can use yaml.Encode(_config.cmValue) as your content.

I think runtime injection from a local file would still be useful, for other types of configuration files (like INI, toml and such). This brings the issue of path relativeness (should it be to the command? to the bundle? to the module?) so this is something tbd with @stefanprodan. Imo we should use relativeness to where it is defined (probably the bundle file).