How to indent content of included template

别来无恙 提交于 2019-12-02 00:54:36
tmirks

You should be able to pipe the output of your template to the indent function available in the sprig package:

{{ if (eq .Case "service")
  service:
    # need to indent! so contents become members of service:
{{ template "pod" | indent 4 }}
{{ end }}

I found I can work around the issue if I indent the contents of pod.tmpl and then indent the top portion to align as below

{{ if (eq $template "pod.tmpl") }}
    apiVersion: v1
    kind: Pod
{{ end }}
{{ if (eq $template "deployment.tmpl") }}
apiVersion: v1
kind: Deployment
metadata:
  name: {{ .Name }}-deployment
spec:
  replicas: {{ .Scale }}
  template:
{{template "pod" dict "Version" $version "Domain" $domain "Image" $image "ImageDerived" $imageDerived "Service" . }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!