Nil pointer evaluating interface with custom values file

ngruson

I'm working on an umbrella chart which has several child charts. On the top level, I have a file values-ext.yaml which contains some values which are used in the child charts.

sql:
  common:
    host: <SQL Server host>
    user: <SQL user>
    pwd: <SQL password>

These settings are read in configmap.yaml of a child chart. In this case, a SQL Server connection string is built up from these settings.

apiVersion: v1
kind: ConfigMap
metadata:
  name: "childchart-config"
  labels:
    app: some-app
    chart: my-child-chart
data:
  ConnectionStrings__DbConnection: Server={{ .Values.sql.common.host }};Database=some-db

I test the chart from the umbrella chart dir like this: helm template --values values-ext.yaml . It gives me this error:

executing "my-project/charts/child-chart/templates/configmap.yaml" at <.Values.sql.common.host>: 
nil pointer evaluating interface {}.host

So, it clearly can't find the values that I want to read from the values-ext.yaml file. I should be able to pass in additional values files like this, right? I also tried with $.Values.sql.common.host but it doesn't seem to matter.

What's wrong here?

David Maze

When the child charts are rendered, their .Values are a subset of the parent chart values. Using $.Values to "escape" the current scope doesn't affect this at all. So within child-chart, .Values in effect refers to what .Values.child-chart would have referred to in the parent.

There's three main things you can do about this:

  1. Move the settings down one level in the YAML file; you'd have to repeat them for each child chart, but they could be used unmodified.

    child-chart:
      sql:
        common: { ... }
    
  2. Move the settings under a global: key. All of the charts that referenced this value would have to reference .Values.global.sql..., but it would be consistent across the parent and child charts.

    global:
      sql:
        common: { ... }
    
    ConnectionStrings__DbConnection: Server={{ .Values.global.sql.common.host }};...
    
  3. Create the ConfigMap in the parent chart and indirectly refer to it in the child charts. It can help to know that all of the charts will be installed as part of the same Helm release, and if you're using the standard {{ .Release.Name }}-{{ .Chart.Name }}-suffix naming pattern, the .Release.Name will be the same in all contexts.

    # in a child chart, that knows it's being included by the parent
    env:
      - name: DB_CONNECTION
        valueFrom:
          configMapKeyRef:
            name: '{{ .Release.Name }}-parent-dbconfig'
            key: ConnectionStrings__DbConnection
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Evaluating an expression with multiple boolean values

Helm chart fails with "nil pointer evaluating interface {}" when trying to evaluate a missing nested key

How do nil interface values work in Golang

Nil pointer dereference trying to copy pointer to pointer

How to serialize nil pointer of structure with custom MarshalBSONValue into BSON?

Compare interface to nil

How to cast nil interface to nil other interface

"pointer to interface, not interface"

pointer to interface is not an interface error?

Set pointer to struct passed in via interface{} to nil using reflect in Golang?

How to return custom errors without causing problems with nil values

nil pointer embedded error

golang (*interface{})(nil) is nil or not?

Nil pointer to struct not deep equal to nil?

omitempty doesn't omit interface nil values in JSON

Why does embedding an Interface in a struct cause the Interface methodset to be defined as nil pointer?

Convert nil interface to pointer of something in Golang?

assigning nil to pointer

Evaluating permission bit of a file

Check for nil and nil interface in Go

Cannot create a custom view using Xib file due to nil subviews

Unwanted behaviour with optional binding evaluating optional(nil)

How do I prevent getting nil interface elements while using custom cell in UITableViewController?

Setting Bootstrap's Custom File Input Cursor to Pointer

Swift 4 handling nil values from Firestore with CodableFirebase and custom classes

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

Trouble evaluating decimal values in java

Interface return runtime error: invalid memory address or nil pointer dereference

Handle pointer to nil pointer in Go