helm模版案例运维记录(一)

韵味老鸟 2024-07-06 17:19:18

helm模版案例运维记录(一)

一:if eq 判断

{{- if eq .Values.controller.type "statefulset" -}}.Values.controller.type 表示模板上下文中的.Values.controller.type 的值如果.Values.controller.type 的值与statefulset相等,那么条件判断为真,将执行{{- if eq .Values.controller.type "statefulset" -}}后续的模板代码

二:if 和 with的区别

{{- with .Values.controller.volumeMounts }} 和 {{- if .Values.controller.volumeMounts }} 有什么区别

{{- with .Values.controller.volumeMounts }} {{ .Field1 }} {{ .Field2 }}{{- end }}```如果`.Values.controller.volumeMounts`不为nil,则会执行`{{ .Field1 }}`和`{{ .Field2 }}`的模板代码。{{- if .Values.controller.volumeMounts }} Some code here...{{- end }}```如果`.Values.controller.volumeMounts`不为nil且不为空,则执行"Some code here..."的模板代码。

需要注意的是,上述示例中的{{-是模板语法中的修饰符,用于去除生成的空白字符,以实现更好的控制模板输出格式。

综上所述,{{- with .Values.controller.volumeMounts }}用于创建局部上下文环境,并在其中执行模板代码,而{{- if .Values.controller.volumeMounts }}用于根据条件判断是否执行模板代码。

0 阅读:0