kuberneteskubernetes-helmmicrok8s

How to fix Helm "installation failed" complaning about a nil pointer evaluating interface on fullnameOverride


I am building a new Helm chart (mychart) that I'm trying to install.

A values.yaml exists and its contents specify the fullnameOverride:

fullnameOverride: "myapp"

I run the following command

helm install --dry-run -f "mychart-stack/values.yaml" mychart-stack1 ./mychart-stack

And it's giving me the error:

template: mychart-stack/templates/persistentvolume.local-storage.range.yml:5:14: executing "mychart-stack/templates/persistentvolume.local-storage.range.yml" at <include "mychart-stack.fullname" .>: error calling include: template: mychart-stack/templates/_helpers.tpl:14:14: executing "mychart-stack.fullname" at <.Values.fullnameOverride>: nil pointer evaluating interface {}.fullnameOverride

The mychart-stack/templates/_helpers.tpl:14:14 is the pregenerated one when you're asking Helm to produce a Chart example.

The error (14:14) is associated at the first line of the following auto generated code:

{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}

A little more context, as it's throwing an error while checking the persistentvolume.local-storage.range.yml, here are the contents of the file:

{{- range .Values.persistentVolume.localStorage }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-{{ include "mychart-stack.fullname" }}-{{ .name }}
spec:
  capacity:
    storage: 20Gi
  # le champ volumeMode requiert l'activation de la "feature gate" Alpha BlockVolume
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage-{{ include "mychart-stack.fullname" }}--{{ .name }}
  local:
    path: {{ .Values.persistentVolume.basePath }}/{{ .name }}
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - {{ .Values.hostName }}
{{- end }}

I don't know what's wrong, the code seems to indicate that it's not defined properly. I tried to run it in --debug mode but it doesn't help (same error).


Solution

  • Finally the problem wasn't the values.yaml that was not set correctly but more the way it was used within the template.

    When using an include of a definition coming from a .tpl file (this one was the autogenerated by Helm), we must be careful to not be in a range.

    I was creating a range of assets so it seems that it will run the code in the context of the range.

    Your conditional logic is being evaluated inside a range loop. This means . you're using to access Values is not the one you expect it to be, as it's overridden for each range iteration evaluation.

    ref: ingress.yaml template returns error in renderring --> nil pointer evaluating interface {}.service

    That means that we should use $ instead of . notation because it references the global scope.

    Example:

    {{- include "mychart-stack.fullname" $ }}