如何在头盔图表中从values.yaml到_helpers.tpl获取值

如何在头盔图表中从values.yaml到_helpers.tpl获取值,yaml,kubernetes-helm,Yaml,Kubernetes Helm,这是values.yaml文件。它包含以下内容,当我尝试将其放入_helper.tpl时,我获取Helm模板失败。错误:在“windows/templates/ingresses/windows.yaml”中呈现错误:template:windows/templates/_helpers.tpl:38:18:在执行“windows.certificate”时:无法评估类型接口中的字段入口{}:退出状态1 值。yaml ingress: enabled: true tls: tru

这是values.yaml文件。它包含以下内容,当我尝试将其放入_helper.tpl时,我获取
Helm模板失败。错误:在“windows/templates/ingresses/windows.yaml”中呈现错误:template:windows/templates/_helpers.tpl:38:18:在执行“windows.certificate”时:无法评估类型接口中的字段入口{}:退出状态1

值。yaml

ingress:
    enabled: true
    tls: true
    certificate: ''
    issuer:
        name: letsencrypt-staging
    hosts:
        windows:
            - name: ''
            path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- printf .Values.ingress.enabled }}  // error line is this. line no 38
 {{- end }}
    - secretName: {{ template "windows.certificate" . }} // calling the helper method.
ingress:
  enabled: true
  tls: true
  certificate: ''
  issuer:
    name: letsencrypt-staging
  hosts:
    windows:
      - name: ''
        path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- if .Values.ingress.enabled }}
 {{- printf .Values.ingress.certificate }} 
 {{- end }}     
 {{- end }}
\u helpers.tpl

ingress:
    enabled: true
    tls: true
    certificate: ''
    issuer:
        name: letsencrypt-staging
    hosts:
        windows:
            - name: ''
            path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- printf .Values.ingress.enabled }}  // error line is this. line no 38
 {{- end }}
    - secretName: {{ template "windows.certificate" . }} // calling the helper method.
ingress:
  enabled: true
  tls: true
  certificate: ''
  issuer:
    name: letsencrypt-staging
  hosts:
    windows:
      - name: ''
        path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- if .Values.ingress.enabled }}
 {{- printf .Values.ingress.certificate }} 
 {{- end }}     
 {{- end }}
在windows.yaml中

ingress:
    enabled: true
    tls: true
    certificate: ''
    issuer:
        name: letsencrypt-staging
    hosts:
        windows:
            - name: ''
            path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- printf .Values.ingress.enabled }}  // error line is this. line no 38
 {{- end }}
    - secretName: {{ template "windows.certificate" . }} // calling the helper method.
ingress:
  enabled: true
  tls: true
  certificate: ''
  issuer:
    name: letsencrypt-staging
  hosts:
    windows:
      - name: ''
        path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- if .Values.ingress.enabled }}
 {{- printf .Values.ingress.certificate }} 
 {{- end }}     
 {{- end }}

问题是缩进,试试这个

值。yaml

ingress:
    enabled: true
    tls: true
    certificate: ''
    issuer:
        name: letsencrypt-staging
    hosts:
        windows:
            - name: ''
            path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- printf .Values.ingress.enabled }}  // error line is this. line no 38
 {{- end }}
    - secretName: {{ template "windows.certificate" . }} // calling the helper method.
ingress:
  enabled: true
  tls: true
  certificate: ''
  issuer:
    name: letsencrypt-staging
  hosts:
    windows:
      - name: ''
        path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- if .Values.ingress.enabled }}
 {{- printf .Values.ingress.certificate }} 
 {{- end }}     
 {{- end }}
还对辅助程序进行了一些更改,以控制定义块的输出

\u helpers.tpl

ingress:
    enabled: true
    tls: true
    certificate: ''
    issuer:
        name: letsencrypt-staging
    hosts:
        windows:
            - name: ''
            path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- printf .Values.ingress.enabled }}  // error line is this. line no 38
 {{- end }}
    - secretName: {{ template "windows.certificate" . }} // calling the helper method.
ingress:
  enabled: true
  tls: true
  certificate: ''
  issuer:
    name: letsencrypt-staging
  hosts:
    windows:
      - name: ''
        path: /
 {{/*
 Calculate certificate
 */}}
 {{- define "windows.certificate" }}
 {{- if .Values.ingress.enabled }}
 {{- printf .Values.ingress.certificate }} 
 {{- end }}     
 {{- end }}

调用帮助程序时,上下文可能不是定义所期望的根

例如,如果在这样的模板中使用它:

{{- range .Values.deployments }}
  {{ $certificate := include "windows.certificate" . }}
{{- end }}
调用帮助程序时的上下文为.Values.deployments。因此,.Values.ingres.certificate将指向.Values.deployments.Values.ingres.certificate,当然,它并不存在


在的变量部分的开头,您有一个示例,说明
块如何影响
的含义。阅读它可能会帮助您了解如何知道您传递给帮助者模板的内容。

对于那些有相同问题的人。

在我的例子中,我不得不将我的文件从Values.yaml重命名为Values.yaml(注意小写文件名)。

是的!!我检查过了,但错误仍然是一样的。我已经编辑了我的代码ToCheck now,我已经编辑了答案以在助手上添加一些更改我应该在哪里添加此代码?在_helpers.tpl中或我调用此helper方法的位置。我修改了我的问题并添加了如何调用helper方法。{{template“windows.certificate”。}}在调用帮助器方法之前,我们需要查看代码。您需要检查是否有任何
{{range…}}
{{with…}}
可能更改了上下文