Helm ABC:修订间差异
跳到导航
跳到搜索
(→range) |
(→range) |
||
第76行: | 第76行: | ||
toppings: |- | toppings: |- | ||
{{- range $index, $topping := .Values.pizzaToppings }} | {{- range $index, $topping := .Values.pizzaToppings }} | ||
{{ $index }}: {{ $topping }} | |||
{{- end }} | {{- end }} | ||
## 1 - output | ## 1 - output | ||
toppings: |- | toppings: |- | ||
0: mushrooms | |||
1: cheese | |||
2: peppers | |||
3: onions | |||
## 2 | ## 2 |
2024年7月22日 (一) 16:41的版本
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 方法遍历列表(list)、元组(tuple )、map、dict 等多值结构,若不指定变量,则 . 为当前的值。
## 1 toppings: |- {{- range $index, $topping := .Values.pizzaToppings }} {{ $index }}: {{ $topping }} {{- end }} ## 1 - output toppings: |- 0: mushrooms 1: cheese 2: peppers 3: onions ## 2 sizes: |- {{- range tuple "small" "medium" "large" }} - {{ . }} {{- end }} ## 2 - output sizes: |- - small - medium - large