Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Helm take only the last value of the map in range

I am New at Helm , so sorry if I am not clear , of if I use the wrong terms.

I am trying to iterate over a list of IP , feed them in a range and create a array of ip for a headless service.

Here is my template:

kind: Endpoints
apiVersion: v1
metadata:
 name: backend-modbile-db-service
 namespace: {{ .Release.Namespace }}
subsets:
 - addresses:
     {{- range $key, $val := .Values.DatabaseEndpoints }}
      - {{ $key }}: {{ $val }}
     {{- end }}
   ports:
     - port: {{ .Values.DatabasePort| default 5984 }}
       name: backend-mobile-db-service

and the Value.yaml concerning theses IP look like this:

#backend-mobile-db-service

DatabasePort: 5984
DatabaseEndpoints:
  ip: 192.168.0.50
  ip: 192.168.0.51
  ip: 192.168.0.52
  ip: 192.168.0.55
  ip: 192.168.0.56
  ip: 192.168.0.57

I expected that the template would take the value and index and put them in the array of my service , but it only take the last key:value pair in the Value.yaml map:

# Source: backend-mobile/templates/backend-mobile-db-service.yaml
kind: Endpoints
apiVersion: v1
metadata:
 name: backend-modbile-db-service
 namespace: default
subsets:
 - addresses:
      - ip: 192.168.0.57
   ports:
     - port: 5984
       name: backend-modbile-db-service

Whereas , I expected an output like so:

# Source: backend-mobile/templates/backend-mobile-db-service.yaml
kind: Endpoints
apiVersion: v1
metadata:
 name: backend-modbile-db-service
 namespace: default
subsets:
 - addresses:
      - ip: 192.168.0.50
      - ip: 192.168.0.51
       [...]
      - ip: 192.168.0.52
   ports:
     - port: 5984
       name: backend-modbile-db-service

Where I the error I made ? Thanks in advance :)

like image 754
Popopame Avatar asked Sep 17 '25 14:09

Popopame


1 Answers

Because you are overwriting ip again and again, so you only see the last one. If you want to declare an array of ip, you should do:

DatabaseEndpoints:
  ip:
  - 192.168.0.50
  - 192.168.0.51
  - 192.168.0.52
  - 192.168.0.55
  - 192.168.0.56
  - 192.168.0.57

Therefore your template should be changed to like below:

subsets:
 - addresses:
     {{- range .Values.DatabaseEndpoints.ip }}
      - ip: {{ . }}
     {{- end }}
like image 61
Ken Chen Avatar answered Sep 19 '25 05:09

Ken Chen