Skip to content

Add include-file flag for external files [#3276]#8227

Closed
vladfr wants to merge 169 commits intohelm:masterfrom
vladfr:3276-add-include-file
Closed

Add include-file flag for external files [#3276]#8227
vladfr wants to merge 169 commits intohelm:masterfrom
vladfr:3276-add-include-file

Conversation

@vladfr
Copy link

@vladfr vladfr commented May 29, 2020

This PR implements the --include-file and --include-dir flags for the install, upgrade and template commands.

These flags load local files and make them available to the chart, so they can be used in templates with functions like .Files.Get or .Files.Glob.

This is my first PR here, and I would appreciate comments regarding style, code split (what goes where), and the amount and quality of tests that we need.

Thank you!

Parsing

Both flags are arrays and can have multiple values, either comma-separated, or by writing the flag multiple times.

Both flags require a key and a path. They will get parsed just like --set*, and later values will overwrite previous ones. The paths are then added as if they are part of the chart; the keys represent the file names inside the chart.

You can use both flags in the same command. Files are parsed first, then directories.

Single files

helm template test . --include-file my_license.conf=../license.conf,foo=foo.txt --include-file bar=bar.txt --set license=my_license.conf

# in chart/templates/cmap.yml
{{ (.Files.Glob .Values.license).AsConfig | indent 2 }}

Dirs

The include-dir flag can include all the files from a local directory. It will not recurse in subdirectories.

helm template test . --include-dir certs=../certs

# in chart/templates/cmap.yml
{{ (.Files.Glob "certs/").AsConfig | indent 2 }}

Globs

The --include-dir flag optionally supports a glob. It can recurse, but it will take everything it finds and add it under one folder, specified in the key.

helm template test . --include-dir conf=../prod/conf/*.conf

# in chart/templates/cmap.yml
{{ (.Files.Glob "conf/").AsConfig | indent 2 }}

Closing

closes #3276

Feedback is welcomed! I know there has been a lot of interest for this issue, so I am looking forward for your input.
If you don't know where to start, here are the open issues with this PR:

  • currently, files are parsed first, then dirs; if a file overlaps somehow, the dir will overwrite it. What if we parse files last, so you can potentially overwrite an unwanted file in a dir? This one is easy to do
  • if a path is not found, is unreadable, or if a glob yields no files, the helm command currently fails. Should we continue the install with a warning?
  • all external files are added to the root of the chart. This means you can overwrite any chart file, including any template. Should we add these files to a special _external dir? Chart authors will need to append it to every lookup: {{ (.Files.Glob "_external/certs/") }}

Still todo:

  • implement --include-dir to get all files in a dir; this could be enhanced with glob
  • add tests
  • add docs

…nd makes it available to the templates

Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 29, 2020
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 29, 2020
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@vladfr vladfr force-pushed the 3276-add-include-file branch from 4b8131e to fa670b9 Compare June 3, 2020 09:00
vladfr added 2 commits June 5, 2020 14:59
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@vladfr vladfr force-pushed the 3276-add-include-file branch from 00e5787 to b3906f0 Compare June 5, 2020 12:05
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@vladfr vladfr marked this pull request as ready for review June 5, 2020 12:22
@vladfr
Copy link
Author

vladfr commented Jun 5, 2020

@bacongobbler - I'm ready for a review on this.

@bacongobbler
Copy link
Member

Hi @vladfr. Most of my time is spent working on another project, so I only have enough time to weigh in on issues and review smaller feature enhancements or security-related issues. I'd suggest reaching out on the Helm developer call on Thursdays to try and see if someone else can review this. Thanks!

@yann-soubeyrand
Copy link
Contributor

Thanks a lot for this PR!

Feedback is welcomed! I know there has been a lot of interest for this issue, so I am looking forward for your input.
If you don't know where to start, here are the open issues with this PR:

* currently, files are parsed first, then dirs; if a file overlaps somehow, the dir will overwrite it. What if we parse files last, so you can potentially overwrite an unwanted file in a dir? This one is easy to do

I think parsing files after dirs is a good idea. IMHO, one wouldn't expect an explicit file include to be overwritten by a less specific dir include.

* if a path is not found, is unreadable, or if a glob yields no files, the helm command currently fails. Should we continue the install with a warning?

Failing when a path is not found or is unreadable seems fine to me. But the warning maybe better in case of a glob returning nothing. It would introduce behavior inconsistency though. No strong opinion on this one, sorry!

* all external files are added to the root of the chart. This means you can overwrite **any** chart file, including any template. Should we add these files to a special `_external` dir?  Chart authors will need to append it to every lookup: `{{ (.Files.Glob "_external/certs/") }}`

What about forbidding some special paths like the templates and the charts directories, the Chart.yaml, Chart.lock, requirements.yaml and requirements.lock files and maybe the values.yaml file?

@hunsche
Copy link

hunsche commented Jun 8, 2020

First congratulations on PR ❤️ 🚀

I am testing this implementation and trying to make some changes to make it work in my scenarios.

Pass the instClient.ExternalFiles = client.ExternalFiles in the newUpgradeCmd method in cmd/helm/upgrade.go so that it works in a helm upgrade - installation.

It is also necessary to call the loadExternalFilesTemp method in cmd/helm/upgrade.go to run new versions; it is interesting to centralize this method somewhere accessible for install and upgrade.

I would like to help you with implementation suggestions.

vladfr added 2 commits June 10, 2020 14:05
Added a fix for upgrade --install
added more tests for loader, parser and upgrade cmd

Signed-off-by: Vlad Fratila <vfratila@adobe.com>
Signed-off-by: Vlad Fratila <vfratila@adobe.com>
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 10, 2020
@vladfr
Copy link
Author

vladfr commented Jun 10, 2020

@hunsche - thank you so much for your notes, you are correct on both points. I've added your suggestions and it seems to work nicely.

I've also increased test coverage. The only part I'm missing is the actual upgrade command with the new flags; I'll try to catch that in a test.

I mistakenly thought that upgrade would run runInstall but it does not. Right now I don't think it's worth refactoring this, as both install and upgrade commands are in the main package - I was able to simply call loadExternalFiles from upgrade. Maybe the function will look better in another go file though.

@vladfr
Copy link
Author

vladfr commented Jun 10, 2020

@yann-soubeyrand thanks for your replies, I'll go ahead and switch the ordering.

We still need to solve the problem of all external files being added to the root of the chart. Your suggestion of blocking paths is reasonable, but I'd like some more feedback on it, since it's not very forward-compatible.

@bacongobbler bacongobbler added this to the 3.4.0 milestone Jun 11, 2020
@bacongobbler
Copy link
Member

Slating for 3.4.0 for review as discussed on the call

@vincent-zurczak
Copy link

vincent-zurczak commented Jun 12, 2020

Hi,

We still need to solve the problem of all external files being added to the root of the chart.

Forbidding paths is a possibility, but I would rather opt for your other proposition and place all the external files in a sub-folder.

--include-file my_license.conf=../license.conf would thus make it available under _external: {{ (.Files.Glob "_external/my_license.conf") }}. There are several motivations:

  • As a Helm package developer, I want to give some flexibility to my package. Some files cannot just be templatized and need to be adapted to deployment contexts. Having these files along with the values.yaml, separated from the Helm repository, is a good approach. It fits for certificates (although there are other ways to manage this), but most of all for some very complex configuration files (we have an excellent example for a mail server).
  • On the other hand, I do not want users to be able to override everything: that would be a nightmare for support. In particular when those that use the package are not those who developed and maintain it. Allowing to override templates or static files is dangerous and could have unknown side effects. Packages must simplify usage and configuration by users, but also set boundaries to prevent errors from users. If there is a file to adapt or update, that will be done in another version of the package: either by making it a template, or by allowing the use of an external file, or even let the choice to the user through a parameter in the values.yaml file.

The initial issue is about adding files from outside the package, not about overriding what is in it. Just my 2 cents. :)

Anyway, thanks for working on this. We have just met the requirement on our project and we will be glad to use this feature as soon it is available. Soon, hopefully. 👍

@vladfr
Copy link
Author

vladfr commented Jun 15, 2020

Anyway, thanks for working on this. We have just met the requirement on our project and we will be glad to use this feature as soon it is available. Soon, hopefully. 👍

Thanks for your feedback @vincent-zurczak, there is more work on this, so the PR is slotted for the 3.4.0 release.

@mattfarina mattfarina self-requested a review September 25, 2020 16:35
@mattfarina
Copy link
Collaborator

@vladfr can you please rebase from the master branch. I'm getting a test error about something in pkg/release/mock.go that's been fixed there. There is also a difference in cmd/helm/install.go that needs to be handled.

The error conveys at least as much information as the boolean.

Signed-off-by: Simon Alling <alling.simon@gmail.com>
Matthew Fisher and others added 15 commits September 30, 2020 19:59
Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
Signed-off-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
A security issue fixed in 3.3.2 caught repos with the same name
being added a second time and produced an error. This caused an
issue for tools, such as helmfile, that will add the same name
with the same configuration multiple times.

This fix checks that the configuration on the existing and new
repo are the same. If there is no change it notes it and exists
with a 0 exit code. If there is a change the existing error is
returned (for reverse compat). If --force-update is given the
user opts in to changing the config for the name.

Closes helm#8771

Signed-off-by: Matt Farina <matt@mattfarina.com>
Add size of labels and number of reviewers is listed twice, pointing
the area with less detail to the one with more detail.

Signed-off-by: Matt Farina <matt@mattfarina.com>
This ensures warning messages are displayed on stderr rather than stdout.

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
Signed-off-by: lemonli <liwenjun0323@gmail.com>
When helm#8779 was merged it introduced an issue with windows builds,
which we do not test for in PR CI. This change fixes that problem.

Signed-off-by: Matt Farina <matt@mattfarina.com>
Closes helm#8806

Signed-off-by: Matt Farina <matt@mattfarina.com>
Remove klog flags from help text.  No change to behavior.

```
...
Flags:
      --debug                      enable verbose output
  -h, --help                       help for helm
      --kube-apiserver string      the address and the port for the Kubernetes API server
      --kube-context string        name of the kubeconfig context to use
      --kube-token string          bearer token used for authentication
      --kubeconfig string          path to the kubeconfig file
  -n, --namespace string           namespace scope for this request
      --registry-config string     path to the registry config file (default "/Users/areese/.config/helm/registry.json")
      --repository-cache string    path to the file containing cached repository indexes (default "/Users/areese/.cache/helm/repository")
      --repository-config string   path to the file containing repository names and URLs (default "/Users/areese/.config/helm/repositories.yaml")
```

Signed-off-by: Adam Reese <adam@reese.io>
Signed-off-by: zouyu <zouy.fnst@cn.fujitsu.com>
Bumps [github.com/lib/pq](https://github.com/lib/pq) from 1.7.0 to 1.8.0.
- [Release notes](https://github.com/lib/pq/releases)
- [Commits](lib/pq@v1.7.0...v1.8.0)

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [github.com/gofrs/flock](https://github.com/gofrs/flock) from 0.7.1 to 0.8.0.
- [Release notes](https://github.com/gofrs/flock/releases)
- [Commits](gofrs/flock@v0.7.1...v0.8.0)

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Mikuláš Dítě <dite@mangoweb.cz>
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.6.0 to 1.7.0.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](sirupsen/logrus@v1.6.0...v1.7.0)

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [github.com/DATA-DOG/go-sqlmock](https://github.com/DATA-DOG/go-sqlmock) from 1.4.1 to 1.5.0.
- [Release notes](https://github.com/DATA-DOG/go-sqlmock/releases)
- [Commits](DATA-DOG/go-sqlmock@v1.4.1...v1.5.0)

Signed-off-by: dependabot[bot] <support@github.com>
@helm-bot helm-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 30, 2020
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 30, 2020
@vladfr
Copy link
Author

vladfr commented Sep 30, 2020

@mattfarina - Unfortunately, I am not able to tend to this in the next few weeks to a month. I have made an attempt, but I messed it up. Sorry about that :(

If someone else can pick it up, I'm ok with that. If this still open when I return, I'll clean it up.

@hunsche
Copy link

hunsche commented Oct 1, 2020

I can do it is a feature that I am using.

@hunsche
Copy link

hunsche commented Oct 2, 2020

I opened the new PR in #8841

@mattfarina
Copy link
Collaborator

It appears this PR is overcome by #8841. So, I am going to close it. If this is not the case we can re-open.

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

Labels

size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow helm to add external files to chart deployment