我在升级头盔图,
我得到错误函数"pod“没有定义,这是有意义的,因为我真的没有这样的功能。
"pod“来自json文件,我将其转换为configmap,helm将此值作为函数而不是直接字符串读取,后者是json文件的一部分。
这是我的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 }}我得到的错误来自于这一行:"legendFormat":"{{pod}}",
这就是我遇到的错误:
/home/ubuntu/infra-devops/helm/vector-chart/prometheus-operator-chart/错误:升级失败:"prometheus-operator/templates/grafana/dashboards/services-health.yaml":模板中的解析错误:未定义prometheus-operator/templates/grafana/dashboards/services-health.yaml:1213:函数"pod“
我试着逃避,但什么也没有成功。有人知道我该怎么解决这个问题吗?
发布于 2019-04-14 09:56:55
可以使用后排转义gotpl占位符。例如,在您的场景中,您可以不使用{{ pod }}编写{{` {{ pod }} `}}。
发布于 2021-01-21 12:11:39
将仪表板json移动到单独的文件中,让我们将其命名为dashboard.json。然后,在configmap文件中:不要将json内联地列出,而是通过键入以下命令来引用dashboard.json文件:
data:
services-health.json: |-
{{ .Files.Get "dashboard.json" | indent 4 }}那就能解决问题了!
发布于 2021-05-01 23:51:50
在我的实验中,我用"legendFormat": "{{ "{{ pod }}" }}",代替了"legendFormat": "{{ "{{ pod }}" }}",,它非常高兴地返回我需要的语法(特别是对于grafana操作符GrafanaDashboard CRD)。
https://stackoverflow.com/questions/55673385
复制相似问题