Helm: Using variables in values YAML file

10/30/2019

I'm wondering what is the best way to pass input into a values.yaml file using a template.

I have a parent chart (called myapp for this example) defined which has the following dependencies:

myapp/requirements.yaml

dependencies:
- name: internaldep
  condition: internaldep.enabled
  repository: file://../internaldep
  version: 0.1.0
- name: kafka
  condition: kafka.enabled
  repository: https://charts.bitnami.com
  version: 6.1.6

In my case, both the internaldep chart (which spins up an internal app used by my company) and the kafka chart (maintined by Bitnami here) have a dependency to Zookeeper.

Because of this, both charts in their own right spin up Zookeeper by having a dependency within their respective charts, as such:

kafka/requirements.yaml and internaldep/requirements.yaml

dependencies:
- name: zookeeper
  version: 5.1.X
  repository: https://charts.bitnami.com
  condition: zookeeper.enabled

In order avoid spinning up two Zookeeper installations, I opted to just spin up one Zookeeper, and use that one instance for both apps as such:

myapp/requirements.yaml

dependencies:
- name: internaldep
  condition: internaldep.enabled
  repository: file://../internaldep
  version: 0.1.0
- name: kafka
  condition: kafka.enabled
  repository: https://charts.bitnami.com
  version: 6.1.6
+ - name: zookeeper
+   version: 5.1.X
+   repository: https://charts.bitnami.com
+   condition: zookeeper.enabled

I've run into a problem. The kafka chart determines the Zookeeper servers to use based on the following code block:

- name: KAFKA_CFG_ZOOKEEPER_CONNECT
  {{- if .Values.zookeeper.enabled }}
  value: {{ template "kafka.zookeeper.fullname" . }}
  {{- else }}
  value: {{ .Values.externalZookeeper.servers | quote }}
  {{- end }}

Since I'm setting .Values.zookeeper.enabled to false (because I only want to use one Zookeeper installation for both apps), this means I must pass in the DNS names where Zookeeper can be found via .Values.externalZookeeper.servers.

However, when I try to do this in the values.yaml file:

kafka:
  externalZookeeper:
    servers: {{ .Release.Name }}-kafka-headless

I receive the error:

error converting YAML to JSON: yaml: line 82: did not find expected key

Is there a smarter way to do this?

-- Scott Crooks
kubernetes-helm

0 Answers