使用 include 语句作为默认值

Blo*_*je5 3 kubernetes-helm

我正在创建一个舵图,我想在其中使用模板函数指定值的默认值。具体来说,我想使用覆盖值 image.name,或默认为模板函数 Chart.name:

{{ .Values.image.name | default include chart.name . }}
Run Code Online (Sandbox Code Playgroud)

但是在对图表进行 linting 时出现以下错误:

[ERROR] templates/: render error in "chart/templates/deployment.yaml": template: chart/templates/deployment.yaml:22:81: executing "chart/templates/deployment.yaml" at <include>: wrong number of args for include: want 2 got 0
Run Code Online (Sandbox Code Playgroud)

是否可以使用包含的模板函数作为默认值?或者我只能使用文字吗?

edb*_*ead 5

你可以。只需将您的 include 语句括在括号中即可:

{{ .Values.image.name | default (include "chart.name" .)}}

请参阅使用默认功能