Helm has/merge option for overrides

55 Views Asked by At

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 }}

0

There are 0 best solutions below