[SOLVED] Need help fixing loop in template

Hi,
I’m a beginner in Go and am struggling with the different types. This is for a Helm template.
In my values.yaml file I have this structure for my variables:

receivers:
  opencensus:
    port: 55678
  zipkin:
    port: 9411
  jaeger:
    jaeger-thrift-tchannel-port: 14267
    jaeger-thrift-http-port: 14268
exporters:
  stackdriver:
    project: "vigilant-sol-256207"
    enable_tracing: true

My end result needs to be this:

data:
  oc-collector-config: |
    receivers:
      opencensus:
        port: 55678
      zipkin:
        port: 9411
      jaeger:
        jaeger-thrift-tchannel-port: 14267
        jaeger-thrift-http-port: 14268
    exporters:
      stackdriver:
        project: "vigilant-sol-256207"
        enable_tracing: true

This is about the closest I got:

  oc-collector-config: |
    receivers:
  {{- range $i, $receivers := .Values.receivers }}
  {{ $receivers | indent 6 }}
  {{ end }}
    exporters:
  {{- range $i, $exporters := .Values.exporters }}
  {{ $exporters | indent 6 }}
  {{ end }}

but it throws me the following error:
at <6>: wrong type for value; expected string; got map[string]interface {}
Can someone please explain me what I’m doing wrong here? I’ve been struggling with it for hours now.

Any help is greatly appreciated.

Kind regards,

Eric V.

OK, got one step closer…
Using the same input and this in my template:

  {{- range $k, $v := .Values.receivers }}
    {{ $k | indent 2 }}: {{ $v }}
  {{ end }}

The result is now:

receivers:
    jaeger: map[jaeger_thrift_http_port:14268 jaeger_thrift_tchannel_port:14267]
    opencensus: map[port:55678] 
    zipkin: map[port:9411]

But I’m struggling to get that last map handled.
Anybody that can help me out please?

Kind regards,

Eric V.

Got it!
This one finally works:

  {{- range $k, $v := .Values.receivers }}
    {{ $k | indent 2 }}:
      {{- range $k2, $v2 := $v }}
        {{ $k2 }}: {{ $v2 }}
    {{- end }}
  {{- end }}

Kind regards,

Eric V.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.