Iteration on range elements of helm chart minus latest

4/19/2020

I would like to iterate the following array of objects put in my values.yaml file

elements:
 -elem1: value
  elem2: value
  elem3: value
 -elem1: value
  elem2: value
  elem3: value

the triplet in each - are values related to each other. I have seen I can use range in something like:

env:
 - name: ELEMENTS
   value: "{{- range .Values.elements}}{{.elem1}}.{{.elem2}}.{{ .elem3}}             {{- end }}"

but this is then translated in something like :

env:
- name: ELEMENTS
   value: "value.value.value value.value.value"

Is there any way to iterate these elements minus the latest one?
I would like to map the content I am reading as json, but I have to iterate minus the latest element to put then the element in my json output.

The final output should be something like:

ELEMENTS="{[ "elem1":value, "elem2": value, "elem3": value],["elem1":value, "elem2": value, "elem3": value]}"
-- Claudio Ferraioli
arrays
charts
kubernetes
kubernetes-helm

0 Answers