Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 515
Shahar Hamuzim Rajuan Avatar asked Apr 14 '19 08:04

Shahar Hamuzim Rajuan


2 Answers

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

like image 144
yanivoliver Avatar answered Oct 13 '22 09:10

yanivoliver


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!

like image 41
Karabilo Avatar answered Oct 13 '22 11:10

Karabilo