6

我正在尝试升级舵图,

我得到错误函数“pod”未定义这是有道理的,因为我真的没有这样的功能。

“pod”来自我将其转换为配置映射的 json 文件,并且 helm 将此值作为函数读取,而不是作为 json 文件的一部分的直接字符串。

这是我的配置图的片段:

# 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 }}

我得到的错误来自这一行:“legendFormat”:“{{pod}}”,

这是我得到的错误:

helm upgrade --dry-run prometheus-operator-chart /home/ubuntu/infra-devops/helm/vector-chart/prometheus-operator-chart/ 错误:升级失败:“prometheus-operator/templates/grafana/ 中的解析错误/仪表板/services-health.yaml”:模板:prometheus-operator/templates/grafana/dashboards/services-health.yaml:1213:未定义功能“pod”

我试图逃避它,但没有任何效果。有人知道我如何解决这个问题吗?

4

4 回答 4

13

使用backticks可以转义 gotpl 占位符。例如,在您的场景中,{{ pod }}您可以编写{{` {{ pod }} `}}.

于 2019-04-14T09:56:55.297 回答
3

将您的仪表板 json 移动到一个单独的文件中,假设将其命名为 dashboard.json。然后在您的 configmap 文件中:不要在内联列出 json,而是通过键入以下内容来引用dashboard.json 文件:

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

那将解决问题!

于 2021-01-21T12:11:39.237 回答
2

在我的实验中,我替换 "legendFormat": "{{ pod }}","legendFormat": "{{ "{{ pod }}" }}", 并且很高兴返回我需要的语法(特别是对于 grafana-operator GrafanaDashboard CRD)。

于 2021-05-01T23:51:50.803 回答
1

将 json 文件保留在 config map 之外并在 config map 中获取它是可行的,但请确保在使用 helm 时将 json 文件保留在模板目录之外,否则它将尝试搜索 {{ pod }} 。

于 2021-02-22T12:35:18.813 回答