Shahar Hamuzim Rajuan
Shahar Hamuzim Rajuan

Reputation: 6159

helm upgrade fails with "function "X" not defined"

I'm trying to upgrade a helm chart,

I get the error function "pod" not defined which make sense because I really have no such function.

The "pod" is coming from a json file which I convert into a configmap and helm is reading this value as a function and not as a straight string which is part of the json file.

This is a snippet of my configmap:

# Generated from 'pods' from https://raw.githubusercontent.com/coreos/prometheus-operator/master/contrib/kube-prometheus/manifests/grafana-dashboardDefinitions.yaml
# Do not change in-place! In order to change this file first read following link:
# https://github.com/helm/charts/tree/master/stable/prometheus-operator/hack
{{- if and .Values.grafana.enabled .Values.grafana.defaultDashboardsEnabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-%s" (include "prometheus-operator.fullname" $) "services-health" | trunc 63 | trimSuffix "-" }}
  labels:
    {{- if $.Values.grafana.sidecar.dashboards.label }}
    {{ $.Values.grafana.sidecar.dashboards.label }}: "1"
    {{- end }}
    app: {{ template "prometheus-operator.name" $ }}-grafana
{{ include "prometheus-operator.labels" $ | indent 4 }}
data:
  services-health.json: |-
    {
      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": "-- Grafana --",
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "type": "dashboard"
          }
        ]
      },
      "targets": [
        {
          "expr": "{__name__=~\"kube_pod_container_status_ready\", container=\"aggregation\",kubernetes_namespace=\"default\",chart=\"\"}",
          "format": "time_series",
          "instant": false,
          "intervalFactor": 2,
          "legendFormat": "{{pod}}",
          "refId": "A"
        }
}
{{- end }}

The error I get is coming from this line: "legendFormat": "{{pod}}",

And this is the error I get:

helm upgrade --dry-run prometheus-operator-chart /home/ubuntu/infra-devops/helm/vector-chart/prometheus-operator-chart/ Error: UPGRADE FAILED: parse error in "prometheus-operator/templates/grafana/dashboards/services-health.yaml": template: prometheus-operator/templates/grafana/dashboards/services-health.yaml:1213: function "pod" not defined

I tried to escape it but nothing worked. Anyone get idea about how I can work around this issue?

Upvotes: 8

Views: 11763

Answers (4)

Jim Peterson
Jim Peterson

Reputation: 61

In the case of my experiments, I replaced "legendFormat": "{{ pod }}", with "legendFormat": "{{ "{{ pod }}" }}", and it was very happy to return the syntax I needed (Specifically for the grafana-operator GrafanaDashboard CRD).

Upvotes: 2

naveen bp
naveen bp

Reputation: 11

Keeping json file out of config map and sourcing it within config map works, but make sure to keep the json file out of template directory while using with helm, or else it will try to search for {{ pod }} .

Upvotes: 1

Karabilo
Karabilo

Reputation: 93

Move your dashboard json to a separate file, let's say name it dashboard.json. Then in your configmap file: instead of listing the json down inline, reference the dashboard.json file by typing the following:

data:
  services-health.json: |-
{{ .Files.Get "dashboard.json" | indent 4 }}

That would solve the problem!

Upvotes: 5

Yaniv Oliver
Yaniv Oliver

Reputation: 3971

Escaping gotpl placeholders is possible using backticks. For example, in your scenario, instead of using {{ pod }} you could write {{` {{ pod }} `}}.

Upvotes: 16

Related Questions