1

I am trying to create a template whereby values have a default set of service names, unless they are overriden. example:

default:
  service:
    - name: nginx1
      service: "dev-nginx1"
      port: 8080
    - name: nginx2
      service: "dev-nginx2"
      port: 8080

  identifiers:
    - identifier: "cust1"  
    - identifier: "cust2"  
    - identifier: "cust3"  


overrides:
  identifiers: 
    - identifier: "cust2"
      service:
        - name: nginx4
          service: "cust2-nginx4"
          port: 8080
        - name: nginx12
          service: "cust2-nginx12"
          port: 8080

Where the above would yield:


---
identifier: cust1
service: dev-nginx
port: 8080
service: dev-nginx2
port: 8080
---
identifier: cust2
service: cust2-nginx4
port: 8080
service: cust2-nginx12
port: 8080
---
identifier: cust3
service: dev-nginx
port: 8080
service: dev-nginx2
port: 8080

I have tried the following, but i'm getting in a mess with the iterations in the incorrect place. Is there an easier way to accomplish this in helm with some sort of merge function?


{{- range $key, $values := $.Values.default.identifiers -}}
{{- range $overrideKey, $overrideValues := $.Values.overrides.identifiers -}}
{{ if eq $values.identifier $overrideValues.identifier }}
---
identifier: {{ $values.identifier }}
{{- range $value := $overrideValues.service }}
service: {{ $value.name }}
port: {{ $value.port }}
{{- end }}

{{ else }} 

---
identifier: {{ $values.identifier }}
{{- range $value := $overrideValues.service }}
service: {{ $value.name }}
port: {{ $value.port }}
{{- end }}


{{- end }}
{{- end }}
{{- end }}

Rygo
  • 159
  • 1
  • 8
  • 1
    Can you install the chart multiple times, one for each `custN` value? Then that name could appear inside the chart as `.Release.Name`, and a typical convention is to start most Kubernetes object names with that name. – David Maze Dec 04 '22 at 12:02
  • hi @DavidMaze yes, actually the above example was just to get my logic straight - but you are correct about the naming, in which i already do this. – Rygo Dec 04 '22 at 14:26

0 Answers0