Helm template trying to pass a list of dictionaries to pluck

453 Views Asked by At

I think I am misunderstanding something about how pipelining and the like works in templating for helm/golang. Helm version:

version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}

Given values.yaml:

base_dict:
  one-thing:
    some-setting: potato
  two-thing:
    some-setting: spud

and configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: some-map
data:
  my_setting: {{ values .Values.base_dict | pluck "some-setting" | join "," }}
{{/*  my_setting2: {{ pluck "some-setting" (values .Values.base_dict) | join "," }}*/}}

my expectation would be that my_setting would be: potato,spud or spud,potato, but instead I get an error:

helm.go:81: [debug] template: /path/to/file:6:50: executing "/path/to/file" at <"some-setting">: wrong type for value; expected map[string]interface {}; got []interface {}

It seems like it is expecting multiple dictionaries instead of a list of dictionaries, but I am not sure how to expand this for pluck?

1

There are 1 best solutions below

0
Andrew Kettmann On

The end goal was to get some_setting (Changed the name from the original due to - vs _ in helm variable names) from the list of dictionaries, and to that goal, I made a helper in my _helpers.tpl:

{{/*Used to make yaml to feed to fromYaml so we can make a json list in helm */}}
{{- define "some-chart.yaml-translator" }}
stuff:
{{- range $key, $value := . }}
- {{ $value.some_setting }}
{{- end }}
{{- end }}

And then in my template:

{{- $agg_dict := include "some-chart.yaml-translator" .Values.base_dict | fromYaml }}
{{- $agg_json := get $agg_dict "lp_names" | toPrettyJson | quote }}

To be clear, this is some pretty garbage stuff, but was the best I could come up with. Happy to entertain other options of course!