Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a ConfigMap entry from a YAML file #275

Open
mattfield opened this issue Dec 11, 2023 · 1 comment
Open

Creating a ConfigMap entry from a YAML file #275

mattfield opened this issue Dec 11, 2023 · 1 comment

Comments

@mattfield
Copy link

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
Copy link
Contributor

b4nst commented Dec 19, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants