helm3 - Helm3 中的 {{ ... }} 和 {{- ... -}} 语法有什么不同?
问题描述
我找不到任何文档,但我不断看到示例。
喜欢:
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{- include "example.serviceAccountName" . -}} ##<=== {{- -}}
example: {{ .Values.example.example }} ##<=== {{ }}
labels:
{{- include "alma.labels" . | nindent 4 }} ##<=== {{- }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
解决方案
Helm 使用标准的 Go 模板。看看https://pkg.go.dev/text/template#hdr-Text_and_spaces简而言之{{- something }}
,意思是“修剪左边的空白”,{{ something -}}
意思是“修剪右边的空白”。| nindent 4
意思是“前面加4个空格”。您需要此运算符来正确缩进您的 yaml。
推荐阅读
- google-bigquery - 如何避免 BigQuery 中的无效快照时间错误
- typescript - 如何查找 Vuejs 项目的所有未翻译字符串?
- java - 测试从通用抽象类扩展的类
- java - Apache Ignite 2.7.5 监控指标
- node.js - NodeJS 异步函数 get(/*db 查询在这里发生*/).then(/* 需要在这里使用 db 响应 */) 不等待并返回未定义
- javascript - TouchBarButton 不是构造函数
- java - XPath 查询很慢
- pyopenssl - PyOpenSSL 在 do_handshake() 上设置超时
- excel - 循环遍历三个工作表并删除每个工作表中的表数据
- powershell - 使用 Powershell 计算和过滤文本文件