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

Parameter inheritence #302

Open
jaxxstorm opened this issue Nov 21, 2019 · 2 comments
Open

Parameter inheritence #302

jaxxstorm opened this issue Nov 21, 2019 · 2 comments

Comments

@jaxxstorm
Copy link

More of a feature request, maybe this is already possible but maybe not.

I use jk pretty heavily for regional deployments and the ability to set parameters for the regional deployments. As an example:

deployment/kube/jk/params
├── eu-central-1.yaml
├── us-east-1.yaml
└── us-west-2.yaml

Here you can see I've got parameter files for each region I deploy to.
Often, the configuration is the same for configurable values in lots of regions with a few slight differences. What I'd like to be able to do is have parameter inheritence through a directory tree, in a similar manner to hiera

How might this look in practice? Well, you'd have a directory structure like this:

deployment/kube/jk/params
├── defaults.yaml
├── regions
│   ├── eu-central-1.yaml
│   ├── us-east-1.yaml
│   └── us-west-2.yaml

Then, as an example, we'd have parameters in defaults.yaml like so:

s3_bucket: my_default_bucket

If the value existed lower down the hierarchy (for example, in regions/us-west-2.yaml it would be the preferred loaded parameter:

s3_bucket: my_uw2_bucket

If this value doesn't exist, it falls back to the default parameters in defaults.yaml.

I imagine this would be another params function, let's say:

const bucket = paramFromTree.String('bucket');
@dlespiau
Copy link
Member

dlespiau commented Nov 23, 2019

Hi!

The input parameters from the command line are merged from left to right so you can do:

jk generate -f defaults.yaml -f regions/us-west-2.yaml ...

and the values of the regional file are merged into the default values.

The rules for this merging are fixed: objects are deep merged but other values (arrays and primitive values) are taken from the right most file.

If you need more, we have now std/merge that can do arbitrary merging: you supply functions to merge the right and left objects/arrays/values. For instance, if you want to merge arrays by taking elements from both sides but ensuring the merge has unique elements, you can just provide the function that does that to merge.

I'll come up with examples in the next few days, I'd like to start writing examples for questions that arise :)

HTH

@adnaan
Copy link

adnaan commented Jul 27, 2020

@dlespiau don't see a way to supply a merge function to either jk run or jk generate. Do you mean we need to read the files on our own and use std/merge ?

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

3 participants