0

I am using Helm 3. I have two values.yaml files. In common/values.yaml I have defined:

deployment:
  ports:
    - name: http
      protocol: TCP

The common is of the type library. In my-app, which is of the type application, the common is added as a dependency. In my-app/values.yaml I have added:

deployment:
  ports:
    - containerPort: 8081

I have defined a template _deployment.yaml in common/templates. In this file I am trying to merge these two deployment dictionaries into one by using:

{{- $deployment := merge .Values.common.deployment .Values.deployment -}}

When I am printing {{ $deployment }}, it is giving output:

map[ports:[map[containerPort:8080 name:http protocol:TCP]]]

And if I do:

{{- $deployment := merge .Values.deployment .Values.common.deployment -}}

The output of {{ $deployment }} is:

map[ports:[map[containerPort:8081]]]

Moreover the output of {{ .Values.common.deployment }} is:

map[ports:[map[name:http protocol:TCP]]]

And the output of {{ .Values.deployment }} is:

map[ports:[map[containerPort:8081]]]

What I would like to have after merging is:

deployment:
  ports:
    - name: http
      protocol: TCP
      containerPort: 8081

Any advice you could give would be much appreciated.

Tapas Bose
  • 28,796
  • 74
  • 215
  • 331

1 Answers1

0

Looks like the merge operation does not work as expected on lists (it's a common problem, as the merge operation is ambiguous on list: should a list be appended or replaced when merging ?)

Anyway, I would suggest to merge the ports data with:

{{- $ports := merge .Values.deployment.ports[0] .Values.common.deployment.ports[0] -}}

and render the result with:

  deployment:
    ports:
      - {{- toJson $ports }}

HTH

dod
  • 294
  • 1
  • 5