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

Add 'include' function identical to helm's #1345

Open
sirianni opened this issue Jul 10, 2020 · 13 comments
Open

Add 'include' function identical to helm's #1345

sirianni opened this issue Jul 10, 2020 · 13 comments

Comments

@sirianni
Copy link

It would be nice to have an include function like helm. The use case is to be able to render a template to a string and then further transform it in a pipeline.

Without this it is impossible to have a common YAML snippet defined in a template and then indent it contextually based on where it is used. For example:

{{ define "my-template" }}
some-yaml:
  foo:
{{ end }}

bar:
  {{- include "my-template" | nindent 2 }}

baz:
  qux:
    {{- include "my-template" | nindent 4 }}
@sirianni sirianni changed the title Implement 'include' function Add 'include' function identical to helm's Jul 10, 2020
@mumoshu
Copy link
Collaborator

mumoshu commented Aug 4, 2020

@sirianni Hey!

I thought the Helmfile way for that has been {{ readFile "path/to/gotmpl/file" }} and {{ tpl (readFile "path/to/gotmpl/file") .Values }}.

Just curious, but do you think we'd still need include?

@sirianni
Copy link
Author

sirianni commented Aug 5, 2020

You're right, the tpl function can just be used directly. I'm not sure why helm defines both tpl and include then.... 🤔

{{ define "my-template" }}
some-yaml:
  foo:
{{ end }}

bar:
  {{- tpl "my-template" . | nindent 2 }}

baz:
  qux:
    {{- tpl "my-template" . | nindent 4 }}

@FWest98
Copy link

FWest98 commented Aug 28, 2020

I think there is still a use for having an include function. The use of template is limited in YAML because it can't easily do proper indentation and other processing, but tpl requires all templates in separate files. This is somewhat inconvenient if you have small repetitive bits such as a random common toleration setting. Furthermore, tpl requires you to hardcode the file path everywhere, while this is not the case for template or include.

It also makes it easier for end-users to use the functions they are already familiar with in Helm, directly in Helmfile.

@mumoshu
Copy link
Collaborator

mumoshu commented Aug 29, 2020

@FWest98 Thanks. Yeah I believe this should be super useful if added. The only thing that makes me underprioritize this is that I thought it wasn't trivial to fully make it Helm-compatible. Especially, Helmfile has a bit different semantics in that it doesn't support automatically importing .tpl files.

So, do we also need to add some convention or configuration to allow automatically importing .tpl files so that defined snippets can be included without importing all the .tpl files?

Or can we just add define + include and defer the .tpl file loading to another feature request? In this case all you could do with it would be to just define and include within a same helmfile template file.

WDYT?

@FWest98
Copy link

FWest98 commented Aug 29, 2020

I believe Helm has the functionality to automatically include all files with an underscore (see here). I think a similar behaviour where helmfile would load all files with underscores in a given directory would be useful. For example, load all files with underscore in helmfile.d, or some other folder to be specified by the user.

@mumoshu
Copy link
Collaborator

mumoshu commented Aug 29, 2020

Sounds good!

Probably automatic loading of _*.tpl fiiles under the same directory as the target helmfile.yaml, like foo for helmfile -f foo/helmfile.yaml apply, would be enough for the first implementation.

@mumoshu
Copy link
Collaborator

mumoshu commented Aug 29, 2020

@FWest98 Would you mind submitting a PR for this?

@FWest98
Copy link

FWest98 commented Aug 30, 2020

That idea sounds good as well! Unfortunately, I don't have any experience with Go, so I don't think I would be the person to start implementing this.

@naphta
Copy link
Contributor

naphta commented Sep 28, 2021

@mumoshu Any desire to see this added still? Happy to take a look in the coming days and submit a PR.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 15, 2022

@naphta Hey. Yeah, I still think this is worth trying!

@armenr
Copy link

armenr commented Feb 16, 2023

This would be an incredibly valuable feature - it would help to reduce complexity greatly, and it would add significant utility to multiple different workflows I - and my colleagues - have designed around helmfile

I'd pay for this feature. :)

@yxxhero
Copy link
Contributor

yxxhero commented Feb 16, 2023

@armenr please post a feature request in helmfile/helmfile.

@yxxhero
Copy link
Contributor

yxxhero commented Nov 29, 2023

@mumoshu @armenr hi. I will post a PR in helmfile/helmfile. thanks so much.

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

No branches or pull requests

6 participants