Helm3模板错误调用包括:template: no template "microservice.labels" associated with template "gotpl"

Helm3 template error calling include: template: no template "microservice.labels" associated with template "gotpl"

我使用 helm create microservice 命令创建了 helm 3 模板。它有以下文件。

/Chart.yaml
./values.yaml
./.helmignore
./templates/ingress.yaml
./templates/deployment.yaml
./templates/service.yaml
./templates/serviceaccount.yaml
./templates/hpa.yaml
./templates/NOTES.txt
./templates/_helpers.tpl
./templates/tests/test-connection.yaml

根据我的应用程序更新了值文件,当我尝试安装 helm chat 时它给出了以下错误消息。

Error: UPGRADE FAILED: template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
helm.go:75: [debug] template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"

这是 ingress.yaml 文件。

{{- if .Values.ingress.enabled -}}
{{- $fullName := include "microservice.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
  {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
  {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
  {{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "microservice.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
  ingressClassName: {{ .Values.ingress.className }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
            pathType: {{ .pathType }}
            {{- end }}
            backend:
              {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $svcPort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
              {{- end }}
          {{- end }}
    {{- end }}
{{- end }}

如何添加 microservice.labels 模板?。我需要创建 microservice.labels.tlp 文件吗?

修复此错误的任何提示。

谢谢 SR

我将 ingress.yaml 文件复制到,chart 创建了旧版本的 helm。 _helpers.tpl 文件中缺少此值。现在我复制了新版本的 hellpers.tpl 文件。部署现在有效。