6

wise SOers. It turns out Grafana dashboard json files use the same {{ }} to do variable substitution as helm does. I have a grafana chart that is laden with these {{ }} to a disagreeable degree.

When I want to put that chart into a template, like so:

apiVersion: v1
kind: ConfigMap
metadata:
  name: super-dashboard
  namespace: monitoring
  labels:
    grafana_dashboard: "1"
data:
  super-dashboard.json: |-
{{ .Files.Get "super-dashboard.json"  | indent 4 }

It works great as long as the super-dashboard.json doesn't have any thing in it like:

"legendFormat": "{{status}} Status",.

Unfortunately, our dashboard does have such a woeful line. When I run helm, I get:

Error: UPGRADE FAILED: parse error at (templates/dashboards/super-dashboard.json:282): function "status" not defined

Naturally, it's looking for some method status which does not exist in the helm template language and fails thusly. If only I could ignore parsing of that pestering file. Oh, ye wise masters of the Internet, have you any sage advice for the humble seeker of your collective wisdom?

3
  • How are you installing the chart? The .Files.Get path you should shouldn't cause the included file to be reinterpreted by the templating engine; you would need to explicitly call tpl for that. Does helm template work on the chart, and if so, does the produced YAML look more or less correct around this block?
    – David Maze
    Commented Feb 14, 2021 at 0:21
  • I'm installing the chart with: helm upgrade --install mychart -f ./mychart/values.yaml ./mychart The json file is in the same directory as the template. (./mychart/template/)
    – vallard
    Commented Feb 15, 2021 at 21:29
  • there is some discussion here: github.com/helm/helm/issues/2798 I like the idea that ntfrnzn has but if I include any of these files in the relative directory I get the error. If I put them outside the directory they don't get picked up.
    – vallard
    Commented Feb 17, 2021 at 7:40

1 Answer 1

5

The issue was my super-dashboard.json file was in the same directories as the templates and helm tried to templatize it. The solution is to have a directory structure like:

mychart/
  templates/
    super-dashboard.yaml
  files/
    super-dashboard.json

Then the yaml file has:

{{ .Files.Get "files/super-dashboard.json" | indent 4 }}

I thought you had to put the files in the same directory but it just has to be at the root of the chart.

Not the answer you're looking for? Browse other questions tagged or ask your own question.