Repository navigation
Description
I'd love to have the functionality of #662 but I wanted to throw my use-case in here while it's topical as what i'm suggesting is probably closer to #705.
We're deploying a bunch of apps, but one particular app has a helm vars file which expects over 150 config values (environment variables):
# example app.yaml.gotmpl
env:
FOO1: {{ requiredEnv "FOO1" | quote }} # fetched from /helm/$app/FOO1
FOO2: {{ requiredEnv "FOO2" | quote }} # fetched from /helm/$app/FOO2 etc.
....
FOO150: ....
As we have a bunch of different apps across a range of languages and platforms, for us at least, it is best to leave the secret fetching and templating to helm/helmfile.
With the PR as it is, individual SSM fetches would likely be slow and prevent us from overriding values with ENV vars (not to mention our paths different between environments), and we'd likely go back to longer deploys and AWS rate limiting. It would be more useful for us to be able to inject entire SSM paths (i.e. /helm/$app/*) as environment variables for a helm run instead of what we're doing now which is using chamber. Chamber is great but means we have to iterate our helmfile.yaml anyway, read in the list of apps and whether or not they are to be installed, and then execute helmfile for each and every one.
It'd be great to have something like the following:
# helmfile.yaml
releases:
- name: example which executes an app to inject values into the helm run
envExec:
- ["./my_script_that_exports_env_vars.sh", "{{MY_ENV}}", "{{$appName}}"] # `$appName` resolved from name in YAML file, `MY_ENV` passed in via env var
# or
- name: an integrated SSM plugin to inject values into the helm run
ssm:
paths:
- /helm/{{MY_ENV}}/{{$appName}}/ # recursively pulling in every param due to a trailing slash
- /helm/{{MY_ENV}}/{{$appName}}/or_individual_keys
Subsequently run with:
MY_ENV=test helmfile sync
or
MY_ENV=prod helmfile sync
In this example, the following keys:
/helm/test/app/FOO1
/helm/test/app/FOO2
Would be exported as:
FOO1=value_of_foo1_key
FOO2=value_of_foo2_key
Using env vars might simplify additional plugin development instead of using a custom resolver for each, as it makes it hard to template out the resolver.
Activity
mumoshu commentedon Jul 10, 2019
@acaire Hey! Thanks a lot for the detailed proposal.
I'm considering to enhance helmfile for this use-case but still figuring out how it should be done.
Would you mind reading my comment here #387 (comment) as the context - what if we added a mix of (1)a pluggable values provider interface and (2)a new configuration syntax that fits nicely with (1)?
The imaginary config would look like:
And the new syntax
valuesFromplays nicely with other use-cases outlined in #387 (comment) as well...Thoughts?
acaire commentedon Jul 10, 2019
@mumoshu thanks for the quick response! I'm curious about the comment: will be fetched and imported as a flat hash of kvs - Will this be imported directly into
.Values.FLAT_KEYas a 1:1 mapping with helm values, or available to be referenced as a helmfile value (i.e. like.Environment.Values?I'd like to delve further into our current use of helmfile - Here's a templated values file for a postgresql chart (this is a custom fork of the chart, but the basic concept remains):
and the related helmfile.yaml component:
Now if I wanted to set
initdb.env.FOO_URLfrom SSM, would I have to do something like this?Or would I have to store my values in SSM like this:
I'd welcome any implementation to take away some of the sticky tape we've put around secrets management, but something that simply injects env vars to a helm run, seems far simpler than putting too much work into a plugin system, at least if we were going to maintain a fork of helmfile 😄 If we ever change our secrets provider, or logic - we don't have to change any of our values templates, just how the values are fetched.
mumoshu commentedon Jul 10, 2019
@acaire Hey!
As the proposed
valuesFromresides underreleasesin my example above, it should be unable to mutate helmfile values(Neither .Environment.Values nor .Values) so the former seems correct if I didn't misread.However looking into your
foo-postgres.yaml.gotmpl, there is a bunch ofenvandrequiredEnvscattered across multiple levels of the yaml hashes.a flat hash of kvsdoesn't seem to help it.Perhaps your use-case should be addressed in terms of helmfile values?
What if we enhanced the syntax to:
Where your
foo-postgres.yaml.gotmplwill be written as:And in SSM you have the following keys set to corresponding values:
WDYT?
This seems to help your goal, in an another way.
acaire commentedon Jul 10, 2019
Ahh that clears it up perfectly, thanks! I'm guessing from your example we'd be able to do this per release, so this would be our final syntax:
With this
helmfile.yaml:So
.Values.FOOwith your gotmpl example as you've described would be evaluated as one, 2 or 3 matching the app name. 👍My only concern is terminology -
values:refers to values optionally rendered by a gotmpl file and passed to helm, but nowvaluesFrom:refers to values passed to a gotmpl file, which is then rendered and passed to helm. Complicated further by using the same.Values.FOOsyntax as helm ❓mumoshu commentedon Jul 10, 2019
No, it isn't how things work!
valuesFromunderreleases[]never refer to values passed to gotmpl files.acaire commentedon Jul 10, 2019
Sorry maybe I'm not explaining correctly.
Basically, you have a list of releases under
releases::I was just suggesting that re-using the term
valuesin thevaluesFrom:directive, may cause confusion.mumoshu commentedon Jul 10, 2019
releases[].valuesFromis an extensible alternative toreleases[].values, so in my understanding the explanations can be rewritten as:mumoshu commentedon Jul 10, 2019
And my hidden plan is deprecating
valuesin favor ofvaluesFrom, as this:is an equivalent of:
acaire commentedon Jul 10, 2019
ok, cool so the example you gave earlier:
Populates
initdb.env.FOO_URLwith{{.Values.FOO_URL}}; but also if the chart had aFOO_URLdefined invalues.yaml, it would set/overwrite that?As a more simplistic example, would this invalidate itself?
mumoshu commentedon Jul 10, 2019
Still trying to understand - What do you imagine to happen when it isn't invalidated?
acaire commentedon Jul 10, 2019
With a given SSM path specified via
valuesFrom, the returned parameters are flattened and available within a .gotmpl via{{.Values}}.i.e.
/helm/prod/postgres1/with a child keyinitdbwith a value oftruebecomes accessible via{{.Values.initdb}}in a .gotmpl file.But you're saying that this is also passed verbatim into the helm install? So if I didn't have a
.gotmplfile at all, helmfile would basically run--set initdb=trueas a helm arg.?And if I did have a
.gotmplfile, and specified it like this:You'd pass helm
--set initdb=trueand--set initdb.env.INITDB=true?mumoshu commentedon Jul 11, 2019
For the top level
valuesFrom, no.For
valuesFromunderreleases[], yes - onlyvaluesFroms underreleases[]are passed verbatim to helm.acaire commentedon Jul 11, 2019
ok thanks for clearing that up - It will mean we'll have to be careful about the naming choice of our SSM keys (so as not to cause clashes as describe above with strings/nested dicts), but otherwise that implementation will work for us 👍
mumoshu commentedon Jul 11, 2019
@acaire Thanks for confirming!
Yes. Naming SSM keys will be important.
I wanted to note one thing though - If we could enhance the syntax to specify where the KVs should be imported, you'll less likely encounter clashes.
Suppose we added
underto specify where to import KVs:All the KVs under
/helm/prod/postgres2will be available under{{.Values.foo.bar.}}so thatinitdbcould be accessed via{{.Values.foo.bar.initdb}}.5 remaining items
mumoshu commentedon Jul 12, 2019
@aegershman Hey! Thanks for chiming-in.
Sure. Here it is:
That sounds like a good idea :)
mumoshu commentedon Jul 12, 2019
@rms1000watt Thanks!
Understood. My idea was to make
typedefaults to the name of a plugin. That is:is equivalent to:
I like the distinction between type and name because it allows you to have different "plugin instances" with the same type but diversified configurations:
I'd prefer
pathPrefixoverpathunderplugins[]so that it is clearer that it isn't the "default" path:mumoshu commentedon Jul 12, 2019
@acaire Can we consider an another syntax that plays nicely with the
targetKeyfeature?What we have so far is:
But I want to suggest this as the alternative:
This also help smoothly extending the syntax for setting single kv:
I'm not satisfied about that
valuesFromactually import not only values but also keys.How about using
keysAndValuesFromfor that, like:acaire commentedon Jul 12, 2019
@mumoshu Happy with either implementation, but I do like
setValues- CouldvalueFromjust besource?keysAndValuesFromseems overly verbose for what i'd consider to be an easy concept to follow - Ultimately IMHO, people care most about getting values to helm - The keys are important to reference of course but the values are crucial.Also, Would there be a mechanism for recursion? (And while I think of it, caching previously fetched credentials across a helmfile execution?) I'd imagine some people would have a path like:
With:
would they be available as
.Values.foo.bar.encrypted.ONEandValues.foo.bar.decrypted.TWO? Also periods are valid path chars 😭mumoshu commentedon Jul 12, 2019
Interesting idea. Perhaps you felt "value" in
setValuesandvalue(s)Fromredundant?I think so, too!
What if we extend the existing
setto accept new things:vs
mumoshu commentedon Jul 12, 2019
I had not thought about that yet.
Good point!
Then maybe we'd use GetParametersByPath API and we'd better not recurse but import the path as-is.
For:
Helmfile will expose
encrypted/ONE.oneanddecrypted/TWO.twounder{{.Values.foo.bar}}.It will be accessed like:
Probably it will be addressed in #444
rms1000watt commentedon Jul 12, 2019
@mumoshu the other thing to consider is where to draw the line.
You could consider the only function of these plugins is to fill the environment. Then all usage of the plugins within the helmfile is just
{{ requiredEnv "var" }}.And blame it on 12-factor apps.. "Environment variables or nothing!" lololol jk 🤣
mumoshu commentedon Jul 13, 2019
@rms1000watt The fundamental problem I see there is that helmfile shouldn't mutate envvars. Otherwise multiple concurrent releases when
--concurrencyis set to some value greater than 1 will can end up data race on envvars :)Helmfile can possibly be enhanced to internally translate
requiredEnv "var"to.Values.varbut thenrequiredEnvisn't really accessing any envvar so its name is quite confusing.To me the point of 12-factor apps is that you should be able to use envvars to set/override any settings at runtime.
For that I believe you can already wire-up things to honor that today, writing a template expression like
{{ default .Values.foo (env "FOO") }}.But from your previous comments I didn't think it, honoring 12-facor apps rules, is your actual goal. Wouldn't your goal be no need to rewrite go templates and values.yaml files each time you switch the backend(SSM, values files, templates)?
If so, that's one of goals of the
setValues/valuesFromproposal 😃mumoshu commentedon Jul 23, 2019
Related: #760 (comment)
mumoshu commentedon Sep 6, 2019
JFYI, this is the backend of this feature I've developed externally: https://github.com/mumoshu/values
It has support for:
rms1000watt commentedon Sep 6, 2019
@mumoshu
valueslooks beautiful. It looks like the perfect compliment tohelmfile🤣👍👍🙌🙌💙Is it something you need help integrating with
helmfile?mumoshu commentedon Sep 6, 2019
@rms1000watt Yup, we need to integrate it into Helmfile 😃
vladfr commentedon Sep 10, 2019
@mumoshu Hi! been following these threads for a while.
valueslooks great, it's pluggable and generic enough, while keeping the yaml small. Kudos!mumoshu commentedon Oct 25, 2019
@rms1000watt @acaire @vladfr I'm super excited about that SSM and also AWS Secrets Manager are finally supported via #906! Would you mind testing it out?
We've ended up with different syntax than what we've discussed in this thread.
But it turned out to provide more flexible configuration especially when combined with go templates.
Also, in near future, that syntax will allow us to keep references to secrets as-is, and defer the secrets retrieval to the time of
kubectl applywhen used with something likehelmfile template --no-process-refs. Good fit for GitOps without SealedSecrets. See https://github.com/variantdev/vals#helm for more info on that.