cm.yaml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {{- if (empty .Values.server.configMapOverrideName) -}}
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. labels:
  6. {{- include "prometheus.server.labels" . | nindent 4 }}
  7. {{- with .Values.server.extraConfigmapLabels }}
  8. {{- toYaml . | nindent 4 }}
  9. {{- end }}
  10. name: {{ template "prometheus.server.fullname" . }}
  11. {{ include "prometheus.namespace" . | indent 2 }}
  12. data:
  13. allow-snippet-annotations: "false"
  14. {{- $root := . -}}
  15. {{- range $key, $value := .Values.ruleFiles }}
  16. {{ $key }}: {{- toYaml $value | indent 2 }}
  17. {{- end }}
  18. {{- range $key, $value := .Values.serverFiles }}
  19. {{ $key }}: |
  20. {{- if eq $key "prometheus.yml" }}
  21. global:
  22. {{ $root.Values.server.global | toYaml | trimSuffix "\n" | indent 6 }}
  23. {{- if $root.Values.server.remoteWrite }}
  24. remote_write:
  25. {{ $root.Values.server.remoteWrite | toYaml | indent 4 }}
  26. {{- end }}
  27. {{- if $root.Values.server.remoteRead }}
  28. remote_read:
  29. {{ $root.Values.server.remoteRead | toYaml | indent 4 }}
  30. {{- end }}
  31. {{- end }}
  32. {{- if eq $key "alerts" }}
  33. {{- if and (not (empty $value)) (empty $value.groups) }}
  34. groups:
  35. {{- range $ruleKey, $ruleValue := $value }}
  36. - name: {{ $ruleKey -}}.rules
  37. rules:
  38. {{ $ruleValue | toYaml | trimSuffix "\n" | indent 6 }}
  39. {{- end }}
  40. {{- else }}
  41. {{ toYaml $value | indent 4 }}
  42. {{- end }}
  43. {{- else }}
  44. {{ toYaml $value | default "{}" | indent 4 }}
  45. {{- end }}
  46. {{- if eq $key "prometheus.yml" -}}
  47. {{- if $root.Values.extraScrapeConfigs }}
  48. {{ tpl $root.Values.extraScrapeConfigs $root | indent 4 }}
  49. {{- end -}}
  50. {{- if or ($root.Values.alertmanager.enabled) ($root.Values.server.alertmanagers) }}
  51. alerting:
  52. {{- if $root.Values.alertRelabelConfigs }}
  53. {{ $root.Values.alertRelabelConfigs | toYaml | trimSuffix "\n" | indent 6 }}
  54. {{- end }}
  55. alertmanagers:
  56. {{- if $root.Values.server.alertmanagers }}
  57. {{ toYaml $root.Values.server.alertmanagers | indent 8 }}
  58. {{- else }}
  59. - kubernetes_sd_configs:
  60. - role: pod
  61. tls_config:
  62. ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  63. bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  64. {{- if $root.Values.alertmanager.prefixURL }}
  65. path_prefix: {{ $root.Values.alertmanager.prefixURL }}
  66. {{- end }}
  67. relabel_configs:
  68. - source_labels: [__meta_kubernetes_namespace]
  69. regex: {{ $root.Release.Namespace }}
  70. action: keep
  71. - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
  72. regex: {{ $root.Release.Name }}
  73. action: keep
  74. - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_name]
  75. regex: {{ default "alertmanager" $root.Values.alertmanager.nameOverride | trunc 63 | trimSuffix "-" }}
  76. action: keep
  77. - source_labels: [__meta_kubernetes_pod_container_port_number]
  78. regex: "9093"
  79. action: keep
  80. {{- end -}}
  81. {{- end -}}
  82. {{- end -}}
  83. {{- end -}}
  84. {{- end -}}