Helm include templates

被刻印的时光 ゝ 提交于 2020-01-06 05:31:10

问题


Please! Is it possible to squash multiple helm templates into one and then refer to it as a one-liner in a deployment file?

EG:

 {{- define "foo.deploy" -}} 
 value:
   {{- include "foo.1" . | nindent 6 }}
   {{- include "foo.2" . | nindent 6 }}
   {{- include "foo.3" . | nindent 6 }}

And then do an {{- include "foo.deploy" . }} in a separate deployment file.

Which should then contain foo.1, foo.2 and foo.3, and their respective definitions.

As opposed to literally writing out all three different 'includes' especially if you've got loads.

Much appreciated,

Thanks,


回答1:


A named template (sometimes called a partial or a subtemplate) is simply a template defined inside of a file, and given a name. We’ll see two ways to create them, and a few different ways to use them. Template names are global. As a result of this, if two templates are declared with the same name the last occurrence will be the one that is used. Since templates in subcharts are compiled together with top-level templates, it is best to name your templates with chart specific names. A popular naming convention is to prefix each defined template with the name of the chart: {{ define "mychart.labels" }}.

More information about named templates you can find here: named-template.

Proper configuration file should look like:

{{/* Generate basic labels */}}
{{- define "mychart.labels" }}
  labels:
    generator: helm
    date: {{ now | htmlDate }}
{{- end }}

In your case part of file should looks like:

{{- define "foo.deploy" -}} 
{{- include "foo.1" . | nindent 6 }}
{{- include "foo.2" . | nindent 6 }}
{{- include "foo.3" . | nindent 6 }}
{{ end }}


来源:https://stackoverflow.com/questions/59424060/helm-include-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!