<.Chart.Name>:无法评估字符串类型的字段Chart

时间:2019-01-14 11:38:35

标签: kubernetes-helm go-templates

当我部署以下内容时,会出现此错误:

RxPagedListBuilder

错误:

configurations.all { 
 resolutionStrategy{
    force 'com.android.support:support-v4:26.0.0'
    }

    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
       if (!requested.name.startsWith("multidex")) {
      details.useVersion '26.0.0'
     }
   }
  }
}

{{- if .Values.front.ingress.enabled -}} {{- $fullName := include "marketplace.fullname" . -}} {{- $ingressPaths := .Values.front.ingress.paths -}} apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ $fullName }}-{{ .Values.environment }}-front labels: app.kubernetes.io/name: {{ include "marketplace.name" . }}-{{ .Values.front.name }} helm.sh/chart: {{ include "marketplace.chart" . }} app.kubernetes.io/instance: {{ .Release.Name }}-{{ .Values.front.name }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- with .Values.front.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: {{- if .Values.front.ingress.tls }} tls: {{- range .Values.front.ingress.tls }} - hosts: {{- range .hosts }} - {{ . | quote }} {{- end }} secretName: {{ .secretName }} {{- end }} {{- end }} rules: {{- range .Values.front.ingress.hosts }} - host: {{ . | quote }} http: paths: {{- range $ingressPaths }} - path: / backend: serviceName: {{ include "marketplace.name" . }}-{{ $.Values.front.name }} servicePort: 3000 {{- end }} {{- end }} {{- end }} 在_helpers.tpl中定义:

  Error: UPGRADE FAILED: render error in "marketplace/templates/front-ingress.yaml": template: marketplace/templates/front-ingress.yaml:36:30: executing "marketplace/templates/front-ingress.yaml" at <include "marketplace...>: error calling include: template: marketplace/templates/_helpers.tpl:6:18: executing "marketplace.name" at <.Chart.Name>: can't evaluate field Chart in type string

marketplace.name是一个内部变量,here解释了优先顺序,但是即使设置{{- define "marketplace.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} {{- end -}} ,错误也是相同的。

奇怪的是,如果我删除此模板,.Chart.Name在任何其他模板中都可以正常工作,所以我认为问题与所使用的nameOverride的范围有关。

使用的值:

.Chart.Name

1 个答案:

答案 0 :(得分:1)

请参阅related issue

基于this workaround,您可以将.存储在变量中,因为在range循环内部,.指的是paths:的实际值

此外,您可能希望将- path: /替换为- path: {{ . }}

{{- if .Values.front.ingress.enabled -}}
{{- $fullName := include "bchart.fullname" . -}}
{{- $ingressPaths := .Values.front.ingress.paths -}}
{{- $dot := . }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
...
...
    {{- range $ingressPaths }}
          - path: {{ . }}
            backend:
              serviceName: {{ include "bchart.name" $dot }}-{{ $.Values.front.name }}
              servicePort: 3000
    {{- end }}