You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Helm Library报错:include参数数量不符(期望2个实际1个)

问题:Helm Library模板合并报错调试求助

执行Helm图表lint时出现以下错误:

==> Linting .
[INFO] Chart.yaml: icon is recommended
[ERROR] templates/: template: myawesomewebapp/templates/deployment.yaml:4:4: executing "myawesomewebapp/templates/deployment.yaml" at <include "common.deployment" (list . "myawesomewebapp.deployment")>: error calling include: template: myawesomewebapp/charts/common/templates/_deployment.yaml:29:4: executing "common.deployment" at <include "common.util.merge" (append . "common.deployment.tpl")>: error calling include: template: myawesomewebapp/charts/common/templates/_util.tpl:20:22: executing "common.util.merge" at <include (index . 2) $top>: error calling include: template: myawesomewebapp/charts/common/templates/_deployment.yaml:18:10: executing "common.deployment.tpl" at <include>: wrong number of args for include: want 2 got 1

相关模板代码(注释用于排查语法错误):

{{- define "common.deployment.tpl" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  #name: {{ .Release.Name | printf "%s-%s" .Chart.Name }}
  labels:
    test: test
  #{{ include "common.labels" . | nindent 2 }}
spec:
  replicas: 1
  #replicas: {{ .Values.replicaCount | default 1 }}
  selector:
    matchLabels:
      test: test
  #selector:
    #matchLabels:
      #{{ include "common.selectorLabels" | nindent 8 }}
  template:
    metadata:
      labels:
        test: test
    spec:
      containers:
{{ include "common.container.tpl" . | indent 8 }}
{{- end -}}

{{- define "common.deployment" -}}
{{- include "common.util.merge" (append . "common.deployment.tpl") -}}
{{- end -}}

(注:原代码存在重复定义common.deployment.tpl的冗余内容,已清理)

merge模板代码:

{{- define "debug.var_dump" -}}
{{- . | mustToPrettyJson | printf "\nThe JSON output of the dumped var is: \n%s" | fail }}
{{- end -}}

{{- define "common.util.merge" -}}
{{- $top := first . }}
{{- $overrides := fromYaml (include (index . 1) $top) | default (dict ) -}}
{{- template "debug.var_dump" $overrides }}
{{- $tpl := fromYaml (include (index . 2) $top) | default (dict ) -}}
{{- toYaml (merge $overrides $tpl) }}
{{- end }}

调试建议

  • 定位参数缺失点:错误提示wrong number of args for include: want 2 got 1,是include调用时未传上下文参数。检查common.deployment.tpl中所有include,比如注释里的{{ include "common.selectorLabels" | nindent 8 }}缺少第二个参数.,即使是注释状态,也要确认是否有其他未注释的include漏传参数。
  • 补全merge函数参数:common.util.merge逻辑里用到了index . 1和index . 2,说明需要接收3个参数(上下文、覆盖模板名、基础模板名),但当前common.deployment中调用merge时只传了2个(上下文+common.deployment.tpl),需补充第三个参数(比如自定义的覆盖模板名)。
  • 单独测试模板渲染:用helm template --show-only <模板路径>命令单独渲染common.deployment.tpl或依赖模板,验证是否能生成合法YAML,排除单个模板的语法问题。
  • 清理冗余代码:原代码重复定义了common.deployment.tpl,会导致解析混乱,先删除重复部分,确保模板结构清晰。
  • 检查上下文传递:所有include调用必须明确传递上下文.,除非模板完全不需要上下文数据,比如include "template-name" .是标准写法,避免遗漏。

内容的提问来源于stack exchange,提问作者MDG55

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 12:35:31