_helpers.tpl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {{/*
  2. Expand the name of the chart.
  3. */}}
  4. {{- define "loki.name" -}}
  5. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
  6. {{- end }}
  7. {{/*
  8. Create a default fully qualified app name.
  9. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  10. If release name contains chart name it will be used as a full name.
  11. */}}
  12. {{- define "loki.fullname" -}}
  13. {{- if .Values.fullnameOverride }}
  14. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
  15. {{- else }}
  16. {{- $name := default .Chart.Name .Values.nameOverride }}
  17. {{- if contains $name .Release.Name }}
  18. {{- .Release.Name | trunc 63 | trimSuffix "-" }}
  19. {{- else }}
  20. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
  21. {{- end }}
  22. {{- end }}
  23. {{- end }}
  24. {{/*
  25. Create chart name and version as used by the chart label.
  26. */}}
  27. {{- define "loki.chart" -}}
  28. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
  29. {{- end }}
  30. {{/*
  31. Common labels
  32. */}}
  33. {{- define "loki.labels" -}}
  34. helm.sh/chart: {{ include "loki.chart" . }}
  35. {{ include "loki.selectorLabels" . }}
  36. {{- if .Chart.AppVersion }}
  37. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  38. {{- end }}
  39. app.kubernetes.io/managed-by: {{ .Release.Service }}
  40. {{- end }}
  41. {{/*
  42. Selector labels
  43. */}}
  44. {{- define "loki.selectorLabels" -}}
  45. app.kubernetes.io/name: {{ include "loki.name" . }}
  46. app.kubernetes.io/instance: {{ .Release.Name }}
  47. {{- end }}
  48. {{/*
  49. Create the name of the service account to use
  50. */}}
  51. {{- define "loki.serviceAccountName" -}}
  52. {{- if .Values.serviceAccount.create -}}
  53. {{ default (include "loki.fullname" .) .Values.serviceAccount.name }}
  54. {{- else -}}
  55. {{ default "default" .Values.serviceAccount.name }}
  56. {{- end -}}
  57. {{- end -}}
  58. {{/*
  59. Docker image name for Loki
  60. */}}
  61. {{- define "loki.lokiImage" -}}
  62. {{- $registry := coalesce .global.registry .service.registry .loki.registry -}}
  63. {{- $repository := coalesce .service.repository .loki.repository -}}
  64. {{- $tag := coalesce .service.tag .loki.tag .defaultVersion | toString -}}
  65. {{- printf "%s/%s:%s" $registry $repository $tag -}}
  66. {{- end -}}
  67. {{/*
  68. Docker image name
  69. */}}
  70. {{- define "loki.image" -}}
  71. {{- $registry := coalesce .global.registry .service.registry -}}
  72. {{- $tag := .service.tag | toString -}}
  73. {{- printf "%s/%s:%s" $registry .service.repository (.service.tag | toString) -}}
  74. {{- end -}}
  75. {{/*
  76. Memcached Docker image
  77. */}}
  78. {{- define "loki.memcachedImage" -}}
  79. {{- $dict := dict "service" .Values.memcached.image "global" .Values.global.image -}}
  80. {{- include "loki.image" $dict -}}
  81. {{- end }}
  82. {{/*
  83. Memcached Exporter Docker image
  84. */}}
  85. {{- define "loki.memcachedExporterImage" -}}
  86. {{- $dict := dict "service" .Values.memcachedExporter.image "global" .Values.global.image -}}
  87. {{- include "loki.image" $dict -}}
  88. {{- end }}
  89. {{/*
  90. Return the appropriate apiVersion for ingress.
  91. */}}
  92. {{- define "loki.ingress.apiVersion" -}}
  93. {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
  94. {{- print "networking.k8s.io/v1" -}}
  95. {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
  96. {{- print "networking.k8s.io/v1beta1" -}}
  97. {{- else -}}
  98. {{- print "extensions/v1beta1" -}}
  99. {{- end -}}
  100. {{- end -}}
  101. {{/*
  102. Return if ingress is stable.
  103. */}}
  104. {{- define "loki.ingress.isStable" -}}
  105. {{- eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
  106. {{- end -}}
  107. {{/*
  108. Return if ingress supports ingressClassName.
  109. */}}
  110. {{- define "loki.ingress.supportsIngressClassName" -}}
  111. {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  112. {{- end -}}
  113. {{/*
  114. Return if ingress supports pathType.
  115. */}}
  116. {{- define "loki.ingress.supportsPathType" -}}
  117. {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  118. {{- end -}}
  119. {{/*
  120. Return the appropriate apiVersion for PodDisruptionBudget.
  121. */}}
  122. {{- define "loki.pdb.apiVersion" -}}
  123. {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">=1.21-0" .Capabilities.KubeVersion.Version) -}}
  124. {{- print "policy/v1" -}}
  125. {{- else -}}
  126. {{- print "policy/v1beta1" -}}
  127. {{- end -}}
  128. {{- end -}}
  129. {{/*
  130. Return the appropriate apiVersion for HorizontalPodAutoscaler.
  131. */}}
  132. {{- define "loki.hpa.apiVersion" -}}
  133. {{- if and (.Capabilities.APIVersions.Has "autoscaling/v2") (semverCompare ">=1.23-0" .Capabilities.KubeVersion.Version) -}}
  134. {{- print "autoscaling/v2" -}}
  135. {{- else -}}
  136. {{- print "autoscaling/v2beta1" -}}
  137. {{- end -}}
  138. {{- end -}}
  139. {{- define "loki.ingester.readinessProbe" -}}
  140. {{- with .Values.ingester.readinessProbe }}
  141. readinessProbe:
  142. {{- toYaml . | nindent 2 }}
  143. {{- else }}
  144. {{- with .Values.loki.readinessProbe }}
  145. readinessProbe:
  146. {{- toYaml . | nindent 2 }}
  147. {{- end }}
  148. {{- end }}
  149. {{- end -}}
  150. {{- define "loki.ingester.livenessProbe" -}}
  151. {{- with .Values.ingester.livenessProbe }}
  152. livenessProbe:
  153. {{- toYaml . | nindent 2 }}
  154. {{- else }}
  155. {{- with .Values.loki.livenessProbe }}
  156. livenessProbe:
  157. {{- toYaml . | nindent 2 }}
  158. {{- end }}
  159. {{- end }}
  160. {{- end -}}
  161. {{- define "loki.config.checksum" -}}
  162. checksum/config: {{ tpl (mergeOverwrite (tpl .Values.loki.config . | fromYaml) .Values.loki.structuredConfig | toYaml) . | sha256sum }}
  163. {{- end }}