helmfile
                                
                                
                                
                                    helmfile copied to clipboard
                            
                            
                            
                        Add 'include' function identical to helm's
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 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?
You're right, the tpl function can just be used directly.  I'm not sure why helm defines both tpl and include then.... :thinking:
{{ define "my-template" }}
some-yaml:
  foo:
{{ end }}
bar:
  {{- tpl "my-template" . | nindent 2 }}
baz:
  qux:
    {{- tpl "my-template" . | nindent 4 }}
                                    
                                    
                                    
                                
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.
@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?
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.
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.
@FWest98 Would you mind submitting a PR for this?
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.
@mumoshu Any desire to see this added still? Happy to take a look in the coming days and submit a PR.
@naphta Hey. Yeah, I still think this is worth trying!
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. :)
@armenr please post a feature request in helmfile/helmfile.
@mumoshu @armenr hi. I will post a PR in helmfile/helmfile. thanks so much.