Home > Software design >  Helm iterate over string with comma separated values
Helm iterate over string with comma separated values

Time:07-27

I'd like to iterate over string which contain comma separated values using range. For example:

DNS_NAMES: example.com, example2.com, example3.com

and then iterate using range over values: example.com, example2.com, example3.com

CodePudding user response:

use split


values.yaml

DNS_NAMES: example.com, example2.com, example3.com

templates/cm.yaml

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  config.yaml: |-
    args:
    {{- range ( split ", " $.Values.DNS_NAMES ) }}
      - {{ . }}
    {{- end }}

output.yaml

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  config.yaml: |-
    args:
      - example.com
      - example2.com
      - example3.com
  • Related