掌舵升级失败,“功能“X”未定义”

Sha*_*uan 2 kubernetes kubernetes-helm configmap

我正在尝试升级舵图,

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

“pod”来自一个 json 文件,我将其转换为 configmap 并且 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 }}
Run Code Online (Sandbox Code Playgroud)

我得到的错误来自这一行:“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”未定义

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

yan*_*ver 8

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

  • 那么传递``--set pod=pod`` 的道理是什么? (2认同)