My question is similar to this question Helm Charts with multiple lists in multiple values files however, the change is that the value structure is different and I need a way to merge those
the chart has the following
env:
{{- toYaml .Values.env | nindent 12 }}
the default values.yaml file has the following
env:
- name: Test
value: "Value"
The custom.yaml file has the values defined as
env:
- name: Test2
value: "Value2"
Based on this post Helm Charts with multiple lists in multiple values files, I am able to merge these two into a single by modifying the chart to
env:
{{- range $key, $value := .Values.abc.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
However, this doesn't work if the default value file has a key/value that has a different format.
My requirement is that I need to insert the worker node IP into all the pod as an environment name HOST_IP. Any additional env variables in the custom.yaml must be added to this.
env:
- name: HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
So, the final yaml must have
env:
- name: HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: Test2
value: "Value2"
The issue here is that when these are merged, it provides an incorrect syntax.
How can I have these two formats merged into a single so that I can add them to the template? Is there a way to merge these in helm?