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陈述有什么问题?

4

1 回答 1

3

您的 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 }}

有关在此处控制空格的更多信息

于 2020-06-10T12:34:22.177 回答