_helpers.tpl 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "prometheus.name" -}}
  6. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
  7. {{- end -}}
  8. {{/*
  9. Create chart name and version as used by the chart label.
  10. */}}
  11. {{- define "prometheus.chart" -}}
  12. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
  13. {{- end -}}
  14. {{/*
  15. Create unified labels for prometheus components
  16. */}}
  17. {{- define "prometheus.common.matchLabels" -}}
  18. app: {{ template "prometheus.name" . }}
  19. release: {{ .Release.Name }}
  20. {{- end -}}
  21. {{- define "prometheus.common.metaLabels" -}}
  22. chart: {{ template "prometheus.chart" . }}
  23. heritage: {{ .Release.Service }}
  24. {{- end -}}
  25. {{- define "prometheus.alertmanager.labels" -}}
  26. {{ include "prometheus.alertmanager.matchLabels" . }}
  27. {{ include "prometheus.common.metaLabels" . }}
  28. {{- end -}}
  29. {{- define "prometheus.alertmanager.matchLabels" -}}
  30. component: {{ .Values.alertmanager.name | quote }}
  31. {{ include "prometheus.common.matchLabels" . }}
  32. {{- end -}}
  33. {{- define "prometheus.nodeExporter.labels" -}}
  34. {{ include "prometheus.nodeExporter.matchLabels" . }}
  35. {{ include "prometheus.common.metaLabels" . }}
  36. {{- end -}}
  37. {{- define "prometheus.nodeExporter.matchLabels" -}}
  38. component: {{ .Values.nodeExporter.name | quote }}
  39. {{ include "prometheus.common.matchLabels" . }}
  40. {{- end -}}
  41. {{- define "prometheus.pushgateway.labels" -}}
  42. {{ include "prometheus.pushgateway.matchLabels" . }}
  43. {{ include "prometheus.common.metaLabels" . }}
  44. {{- end -}}
  45. {{- define "prometheus.pushgateway.matchLabels" -}}
  46. component: {{ .Values.pushgateway.name | quote }}
  47. {{ include "prometheus.common.matchLabels" . }}
  48. {{- end -}}
  49. {{- define "prometheus.server.labels" -}}
  50. {{ include "prometheus.server.matchLabels" . }}
  51. {{ include "prometheus.common.metaLabels" . }}
  52. {{- end -}}
  53. {{- define "prometheus.server.matchLabels" -}}
  54. component: {{ .Values.server.name | quote }}
  55. {{ include "prometheus.common.matchLabels" . }}
  56. {{- end -}}
  57. {{/*
  58. Create a default fully qualified app name.
  59. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  60. */}}
  61. {{- define "prometheus.fullname" -}}
  62. {{- if .Values.fullnameOverride -}}
  63. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  64. {{- else -}}
  65. {{- $name := default .Chart.Name .Values.nameOverride -}}
  66. {{- if contains $name .Release.Name -}}
  67. {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
  68. {{- else -}}
  69. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  70. {{- end -}}
  71. {{- end -}}
  72. {{- end -}}
  73. {{/*
  74. Create a fully qualified alertmanager name.
  75. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  76. */}}
  77. {{- define "prometheus.alertmanager.fullname" -}}
  78. {{- if .Values.alertmanager.fullnameOverride -}}
  79. {{- .Values.alertmanager.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  80. {{- else -}}
  81. {{- $name := default .Chart.Name .Values.nameOverride -}}
  82. {{- if contains $name .Release.Name -}}
  83. {{- printf "%s-%s" .Release.Name .Values.alertmanager.name | trunc 63 | trimSuffix "-" -}}
  84. {{- else -}}
  85. {{- printf "%s-%s-%s" .Release.Name $name .Values.alertmanager.name | trunc 63 | trimSuffix "-" -}}
  86. {{- end -}}
  87. {{- end -}}
  88. {{- end -}}
  89. {{/*
  90. Create a fully qualified node-exporter name.
  91. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  92. */}}
  93. {{- define "prometheus.nodeExporter.fullname" -}}
  94. {{- if .Values.nodeExporter.fullnameOverride -}}
  95. {{- .Values.nodeExporter.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  96. {{- else -}}
  97. {{- $name := default .Chart.Name .Values.nameOverride -}}
  98. {{- if contains $name .Release.Name -}}
  99. {{- printf "%s-%s" .Release.Name .Values.nodeExporter.name | trunc 63 | trimSuffix "-" -}}
  100. {{- else -}}
  101. {{- printf "%s-%s-%s" .Release.Name $name .Values.nodeExporter.name | trunc 63 | trimSuffix "-" -}}
  102. {{- end -}}
  103. {{- end -}}
  104. {{- end -}}
  105. {{/*
  106. Create a fully qualified Prometheus server name.
  107. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  108. */}}
  109. {{- define "prometheus.server.fullname" -}}
  110. {{- if .Values.server.fullnameOverride -}}
  111. {{- .Values.server.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  112. {{- else -}}
  113. {{- $name := default .Chart.Name .Values.nameOverride -}}
  114. {{- if contains $name .Release.Name -}}
  115. {{- printf "%s-%s" .Release.Name .Values.server.name | trunc 63 | trimSuffix "-" -}}
  116. {{- else -}}
  117. {{- printf "%s-%s-%s" .Release.Name $name .Values.server.name | trunc 63 | trimSuffix "-" -}}
  118. {{- end -}}
  119. {{- end -}}
  120. {{- end -}}
  121. {{/*
  122. Create a fully qualified pushgateway name.
  123. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  124. */}}
  125. {{- define "prometheus.pushgateway.fullname" -}}
  126. {{- if .Values.pushgateway.fullnameOverride -}}
  127. {{- .Values.pushgateway.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  128. {{- else -}}
  129. {{- $name := default .Chart.Name .Values.nameOverride -}}
  130. {{- if contains $name .Release.Name -}}
  131. {{- printf "%s-%s" .Release.Name .Values.pushgateway.name | trunc 63 | trimSuffix "-" -}}
  132. {{- else -}}
  133. {{- printf "%s-%s-%s" .Release.Name $name .Values.pushgateway.name | trunc 63 | trimSuffix "-" -}}
  134. {{- end -}}
  135. {{- end -}}
  136. {{- end -}}
  137. {{/*
  138. Get KubeVersion removing pre-release information.
  139. */}}
  140. {{- define "prometheus.kubeVersion" -}}
  141. {{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}}
  142. {{- end -}}
  143. {{/*
  144. Return the appropriate apiVersion for deployment.
  145. */}}
  146. {{- define "prometheus.deployment.apiVersion" -}}
  147. {{- print "apps/v1" -}}
  148. {{- end -}}
  149. {{/*
  150. Return the appropriate apiVersion for daemonset.
  151. */}}
  152. {{- define "prometheus.daemonset.apiVersion" -}}
  153. {{- print "apps/v1" -}}
  154. {{- end -}}
  155. {{/*
  156. Return the appropriate apiVersion for networkpolicy.
  157. */}}
  158. {{- define "prometheus.networkPolicy.apiVersion" -}}
  159. {{- print "networking.k8s.io/v1" -}}
  160. {{- end -}}
  161. {{/*
  162. Return the appropriate apiVersion for poddisruptionbudget.
  163. */}}
  164. {{- define "prometheus.podDisruptionBudget.apiVersion" -}}
  165. {{- if .Capabilities.APIVersions.Has "policy/v1" }}
  166. {{- print "policy/v1" -}}
  167. {{- else -}}
  168. {{- print "policy/v1beta1" -}}
  169. {{- end -}}
  170. {{- end -}}
  171. {{/*
  172. Return the appropriate apiVersion for rbac.
  173. */}}
  174. {{- define "rbac.apiVersion" -}}
  175. {{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1" }}
  176. {{- print "rbac.authorization.k8s.io/v1" -}}
  177. {{- else -}}
  178. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  179. {{- end -}}
  180. {{- end -}}
  181. {{/*
  182. Return the appropriate apiVersion for ingress.
  183. */}}
  184. {{- define "ingress.apiVersion" -}}
  185. {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19.x" (include "prometheus.kubeVersion" .)) -}}
  186. {{- print "networking.k8s.io/v1" -}}
  187. {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
  188. {{- print "networking.k8s.io/v1beta1" -}}
  189. {{- else -}}
  190. {{- print "extensions/v1beta1" -}}
  191. {{- end -}}
  192. {{- end -}}
  193. {{/*
  194. Return if ingress is stable.
  195. */}}
  196. {{- define "ingress.isStable" -}}
  197. {{- eq (include "ingress.apiVersion" .) "networking.k8s.io/v1" -}}
  198. {{- end -}}
  199. {{/*
  200. Return if ingress supports ingressClassName.
  201. */}}
  202. {{- define "ingress.supportsIngressClassName" -}}
  203. {{- or (eq (include "ingress.isStable" .) "true") (and (eq (include "ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "prometheus.kubeVersion" .))) -}}
  204. {{- end -}}
  205. {{/*
  206. Return if ingress supports pathType.
  207. */}}
  208. {{- define "ingress.supportsPathType" -}}
  209. {{- or (eq (include "ingress.isStable" .) "true") (and (eq (include "ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "prometheus.kubeVersion" .))) -}}
  210. {{- end -}}
  211. {{/*
  212. Create the name of the service account to use for the alertmanager component
  213. */}}
  214. {{- define "prometheus.serviceAccountName.alertmanager" -}}
  215. {{- if .Values.serviceAccounts.alertmanager.create -}}
  216. {{ default (include "prometheus.alertmanager.fullname" .) .Values.serviceAccounts.alertmanager.name }}
  217. {{- else -}}
  218. {{ default "default" .Values.serviceAccounts.alertmanager.name }}
  219. {{- end -}}
  220. {{- end -}}
  221. {{/*
  222. Create the name of the service account to use for the nodeExporter component
  223. */}}
  224. {{- define "prometheus.serviceAccountName.nodeExporter" -}}
  225. {{- if .Values.serviceAccounts.nodeExporter.create -}}
  226. {{ default (include "prometheus.nodeExporter.fullname" .) .Values.serviceAccounts.nodeExporter.name }}
  227. {{- else -}}
  228. {{ default "default" .Values.serviceAccounts.nodeExporter.name }}
  229. {{- end -}}
  230. {{- end -}}
  231. {{/*
  232. Create the name of the service account to use for the pushgateway component
  233. */}}
  234. {{- define "prometheus.serviceAccountName.pushgateway" -}}
  235. {{- if .Values.serviceAccounts.pushgateway.create -}}
  236. {{ default (include "prometheus.pushgateway.fullname" .) .Values.serviceAccounts.pushgateway.name }}
  237. {{- else -}}
  238. {{ default "default" .Values.serviceAccounts.pushgateway.name }}
  239. {{- end -}}
  240. {{- end -}}
  241. {{/*
  242. Create the name of the service account to use for the server component
  243. */}}
  244. {{- define "prometheus.serviceAccountName.server" -}}
  245. {{- if .Values.serviceAccounts.server.create -}}
  246. {{ default (include "prometheus.server.fullname" .) .Values.serviceAccounts.server.name }}
  247. {{- else -}}
  248. {{ default "default" .Values.serviceAccounts.server.name }}
  249. {{- end -}}
  250. {{- end -}}
  251. {{/*
  252. Define the prometheus.namespace template if set with forceNamespace or .Release.Namespace is set
  253. */}}
  254. {{- define "prometheus.namespace" -}}
  255. {{- if .Values.forceNamespace -}}
  256. {{ printf "namespace: %s" .Values.forceNamespace }}
  257. {{- else -}}
  258. {{ printf "namespace: %s" .Release.Namespace }}
  259. {{- end -}}
  260. {{- end -}}