Helm ABC
跳到导航
跳到搜索
yaml 中的语法、函数。
控制结构
# values.yaml favorite: drink: coffee food: pizza pizzaToppings: - mushrooms - cheese - peppers - onions # Source: mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: {{ $.Release.Name }}-configmap data: myvalue: "Hello World" {{- with .Values.favorite }} drink: {{ .drink | default "tea" | quote }} food: {{ .food | upper | quote }} {{ if eq .drink "coffee" }}mug: "true"{{ end }} {{- end }} toppings: |- {{- range .Values.pizzaToppings }} - {{ . | title | quote }} {{- end }} # Output apiVersion: v1 kind: ConfigMap metadata: name: edgy-dragonfly-configmap data: myvalue: "Hello World" drink: "coffee" food: "PIZZA" mug: "true" toppings: |- - "Mushrooms" - "Cheese" - "Peppers" - "Onions"
if
{{- if PIPELINE }} # Do something {{- else if OTHER PIPELINE }} # Do something else {{- else }} # Default case {{- end }} # if 写成换行,就需要用 {{- 格式删除空格/回车 {{- if eq $.Values.favorite.drink "coffee" }} mug: "true" {{- end }} # 要确保 {{- 和其他命令之间有一个空格。{{- 3 }} 表示“删除左边空格并打印3”,而 {{-3 }} 表示“打印 -3 ”。
with
用来指定范围,PIPELINE 值不为空时执行
{{- with PIPELINE }} # restricted scope {{- end }} # 修改配置映射中的 . 的作用域指向 .Values.favorite # .drink --> .Values.favorite.drink # $.Release --> .Release
range
range 方法迭代 pizzaToppings 列表,. 设置为当前的值。|- 标识在 YAML 中是指多行字符串。
sizes: |- {{- range tuple "small" "medium" "large" }} - {{ . }} {{- end }} # output sizes: |- - small - medium - large