Skip to content

proposal: import file(s) during helm install #1754

Closed

Description

@syhol

More of a feature request as I haven't fleshed out all the details yet.

Right now the only way I can configure config maps and secrets from files is to copy entire file contents (and base 64 for secrets) into the values files or --set, its a bit awkward.

Lets say I have an RSA key, at the moment I base64 this, strip whitespace and put it into my values file:

rsaPrivateKey: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBdUcydDRBZ2dydXl3WjFKa2o4azBWZ1c3ak1vTlhoRVVMSG1mbEpWRFFJbmZTRVBtCnZaWGlYUHRaOVA0VGdwLzQzYmY1MXIvSGt6NVhnbjBlR2FkQlJlZUIxSUxyRXI3N2M5ZXMyenJCWmJUcWZ3UHoKNVNZNzdraXBZVURkczVEOVlsWnUyQk5sMFJzUGpUWWJQOCtvbnNXeVVyNXc2L0cxNEZTK0dnWTA2bGpyTVdPbwpjOVA5dWVqbXlZYitNMUgrMGR4SWl4Wkg5TndBcnJ1RVZJVHlxVGJnaE9tYUhPK1lGUWlySG5XNjk2U01EbmozCnVja21tRTlwS3kwQkk0eUlHdnRIdWJRYTh3U21TMkw0RTA3Y1pXdzkrMW5LdU00Z2E1bStVL3U1WTJSOGJzSm4KVjg5a2ZFVFlVUUF3YUxVVTZySE44UFBlUFZvc3dWWTNjd1kyRXdJREFRQUJBb0lCQUVCWnJLaVZ6V21ibG5XRwpyeVhvYTRWMFhKdGtTTVBBcTh4VTU1UjlmRWpCa3BIeGQwcEJTUWx1ZmxYWWJWQlBweE1keFdQajZLdjh2YVgvCktBaUZibVlJd0NrNVFQSjZodHhGcmIrVXdiUk9LdUFFcmc0UGlDdTlXTFJoWUxudDVpdHd3eDVMcm1RRzBDZFMKY0xHVU1GNnQxbW0rbjBJRVJaU3ZuT0VSdDFibzlVZUE4dlduRjJPU2ZpM2pIWi8zdWFuZmdwcVh1eFVtN202YgplU3cwTDYxVGpLRFU1THBKNDJFcjlJaGRpbG83eXdoREszbTN0ZHNlcS9FY3ltL1I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E1LaWp2MHRFCmRUa3hBb0dCQUlKcE9mTkJZYm9pQlJBL2ZORU1HakNzNUo4SzVlOWlVMG44a1N3NXJlSVNySG5WYy9HckhZSW8KWkxsdDVVdk01bDJ5TGFZRVBRUWpOeGErd05SeUVaemhuZlhGV05kSndRNFdYSVd5WUNmU0FFSGh0UTRnbUZ1RgphczNUZHNqNjU2VGp4dlg0MVU3T21OalVZc0FmYVlQTFN5bzAxM1FjR0JUelBYYlo3R0tUCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg=="

I know we have access to (.Files.Glob "foo/*").AsConfig and (.Files.Glob "bar/*").AsSecrets, but this is restricted to files inside the chart.

Perhaps we could use go template engine on the value file itself, like:

rsaPrivateKey: {{ (.Files.Glob "*.key.pem").AsSecrets }}

This would give helm more flexibility, but also more complexity. The functionality could more restricted than whats in chart template files, perhaps even with a different syntax/engine. I'm not sure how it would work with relative paths, that is something we would have to figure out.

I have a feeling this was what #1662 was trying to get across, but I'm not sure. Has anyone else felt like this is needed?

P.S I am so happy with helm, its a great tool and I think you guys are doing a great job.

