_helpers.tpl 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "tempo.name" -}}
  6. {{- default "tempo" .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
  7. {{- end -}}
  8. {{/*
  9. Create a default fully qualified app name.
  10. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  11. If release name contains chart name it will be used as a full name.
  12. */}}
  13. {{- define "tempo.fullname" -}}
  14. {{- if .Values.fullnameOverride -}}
  15. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  16. {{- else -}}
  17. {{- $name := default "tempo" .Values.nameOverride -}}
  18. {{- if contains $name .Release.Name -}}
  19. {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
  20. {{- else -}}
  21. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  22. {{- end -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{/*
  26. Docker image selector for Tempo. Hierachy based on global, component, and tempo values.
  27. */}}
  28. {{- define "tempo.tempoImage" -}}
  29. {{- $registry := coalesce .global.registry .component.registry .tempo.registry -}}
  30. {{- $repository := coalesce .component.repository .tempo.repository -}}
  31. {{- $tag := coalesce .component.tag .tempo.tag .defaultVersion | toString -}}
  32. {{- printf "%s/%s:%s" $registry $repository $tag -}}
  33. {{- end -}}
  34. {{/*
  35. Optional list of imagePullSecrets for Tempo docker images
  36. */}}
  37. {{- define "tempo.imagePullSecrets" -}}
  38. {{- $imagePullSecrets := coalesce .global.pullSecrets .component.pullSecrets .tempo.pullSecrets -}}
  39. {{- if $imagePullSecrets -}}
  40. imagePullSecrets:
  41. {{- range $imagePullSecrets }}
  42. - name: {{ . }}
  43. {{ end }}
  44. {{- end }}
  45. {{- end -}}
  46. {{/*
  47. Create chart name and version as used by the chart label.
  48. */}}
  49. {{- define "tempo.chart" -}}
  50. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
  51. {{- end -}}
  52. {{/*
  53. Calculate image name based on whether enterprise features are requested. Fallback to hierarchy handling in `tempo.tempoImage`.
  54. */}}
  55. {{- define "tempo.imageReference" -}}
  56. {{ $tempo := "" }}
  57. {{- if .ctx.Values.enterprise.enabled -}}
  58. {{ $tempo = merge .ctx.Values.enterprise.image .ctx.Values.tempo.image }}
  59. {{- else -}}
  60. {{ $tempo = .ctx.Values.tempo.image }}
  61. {{- end -}}
  62. {{- $componentSection := include "tempo.componentSectionFromName" . }}
  63. {{- if not (hasKey .ctx.Values $componentSection) }}
  64. {{- print "Component section " $componentSection " does not exist" | fail }}
  65. {{- end }}
  66. {{- $component := (index .ctx.Values $componentSection).image | default dict }}
  67. {{- $dict := dict "tempo" $tempo "component" $component "global" .ctx.Values.global.image "defaultVersion" .ctx.Chart.AppVersion -}}
  68. {{- include "tempo.tempoImage" $dict -}}
  69. {{- end -}}
  70. {{/*
  71. Simple resource labels
  72. */}}
  73. {{- define "tempo.labels" -}}
  74. helm.sh/chart: {{ include "tempo.chart" .ctx }}
  75. app.kubernetes.io/name: {{ include "tempo.name" .ctx }}
  76. app.kubernetes.io/instance: {{ .ctx.Release.Name }}
  77. {{- if .component }}
  78. app.kubernetes.io/component: {{ .component }}
  79. {{- end }}
  80. {{- if .memberlist }}
  81. app.kubernetes.io/part-of: memberlist
  82. {{- end }}
  83. {{- if .ctx.Chart.AppVersion }}
  84. app.kubernetes.io/version: {{ .ctx.Chart.AppVersion | quote }}
  85. {{- end }}
  86. app.kubernetes.io/managed-by: {{ .ctx.Release.Service }}
  87. {{- end -}}
  88. {{/*
  89. Simple service selector labels
  90. */}}
  91. {{- define "tempo.selectorLabels" -}}
  92. app.kubernetes.io/name: {{ include "tempo.name" .ctx }}
  93. app.kubernetes.io/instance: {{ .ctx.Release.Name }}
  94. {{- if .component }}
  95. app.kubernetes.io/component: {{ .component }}
  96. {{- end -}}
  97. {{- end -}}
  98. {{/*
  99. Create the name of the service account to use
  100. */}}
  101. {{- define "tempo.serviceAccountName" -}}
  102. {{- if .Values.serviceAccount.create -}}
  103. {{ default (include "tempo.fullname" .) .Values.serviceAccount.name }}
  104. {{- else -}}
  105. {{ default "default" .Values.serviceAccount.name }}
  106. {{- end -}}
  107. {{- end -}}
  108. {{/*
  109. Return the appropriate apiVersion for ingress.
  110. */}}
  111. {{- define "tempo.ingress.apiVersion" -}}
  112. {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
  113. {{- print "networking.k8s.io/v1" -}}
  114. {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
  115. {{- print "networking.k8s.io/v1beta1" -}}
  116. {{- else -}}
  117. {{- print "extensions/v1beta1" -}}
  118. {{- end -}}
  119. {{- end -}}
  120. {{/*
  121. Return if ingress is stable.
  122. */}}
  123. {{- define "tempo.ingress.isStable" -}}
  124. {{- eq (include "tempo.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
  125. {{- end -}}
  126. {{/*
  127. Return if ingress supports ingressClassName.
  128. */}}
  129. {{- define "tempo.ingress.supportsIngressClassName" -}}
  130. {{- or (eq (include "tempo.ingress.isStable" .) "true") (and (eq (include "tempo.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  131. {{- end -}}
  132. {{/*
  133. Return if ingress supports pathType.
  134. */}}
  135. {{- define "tempo.ingress.supportsPathType" -}}
  136. {{- or (eq (include "tempo.ingress.isStable" .) "true") (and (eq (include "tempo.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  137. {{- end -}}
  138. {{/*
  139. Return the appropriate apiVersion for PodDisruptionBudget.
  140. */}}
  141. {{- define "tempo.pdb.apiVersion" -}}
  142. {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">=1.21-0" .Capabilities.KubeVersion.Version) -}}
  143. {{- print "policy/v1" -}}
  144. {{- else -}}
  145. {{- print "policy/v1beta1" -}}
  146. {{- end -}}
  147. {{- end -}}
  148. {{/*
  149. Return the appropriate apiVersion for HorizontalPodAutoscaler.
  150. */}}
  151. {{- define "tempo.hpa.apiVersion" -}}
  152. {{- if and (.Capabilities.APIVersions.Has "autoscaling/v2") (semverCompare ">=1.23-0" .Capabilities.KubeVersion.Version) -}}
  153. {{- print "autoscaling/v2" -}}
  154. {{- else -}}
  155. {{- print "autoscaling/v2beta1" -}}
  156. {{- end -}}
  157. {{- end -}}
  158. {{/*
  159. Resource name template
  160. */}}
  161. {{- define "tempo.resourceName" -}}
  162. {{ include "tempo.fullname" .ctx }}{{- if .component -}}-{{ .component }}{{- end -}}
  163. {{- end -}}
  164. {{/*
  165. Calculate the config from structured and unstructured text input
  166. */}}
  167. {{- define "tempo.calculatedConfig" -}}
  168. {{ tpl (mergeOverwrite (tpl .Values.config . | fromYaml) .Values.tempo.structuredConfig | toYaml) . }}
  169. {{- end -}}
  170. {{/*
  171. Renders the overrides config
  172. */}}
  173. {{- define "tempo.overridesConfig" -}}
  174. {{ tpl .Values.overrides . }}
  175. {{- end -}}
  176. {{/*
  177. The volume to mount for tempo configuration
  178. */}}
  179. {{- define "tempo.configVolume" -}}
  180. {{- if eq .Values.configStorageType "Secret" -}}
  181. secret:
  182. secretName: {{ tpl .Values.externalConfigSecretName . }}
  183. {{- else if eq .Values.configStorageType "ConfigMap" -}}
  184. configMap:
  185. name: {{ tpl .Values.externalConfigSecretName . }}
  186. items:
  187. - key: "tempo.yaml"
  188. path: "tempo.yaml"
  189. {{- if .Values.queryFrontend.query.enabled }}
  190. - key: "tempo-query.yaml"
  191. path: "tempo-query.yaml"
  192. {{- end -}}
  193. {{- end -}}
  194. {{- end -}}
  195. {{/*
  196. The volume to mount for tempo runtime configuration
  197. */}}
  198. {{- define "tempo.runtimeVolume" -}}
  199. configMap:
  200. name: {{ tpl .Values.externalRuntimeConfigName . }}
  201. items:
  202. - key: "overrides.yaml"
  203. path: "overrides.yaml"
  204. {{- end -}}
  205. {{/*
  206. Internal servers http listen port - derived from Loki default
  207. */}}
  208. {{- define "tempo.serverHttpListenPort" -}}
  209. {{ (((.Values.tempo).structuredConfig).server).http_listen_port | default "3100" }}
  210. {{- end -}}
  211. {{/*
  212. Internal servers grpc listen port - derived from Tempo default
  213. */}}
  214. {{- define "tempo.serverGrpcListenPort" -}}
  215. {{ (((.Values.tempo).structuredConfig).server).grpc_listen_port | default "9095" }}
  216. {{- end -}}
  217. {{/*
  218. Memberlist bind port
  219. */}}
  220. {{- define "tempo.memberlistBindPort" -}}
  221. {{ (((.Values.tempo).structuredConfig).memberlist).bind_port | default "7946" }}
  222. {{- end -}}
  223. {{/*
  224. Calculate values.yaml section name from component name
  225. Expects the component name in .component on the passed context
  226. */}}
  227. {{- define "tempo.componentSectionFromName" -}}
  228. {{- .component | replace "-" "_" | camelcase | untitle -}}
  229. {{- end -}}
  230. {{/*
  231. POD labels
  232. */}}
  233. {{- define "tempo.podLabels" -}}
  234. helm.sh/chart: {{ include "tempo.chart" .ctx }}
  235. app.kubernetes.io/name: {{ include "tempo.name" .ctx }}
  236. app.kubernetes.io/instance: {{ .ctx.Release.Name }}
  237. app.kubernetes.io/version: {{ .ctx.Chart.AppVersion | quote }}
  238. app.kubernetes.io/managed-by: {{ .ctx.Release.Service }}
  239. {{- if .component }}
  240. app.kubernetes.io/component: {{ .component }}
  241. {{- end }}
  242. {{- if .memberlist }}
  243. app.kubernetes.io/part-of: memberlist
  244. {{- end -}}
  245. {{- end -}}
  246. {{/*
  247. POD annotations
  248. */}}
  249. {{- define "tempo.podAnnotations" -}}
  250. {{- if .ctx.Values.useExternalConfig }}
  251. checksum/config: {{ .ctx.Values.externalConfigVersion }}
  252. {{- else -}}
  253. checksum/config: {{ include (print .ctx.Template.BasePath "/configmap-tempo.yaml") .ctx | sha256sum }}
  254. {{- end }}
  255. {{- with .ctx.Values.global.podAnnotations }}
  256. {{ toYaml . }}
  257. {{- end }}
  258. {{- if .component }}
  259. {{- $componentSection := include "tempo.componentSectionFromName" . }}
  260. {{- if not (hasKey .ctx.Values $componentSection) }}
  261. {{- print "Component section " $componentSection " does not exist" | fail }}
  262. {{- end }}
  263. {{- with (index .ctx.Values $componentSection).podAnnotations }}
  264. {{ toYaml . }}
  265. {{- end }}
  266. {{- end }}
  267. {{- end -}}
  268. {{/*
  269. Cluster name that shows up in dashboard metrics
  270. */}}
  271. {{- define "tempo.clusterName" -}}
  272. {{ (include "tempo.calculatedConfig" . | fromYaml).cluster_name | default .Release.Name }}
  273. {{- end -}}