Search code examples
kubernetes-helmgrafana

helm template escaped values for Grafana charts


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?


Solution

  • 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.