Using variables in templates so set the scope using - with

9 views
Skip to first unread message

Adam Daughterson

unread,
Oct 3, 2019, 2:35:18 PM10/3/19
to Helm Developers
Hello group,

I'm posed with an interesting problem that I've been bumping up against for a few hours now setting the scope using a  {{- with }} statement.

Given the following values.yaml snippet:

configmap:
  dev
:
    resources
:
      limits
:
        cpu
: 10m
        memory
: 16Mi
      requests
:
        cpu
: 5m
        memory
: 8Mi
  alpha
:
    resources
:
      limits
:
        cpu
: 30m
        memory
: 32Mi
      requests
:
        cpu
: 5m
        memory
: 16Mi


I'm trying to use something like the following to populate the resources block as so:

{{- $env := printf "%s" .Values.configmap.environment }}

# snip...
          resources
:
           
{{- with .Values.configmap }}.{{$env}}
             
{{- toYaml . | nindent 12 }}
           
{{- end}}
# snip...


...which renders to this:

       
          resources:.dev
            alpha
:
              resources
:
                limits
:
                  cpu
: 200m
                  memory
: 256Mi
                requests
:
                  cpu
: 20m
                  memory
: 32Mi
            dev
:
              resources
:
                limits
:
                  cpu
: 100m
                  memory
: 128Mi
                requests
:
                  cpu
: 10m
                  memory
: 16Mi


The desired rendered yaml should actually be (when --set configmap.environment=dev is passed to helm):

          resources:
                limits
:
                  cpu
: 100m
                  memory
: 128Mi
                requests
:
                  cpu
: 10m
                  memory
: 16Mi

Can someone offer any guidance on getting this kind of thing working?

Yours gratefully,

Adam D


Adam Daughterson

unread,
Oct 3, 2019, 2:39:38 PM10/3/19
to Helm Developers
EDIT: the template snippet is actually this:

          {{- with .Values.configmap }}.{{$env}}

          resources
:
           
{{- toYaml .resources | nindent 12 }}
         
{{- end}}



Thanks
Reply all
Reply to author
Forward
0 new messages