<.Chart.name>: can't evaluate field name in type interface {}

1/20/2020

When you deploy the chart you get the following error: <.Chart.name>: can't evaluate field name in type interface {}

-- Tudor
charts
configmap
kubernetes
kubernetes-helm

2 Answers

1/20/2020

As per official helm documentation there are terms Predefined Values and Built-in Objects

The built-in values always begin with a capital letter. This is in keeping with Go’s naming convention. When you create your own names, you are free to use a convention that suits your team

List of those mandatory capitalized built-in values

  • Release: This object describes the release itself. It has several objects inside of it:
    • Release.Name: The release name
    • Release.Namespace: The namespace to be released into (if the manifest doesn’t override)
    • Release.IsUpgrade: This is set to true if the current operation is an upgrade or rollback.
    • Release.IsInstall: This is set to true if the current operation is an install.
    • Release.Revision: The revision number for this release. On install, this is 1, and it is incremented with each upgrade and rollback.
    • Release.Service: The service that is rendering the present template. On Helm, this is always Helm.
  • Values: Values passed into the template from the values.yaml file and from user-supplied files. By default, Values is empty.
  • Chart: The contents of the Chart.yaml file. Any data in Chart.yaml will be accessible here. For example {{ .Chart.Name }}-{{ .Chart.Version }} will print out the mychart-0.1.0.
  • Files: This provides access to all non-special files in a chart. While you cannot use it to access templates, you can use it to access other files in the chart. See the section Accessing Files for more.
    • Files.Get is a function for getting a file by name (.Files.Get config.ini)
    • Files.GetBytes is a function for getting the contents of a file as an array of bytes instead of as a string. This is useful for things like images.
    • Files.Glob is a function that returns a list of files whose names match the given shell glob pattern.
    • Files.Lines is a function that reads a file line-by-line. This is useful for iterating over each line in a file.
    • Files.AsSecrets is a function that returns the file bodies as Base 64 encoded strings.
    • Files.AsConfig is a function that returns file bodies as a YAML map.
  • Capabilities: This provides information about what capabilities the Kubernetes cluster supports.
    • Capabilities.APIVersions is a set of versions.
    • Capabilities.APIVersions.Has $version indicates whether a version (e.g., batch/v1) or resource (e.g., apps/v1/Deployment) is available on the cluster.
    • Capabilities.KubeVersion and Capabilities.KubeVersion.Version is the Kubernetes version.
    • Capabilities.KubeVersion.Major is the Kubernetes major version.
    • Capabilities.KubeVersion.Minor is the Kubernetes minor version.
  • Template: Contains information about the current template that is being executed
    • Name: A namespaced file path to the current template (e.g. mychart/templates/mytemplate.yaml)
    • BasePath: The namespaced path to the templates directory of the current chart (e.g. mychart/templates).

Small example:

apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
    targetPort: {{ .Values.service.internalPort }}
    protocol: TCP
    name: {{ .Values.service.name }}
selector:
    app: {{ template "fullname" . }}

And again - feel free to use any other manually defined values with lower-case. Hope it helps

-- VKR
Source: StackOverflow

1/20/2020

It's a beginner mistake, fields start with upper case even though Chart.yaml field starts with lower case. Same with Chart.Version and all the other fields.

Very weird for java developers.

-- Tudor
Source: StackOverflow