helm configmap in values.yaml

Viewed 5848

I am trying to do the following, so where MYVALUE in host needs to change to include Release Name. Can't figure how to do this, as you can't use env variables like {{ .Release.Name }} directly in to a values.yaml file.

I did do a fullnameOverride and put fullnameOverride: myrelease-mysql for the mysql pod and then jasper has host: myrelease-mysql that works but wanted to know if there was a clever way to put release name into a values.yaml file.

I assumed I would need to use a configMap as can use .Release.Name there and then embed that config key into values.yaml.

Values.yaml

jasperreports:
  mariadb:
    enabled: false
  externalDatabase:
    host: MYVALUE   // Also tried $MVALUE
    user: sqluser
    database: jasper
  jasperreportsUsername: jasper
  env:
      - name: MYVALUE
        valueFrom:
          configMapKeyRef:
              name: mysql-jasper
              key: mysql_releasename

ConfigMap

kind: ConfigMap
metadata:
  name: mysql-jasper
data:
  mysql_releasename: {{ .Release.Name }}-"mysql"
1 Answers

It seems that helm does not support any template rendering capabilities in a values.yaml file - there are multiple topics on the helm GitHub:

For now this feature is not implemented so you need to find a workaround - the suggestion from David Maze seems to be a good direction, but if you want to follow your approach you can use below workaround using --set flag in the helm install command or use sed command and pipe to helm install command.

First solution with --set flag.

My values.yaml file is little bit different than yours:

mariadb:
  enabled: false
externalDatabase:
  user: sqluser
  database: jasper
jasperreportsUsername: jasper

That's because when I was using your values.yaml I couldn't manage to apply these values to bitnami/jasperreports chart, the helm install command was using default values from here.

I'm setting a shell variable RELEASE_NAME which I will use both for setting chart name and externalDatabase.host value.

RELEASE_NAME=my-test-release
helm install $RELEASE_NAME bitnami/jasperreports -f values.yaml --set externalDatabase.host=$RELEASE_NAME-mysql

The above helm install command will override default values both by setting values from the values.yaml file + setting externalDatabase.host value.

Before applying you can check if this solution works as expected by using helm template command:

RELEASE_NAME=my-test-release
helm template $RELEASE_NAME bitnami/jasperreports -f values.yaml --set externalDatabase.host=$RELEASE_NAME-mysql
...
- name: MARIADB_HOST
  value: "my-test-release-mariadb"
...

Another approach is to set a bash variable RELEASE_NAME which will be used in the sed command to output modified values.yaml file (I'm not editing values.yaml file itself). This output will be pipe into a helm install command (where I also used theRELEASE_NAME variable).

values.yaml:

mariadb:
  enabled: false
externalDatabase:
  host: MYHOST
  user: sqluser
  database: jasper
jasperreportsUsername: jasper
RELEASE_NAME=my-test-release
sed "s/MYHOST/$RELEASE_NAME-mysql/g" values.yaml | helm install $RELEASE_NAME bitnami/jasperreports -f -

This approach will set chart configuration the same as in the first approach.

Related