Activity

  1. technosophos commented on Dec 23, 2016

    @technosophos
    Member

    Sorry, may answer is a little disjointed because you raised several interesting things. I'm not totally sure I understand what you're asking, but I'll do my best.

    First, the problem you raise is an interesting one that we want to solve better than we are today.

    Second, we will probably never support running the template engine over values.yaml because it generates substantial cognitive complexity. It also allows user to inject templates into a sealed chart, which can cause problems.

    Third, you gave me an interesting idea. The reason you cannot access files outside of the chart is because chart rendering is done on Tiller (mainly to ensure 100% reproducibility). And only files sent as part of the chart are available. Now, one thing you just brought up that I never thought about before is making it possible to pass files into a chart at install time. Maybe something like helm install --extra-files *.key.pem .... As long as those files weren't templates, it would not violate our stability guidelines, then they would be available to the chart on the server. Would that be useful?

  2. syhol commented on Dec 23, 2016

    @syhol
    Author

    Yes! This is just what I need. Thanks for making sense of my issue. I can get by without this but I think it could be useful it many places, like mysql /docker-entrypoint-initdb.d files and nginx vhosts.

  3. technosophos commented on Dec 23, 2016

    @technosophos
    Member

    I'm going to rename the issue and drop it into the feature triage queue for 2.3.

  4. changed the title [-]proposal: Better way use files in config maps and secrets[/-] [+]proposal: import file(s) during `helm install`[/+] on Dec 23, 2016
  5. added this to the milestone on Dec 23, 2016
  6. tallpauley commented on Jan 9, 2017

    @tallpauley
    Contributor

    Passing files through --extra-files sounds like a solution, but to me this seems like a sneaky backdoor way to get additional input into the release. I guess I see values.yml (and --set) as sort of the "interface" in which inputs are passed to helm. What I've been doing is just helm install --set "value=cat file | base64`. Why can't the command-line client do something similar?

    I think it would be nice to have a syntax like helm install --file-set value=config.json or something of the like. Then in the template you just b64dec the value if its a configmap, or leave it if its a secret.

    I guess I like passing files via Values, since it is a singular, documentable way to pass values into a chart. With --extra-files, where would you document this file that your chart needs as input? I'm not totally against the idea, I'm just trying to imagine how this would work.

    I think an advantage of the --extra-files approach though is that you could have a default file. For example you have a default my.cnf, which can be overridable by --extra-files my.cnf=myconf.cnf. Whereas with the other approach I suggested, the entire default file would have to be inside Values.cnf, which would suck.

    At the end of this self dialogue, I think --extra-files might be quite nice :) I suppose one could document these required or optional files in values.yml

  7. syhol commented on Jan 16, 2017

    @syhol
    Author

    After a little research...

    TLDR:- Massive strings in ConfigMap templates is a fairly common pattern(/problem)

    Looking at these suggests there are use cases for injecting files as value strings:

    Also looking at these suggests there are use cases for templating in non kubernetes files (out of scope for this proposal):

    So I think this is still a valid proposal.

    Moving forward...

    @tallpauley I love the --file-set idea but I agree it would be nice to have a default file. What if every file in ./mychart/values/* gets converted to a value, then ./mychart/values/my.cnf could then be accessed in templates using {{ .Values.mycnf }} .

    You now have 3 ways of overriding a value. In the following example we are setting mycnf to "foobar".
    Either use the new --file-set:

    echo 'foobar' > myconf.cnf
    helm install --file-set mycnf=myconf.cnf my-chart
    

    or use the old school --set

    helm install --set mycnf=foobar my-chart
    

    or add a new item in a custom values file:

    echo 'mycnf: "foobar"' > custom.yaml
    helm install --values custom.yaml my-chart
    

    This feels like a nice solution to me:

    Chart Default Values

    • ./values.yaml
    • ./values/*

    Setting Values on Install

    • helm install --set value=foobar my-chart
    • helm install --values custom.yaml my-chart
    • helm install --file-set value=custom.yaml my-chart

    @technosophos How do you feel about this?

  8. technosophos commented on Jan 26, 2017

    @technosophos
    Member

    @syhol I'm not sure I see the difference between the /values proposal and simply using {{ .Files.Get }}

    I do like the idea of a --file-set, since it prevents an unexpected injection, but still provides the ability to dump an entire file into a variable.

  9. syhol commented on Jan 27, 2017

    @syhol
    Author

    The benefit of /values is that the contents end up in .Values. Thats lets us nicely implement default files, while still allowing injection/overriding using existing or new methods (--set --values --file-set).

    It comes back to my original use case. I want a default key file in the chart, but for staging/prod deploys I want to specify a custom key file instead.

    Also the cases I linked to in my last comment look like they want to achieve something similar.

    {{ .Files.Get }} would still be a sensible option when you don't want to allow files to be overridden at install time.

  10. binoculars commented on Jul 21, 2017

    @binoculars
    Contributor

    I found a workaround with bash (v4 required):

    #!/usr/bin/env bash
    
    PREFIX='mykey.'
    LIST=''
    
    for file in /path/to/files/*; do
        contents=$(< ${file})
        LIST+=",${PREFIX}$(basename ${file//\./\\.})=${contents//,/\\,}"
    done
    
    helm install --dry-run --debug /path/to/chart/ --set "${LIST:1}" 

    E.g. if you have test1.txt, test2.txt in /path/to/files/, the user-supplied values will become:

    mykey:
      test1.txt: |-
        contents of test1
      test2.txt: |-
        contents of test2

    Happy Helming!

  11. chancez commented on Aug 1, 2017

    @chancez

    Hitting this pain point right now. We're forced to use either an umbrella chart, which hasn't worked well for our current use-case, and bundling our files into our chart is no good because the chart is supposed to be re-usable and not contain any secrets or per-environment configs.

  12. lukasheinrich commented on Aug 4, 2017

    @lukasheinrich

    Just adding a +1 for this. We're in the same situation as @chancez in that we want to provide reusable charts where people can add their secrets -- some of which are values that can be set via --set X.Y.Z=val but some of which are also files (Kerberos Keytabs, Certificates, etc). To me, the --file-set would work as it is close to what we're doing now (generating a values yaml file with file contents at specific keys)

  13. kevinschumacher commented on Aug 18, 2017

    @kevinschumacher

    Like @chancez, an umbrella chart doesn't work great for my use case either.

    Seems like there are two main items addressed by @syhol's proposal:

    1. ability to override a value with contents of a file at install/upgrade time (i.e., the proposed --file-set option)
    2. ability to set default Values in the chart, from files (the proposed ./values/* directory)

    I quite the like the proposal and find it pretty clean from a user's perspective (not sure about impl. complexities).

    Is there anything suggested here that's against helm's design philosophy? @technosophos any thoughts since you were the last to chime in?

  14. davidkarlsen commented on Nov 3, 2017

    @davidkarlsen
    Member

    Would love to see this feature!

    I’ve developed my generic helm chart for our apps (they basically all extend the same base dockerimage, and place in some config files via configmaps). But .Files read files within the chart - and need to be able to post in arbitrary files via cmd line with helm and get them added to the configmap.

  15. 19 remaining items

  16. saplla commented on Jun 8, 2018

    @saplla

    +1 so it's possible to bundle Makefiles into charts so our CD system can download the chart, unpack it and run make to install it, passing appropriate env vars via --set.

  17. added 5 commits that reference this issue on Jul 24, 2018
    daa0d07
    ed5d84a
    bdb4f18
    a1fb0f9
    1edb839
  18. added a commit that references this issue on Jul 25, 2018
    dc93908
  19. added 4 commits that reference this issue on Dec 6, 2018
    65f33d4
    3c2cc31
    5de955d
    8a1ac2d
  20. added a commit that references this issue on Feb 17, 2019
    969a5d6
  21. abdennour commented on Jul 17, 2019

    @abdennour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions