头盔:如果台词工作不正确

问题描述 投票:0回答:1

这里是我的templates/deployment.yaml代码段:

volumes:
  - name: notebooks
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdf"
  {{- else }}
    emptyDir: {}
  {{- end -}}
  - name: logs
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdfdsf"
  {{- else }}
    emptyDir: {}
  {{- end -}}
  - name: conf
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdfsdfsdfsd"
  {{- else }}
    emptyDir: {}
  {{- end -}}

目前,我正在获取:

& helm template zeppelin ./
Error: YAML parse error on zeppelin/templates/deployment.yaml: error converting YAML to JSON: yaml: line 95: block sequence entries are not allowed in this context

正在得到我:

在此上下文中不允许使用块序列条目

我尝试清理一下代码:

  volumes:
    - name: notebooks
      persistentVolumeClaim:
        claimName: "sdfsdf"
    - name: logs
      persistentVolumeClaim:
        claimName: "sdfsdfdsf"
    - name: conf
      persistentVolumeClaim:
        claimName: "sdfsdfsdfsdfsd"

它被矫正地渲染。

if语句怎么了?

kubernetes-helm
1个回答
1
投票

如果在if / else语句中有一些额外的修饰,会破坏yaml结构。

工作示例:

volumes:
  - name: notebooks
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdf"
  {{- else }}
    emptyDir: {}
  {{- end }}
  - name: logs
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdfdsf"
  {{- else }}
    emptyDir: {}
  {{- end }}
  - name: conf
  {{- if .Values.persistence.enabled }}
    persistentVolumeClaim:
      claimName: "sdfsdfsdfsdfsd"
  {{- else }}
    emptyDir: {}
  {{- end }}

有关controlling whitespace here的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.