blob: 2a1014d9174b49b32ede4c949dcf3641381d8206 [file] [log] [blame]
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001{{/*
2Enforce valid label value.
3See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
4*/}}
5{{- define "loki.validLabelValue" -}}
6{{- (regexReplaceAllLiteral "[^a-zA-Z0-9._-]" . "-") | trunc 63 | trimSuffix "-" | trimSuffix "_" | trimSuffix "." }}
7{{- end }}
8
9{{/*
10Expand the name of the chart.
11*/}}
12{{- define "loki.name" -}}
13{{- $default := ternary "enterprise-logs" "loki" .Values.enterprise.enabled }}
14{{- coalesce .Values.nameOverride $default | trunc 63 | trimSuffix "-" }}
15{{- end }}
16
17{{/*
18singleBinary fullname
19*/}}
20{{- define "loki.singleBinaryFullname" -}}
21{{- if .Values.fullnameOverride -}}
22{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
23{{- else -}}
24{{- $name := default .Chart.Name .Values.nameOverride -}}
25{{- if contains $name .Release.Name -}}
26{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
27{{- else -}}
28{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
29{{- end -}}
30{{- end -}}
31{{- end -}}
32
33{{/*
34Resource name template
35Params:
36 ctx = . context
37 component = component name (optional)
38 rolloutZoneName = rollout zone name (optional)
39*/}}
40{{- define "loki.resourceName" -}}
41{{- $resourceName := include "loki.fullname" .ctx -}}
42{{- if .component -}}{{- $resourceName = printf "%s-%s" $resourceName .component -}}{{- end -}}
43{{- if and (not .component) .rolloutZoneName -}}{{- printf "Component name cannot be empty if rolloutZoneName (%s) is set" .rolloutZoneName | fail -}}{{- end -}}
44{{- if .rolloutZoneName -}}{{- $resourceName = printf "%s-%s" $resourceName .rolloutZoneName -}}{{- end -}}
45{{- if gt (len $resourceName) 253 -}}{{- printf "Resource name (%s) exceeds kubernetes limit of 253 character. To fix: shorten release name if this will be a fresh install or shorten zone names (e.g. \"a\" instead of \"zone-a\") if using zone-awareness." $resourceName | fail -}}{{- end -}}
46{{- $resourceName -}}
47{{- end -}}
48
49{{/*
50Return if deployment mode is simple scalable
51*/}}
52{{- define "loki.deployment.isScalable" -}}
Mohammed Naser65cda132024-05-02 14:34:08 -040053 {{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") (eq .Values.deploymentMode "SimpleScalable") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000054{{- end -}}
55
56{{/*
57Return if deployment mode is single binary
58*/}}
59{{- define "loki.deployment.isSingleBinary" -}}
Mohammed Naser65cda132024-05-02 14:34:08 -040060 {{- or (eq .Values.deploymentMode "SingleBinary") (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000061{{- end -}}
62
63{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -040064Return if deployment mode is distributed
65*/}}
66{{- define "loki.deployment.isDistributed" -}}
67 {{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "Distributed") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }}
68{{- end -}}
69
70
71{{/*
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000072Create a default fully qualified app name.
73We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
74If release name contains chart name it will be used as a full name.
75*/}}
76{{- define "loki.fullname" -}}
77{{- if .Values.fullnameOverride }}
78{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
79{{- else }}
80{{- $name := include "loki.name" . }}
81{{- if contains $name .Release.Name }}
82{{- .Release.Name | trunc 63 | trimSuffix "-" }}
83{{- else }}
84{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
85{{- end }}
86{{- end }}
87{{- end }}
88
Giovanni Tirloni59219b62024-04-09 14:50:25 -030089{{/*
90Cluster label for rules and alerts.
91*/}}
92{{- define "loki.clusterLabel" -}}
93{{- if .Values.clusterLabelOverride }}
94{{- .Values.clusterLabelOverride | trunc 63 | trimSuffix "-" }}
95{{- else }}
96{{- if .Values.fullnameOverride }}
97{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
98{{- else }}
99{{- $name := include "loki.name" . }}
100{{- if contains $name .Release.Name }}
101{{- .Release.Name | trunc 63 | trimSuffix "-" }}
102{{- else }}
103{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
104{{- end }}
105{{- end }}
106{{- end }}
107{{- end }}
108
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000109{{/* Create a default storage config that uses filesystem storage
110This is required for CI, but Loki will not be queryable with this default
111applied, thus it is encouraged that users override this.
112*/}}
113{{- define "loki.storageConfig" -}}
114{{- if .Values.loki.storageConfig -}}
115{{- .Values.loki.storageConfig | toYaml | nindent 4 -}}
116{{- else }}
117{{- .Values.loki.defaultStorageConfig | toYaml | nindent 4 }}
118{{- end}}
119{{- end}}
120
121{{/*
122Create chart name and version as used by the chart label.
123*/}}
124{{- define "loki.chart" -}}
125{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
126{{- end }}
127
128{{/*
129Common labels
130*/}}
131{{- define "loki.labels" -}}
132helm.sh/chart: {{ include "loki.chart" . }}
133{{ include "loki.selectorLabels" . }}
134{{- if or (.Chart.AppVersion) (.Values.loki.image.tag) }}
135app.kubernetes.io/version: {{ include "loki.validLabelValue" (.Values.loki.image.tag | default .Chart.AppVersion) | quote }}
136{{- end }}
137app.kubernetes.io/managed-by: {{ .Release.Service }}
138{{- end }}
139
140{{/*
141Selector labels
142*/}}
143{{- define "loki.selectorLabels" -}}
144app.kubernetes.io/name: {{ include "loki.name" . }}
145app.kubernetes.io/instance: {{ .Release.Name }}
146{{- end }}
147
148{{/*
149Create the name of the service account to use
150*/}}
151{{- define "loki.serviceAccountName" -}}
152{{- if .Values.serviceAccount.create -}}
153 {{ default (include "loki.name" .) .Values.serviceAccount.name }}
154{{- else -}}
155 {{ default "default" .Values.serviceAccount.name }}
156{{- end -}}
157{{- end -}}
158
159{{/*
160Base template for building docker image reference
161*/}}
162{{- define "loki.baseImage" }}
163{{- $registry := .global.registry | default .service.registry | default "" -}}
164{{- $repository := .service.repository | default "" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300165{{- $ref := ternary (printf ":%s" (.service.tag | default .defaultVersion | toString)) (printf "@%s" .service.digest) (empty .service.digest) -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000166{{- if and $registry $repository -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300167 {{- printf "%s/%s%s" $registry $repository $ref -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000168{{- else -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300169 {{- printf "%s%s%s" $registry $repository $ref -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000170{{- end -}}
171{{- end -}}
172
173{{/*
174Docker image name for Loki
175*/}}
176{{- define "loki.lokiImage" -}}
177{{- $dict := dict "service" .Values.loki.image "global" .Values.global.image "defaultVersion" .Chart.AppVersion -}}
178{{- include "loki.baseImage" $dict -}}
179{{- end -}}
180
181{{/*
182Docker image name for enterprise logs
183*/}}
184{{- define "loki.enterpriseImage" -}}
185{{- $dict := dict "service" .Values.enterprise.image "global" .Values.global.image "defaultVersion" .Values.enterprise.version -}}
186{{- include "loki.baseImage" $dict -}}
187{{- end -}}
188
189{{/*
190Docker image name
191*/}}
192{{- define "loki.image" -}}
193{{- if .Values.enterprise.enabled -}}{{- include "loki.enterpriseImage" . -}}{{- else -}}{{- include "loki.lokiImage" . -}}{{- end -}}
194{{- end -}}
195
196{{/*
197Docker image name for kubectl container
198*/}}
199{{- define "loki.kubectlImage" -}}
200{{- $dict := dict "service" .Values.kubectlImage "global" .Values.global.image "defaultVersion" "latest" -}}
201{{- include "loki.baseImage" $dict -}}
202{{- end -}}
203
204{{/*
205Generated storage config for loki common config
206*/}}
207{{- define "loki.commonStorageConfig" -}}
208{{- if .Values.minio.enabled -}}
209s3:
210 endpoint: {{ include "loki.minio" $ }}
Mohammed Naser65cda132024-05-02 14:34:08 -0400211 bucketnames: chunks
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000212 secret_access_key: {{ $.Values.minio.rootPassword }}
213 access_key_id: {{ $.Values.minio.rootUser }}
214 s3forcepathstyle: true
215 insecure: true
216{{- else if eq .Values.loki.storage.type "s3" -}}
217{{- with .Values.loki.storage.s3 }}
218s3:
219 {{- with .s3 }}
220 s3: {{ . }}
221 {{- end }}
222 {{- with .endpoint }}
223 endpoint: {{ . }}
224 {{- end }}
225 {{- with .region }}
226 region: {{ . }}
227 {{- end}}
228 bucketnames: {{ $.Values.loki.storage.bucketNames.chunks }}
229 {{- with .secretAccessKey }}
230 secret_access_key: {{ . }}
231 {{- end }}
232 {{- with .accessKeyId }}
233 access_key_id: {{ . }}
234 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300235 {{- with .signatureVersion }}
236 signature_version: {{ . }}
237 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000238 s3forcepathstyle: {{ .s3ForcePathStyle }}
239 insecure: {{ .insecure }}
240 {{- with .http_config}}
241 http_config:
242 {{- with .idle_conn_timeout }}
243 idle_conn_timeout: {{ . }}
244 {{- end}}
245 {{- with .response_header_timeout }}
246 response_header_timeout: {{ . }}
247 {{- end}}
248 {{- with .insecure_skip_verify }}
249 insecure_skip_verify: {{ . }}
250 {{- end}}
251 {{- with .ca_file}}
252 ca_file: {{ . }}
253 {{- end}}
254 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300255 {{- with .backoff_config}}
256 backoff_config:
257 {{- with .min_period }}
258 min_period: {{ . }}
259 {{- end}}
260 {{- with .max_period }}
261 max_period: {{ . }}
262 {{- end}}
263 {{- with .max_retries }}
264 max_retries: {{ . }}
265 {{- end}}
266 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000267{{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300268
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000269{{- else if eq .Values.loki.storage.type "gcs" -}}
270{{- with .Values.loki.storage.gcs }}
271gcs:
272 bucket_name: {{ $.Values.loki.storage.bucketNames.chunks }}
273 chunk_buffer_size: {{ .chunkBufferSize }}
274 request_timeout: {{ .requestTimeout }}
275 enable_http2: {{ .enableHttp2 }}
276{{- end -}}
277{{- else if eq .Values.loki.storage.type "azure" -}}
278{{- with .Values.loki.storage.azure }}
279azure:
280 account_name: {{ .accountName }}
281 {{- with .accountKey }}
282 account_key: {{ . }}
283 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300284 {{- with .connectionString }}
285 connection_string: {{ . }}
286 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000287 container_name: {{ $.Values.loki.storage.bucketNames.chunks }}
288 use_managed_identity: {{ .useManagedIdentity }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300289 use_federated_token: {{ .useFederatedToken }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000290 {{- with .userAssignedId }}
291 user_assigned_id: {{ . }}
292 {{- end }}
293 {{- with .requestTimeout }}
294 request_timeout: {{ . }}
295 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300296 {{- with .endpointSuffix }}
297 endpoint_suffix: {{ . }}
298 {{- end }}
299{{- end -}}
300{{- else if eq .Values.loki.storage.type "swift" -}}
301{{- with .Values.loki.storage.swift }}
302swift:
303 {{- with .auth_version }}
304 auth_version: {{ . }}
305 {{- end }}
306 auth_url: {{ .auth_url }}
307 {{- with .internal }}
308 internal: {{ . }}
309 {{- end }}
310 username: {{ .username }}
311 user_domain_name: {{ .user_domain_name }}
312 {{- with .user_domain_id }}
313 user_domain_id: {{ . }}
314 {{- end }}
315 {{- with .user_id }}
316 user_id: {{ . }}
317 {{- end }}
318 password: {{ .password }}
319 {{- with .domain_id }}
320 domain_id: {{ . }}
321 {{- end }}
322 domain_name: {{ .domain_name }}
323 project_id: {{ .project_id }}
324 project_name: {{ .project_name }}
325 project_domain_id: {{ .project_domain_id }}
326 project_domain_name: {{ .project_domain_name }}
327 region_name: {{ .region_name }}
328 container_name: {{ .container_name }}
329 max_retries: {{ .max_retries | default 3 }}
330 connect_timeout: {{ .connect_timeout | default "10s" }}
331 request_timeout: {{ .request_timeout | default "5s" }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000332{{- end -}}
333{{- else -}}
334{{- with .Values.loki.storage.filesystem }}
335filesystem:
336 chunks_directory: {{ .chunks_directory }}
337 rules_directory: {{ .rules_directory }}
338{{- end -}}
339{{- end -}}
340{{- end -}}
341
342{{/*
343Storage config for ruler
344*/}}
345{{- define "loki.rulerStorageConfig" -}}
346{{- if .Values.minio.enabled -}}
347type: "s3"
348s3:
Mohammed Naser65cda132024-05-02 14:34:08 -0400349 bucketnames: ruler
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000350{{- else if eq .Values.loki.storage.type "s3" -}}
351{{- with .Values.loki.storage.s3 }}
352type: "s3"
353s3:
354 {{- with .s3 }}
355 s3: {{ . }}
356 {{- end }}
357 {{- with .endpoint }}
358 endpoint: {{ . }}
359 {{- end }}
360 {{- with .region }}
361 region: {{ . }}
362 {{- end}}
363 bucketnames: {{ $.Values.loki.storage.bucketNames.ruler }}
364 {{- with .secretAccessKey }}
365 secret_access_key: {{ . }}
366 {{- end }}
367 {{- with .accessKeyId }}
368 access_key_id: {{ . }}
369 {{- end }}
370 s3forcepathstyle: {{ .s3ForcePathStyle }}
371 insecure: {{ .insecure }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300372 {{- with .http_config }}
373 http_config: {{ toYaml . | nindent 6 }}
374 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000375{{- end -}}
376{{- else if eq .Values.loki.storage.type "gcs" -}}
377{{- with .Values.loki.storage.gcs }}
378type: "gcs"
379gcs:
380 bucket_name: {{ $.Values.loki.storage.bucketNames.ruler }}
381 chunk_buffer_size: {{ .chunkBufferSize }}
382 request_timeout: {{ .requestTimeout }}
383 enable_http2: {{ .enableHttp2 }}
384{{- end -}}
385{{- else if eq .Values.loki.storage.type "azure" -}}
386{{- with .Values.loki.storage.azure }}
387type: "azure"
388azure:
389 account_name: {{ .accountName }}
390 {{- with .accountKey }}
391 account_key: {{ . }}
392 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300393 {{- with .connectionString }}
394 connection_string: {{ . }}
395 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000396 container_name: {{ $.Values.loki.storage.bucketNames.ruler }}
397 use_managed_identity: {{ .useManagedIdentity }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300398 use_federated_token: {{ .useFederatedToken }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000399 {{- with .userAssignedId }}
400 user_assigned_id: {{ . }}
401 {{- end }}
402 {{- with .requestTimeout }}
403 request_timeout: {{ . }}
404 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300405 {{- with .endpointSuffix }}
406 endpoint_suffix: {{ . }}
407 {{- end }}
408{{- end -}}
409{{- else if eq .Values.loki.storage.type "swift" -}}
410{{- with .Values.loki.storage.swift }}
411swift:
412 {{- with .auth_version }}
413 auth_version: {{ . }}
414 {{- end }}
415 auth_url: {{ .auth_url }}
416 {{- with .internal }}
417 internal: {{ . }}
418 {{- end }}
419 username: {{ .username }}
420 user_domain_name: {{ .user_domain_name }}
421 {{- with .user_domain_id }}
422 user_domain_id: {{ . }}
423 {{- end }}
424 {{- with .user_id }}
425 user_id: {{ . }}
426 {{- end }}
427 password: {{ .password }}
428 {{- with .domain_id }}
429 domain_id: {{ . }}
430 {{- end }}
431 domain_name: {{ .domain_name }}
432 project_id: {{ .project_id }}
433 project_name: {{ .project_name }}
434 project_domain_id: {{ .project_domain_id }}
435 project_domain_name: {{ .project_domain_name }}
436 region_name: {{ .region_name }}
437 container_name: {{ .container_name }}
438 max_retries: {{ .max_retries | default 3 }}
439 connect_timeout: {{ .connect_timeout | default "10s" }}
440 request_timeout: {{ .request_timeout | default "5s" }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000441{{- end -}}
442{{- else }}
443type: "local"
444{{- end -}}
445{{- end -}}
446
447{{/* Loki ruler config */}}
448{{- define "loki.rulerConfig" }}
449ruler:
450 storage:
451 {{- include "loki.rulerStorageConfig" . | nindent 4}}
452{{- if (not (empty .Values.loki.rulerConfig)) }}
453{{- toYaml .Values.loki.rulerConfig | nindent 2}}
454{{- end }}
455{{- end }}
456
457{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400458Calculate the config from structured and unstructured text input
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300459*/}}
460{{- define "loki.calculatedConfig" -}}
461{{ tpl (mergeOverwrite (tpl .Values.loki.config . | fromYaml) .Values.loki.structuredConfig | toYaml) . }}
462{{- end }}
463
464{{/*
465The volume to mount for loki configuration
466*/}}
467{{- define "loki.configVolume" -}}
468{{- if eq .Values.loki.configStorageType "Secret" -}}
469secret:
Mohammed Naser65cda132024-05-02 14:34:08 -0400470 secretName: {{ tpl .Values.loki.configObjectName . }}
471{{- else -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300472configMap:
Mohammed Naser65cda132024-05-02 14:34:08 -0400473 name: {{ tpl .Values.loki.configObjectName . }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300474 items:
475 - key: "config.yaml"
476 path: "config.yaml"
477{{- end -}}
478{{- end -}}
479
480{{/*
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000481Memcached Docker image
482*/}}
483{{- define "loki.memcachedImage" -}}
484{{- $dict := dict "service" .Values.memcached.image "global" .Values.global.image -}}
485{{- include "loki.image" $dict -}}
486{{- end }}
487
488{{/*
489Memcached Exporter Docker image
490*/}}
491{{- define "loki.memcachedExporterImage" -}}
492{{- $dict := dict "service" .Values.memcachedExporter.image "global" .Values.global.image -}}
493{{- include "loki.image" $dict -}}
494{{- end }}
495
496{{/*
497Return the appropriate apiVersion for ingress.
498*/}}
499{{- define "loki.ingress.apiVersion" -}}
500 {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
501 {{- print "networking.k8s.io/v1" -}}
502 {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
503 {{- print "networking.k8s.io/v1beta1" -}}
504 {{- else -}}
505 {{- print "extensions/v1beta1" -}}
506 {{- end -}}
507{{- end -}}
508
509{{/*
510Return if ingress is stable.
511*/}}
512{{- define "loki.ingress.isStable" -}}
513 {{- eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
514{{- end -}}
515
516{{/*
517Return if ingress supports ingressClassName.
518*/}}
519{{- define "loki.ingress.supportsIngressClassName" -}}
520 {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
521{{- end -}}
522
523{{/*
524Return if ingress supports pathType.
525*/}}
526{{- define "loki.ingress.supportsPathType" -}}
527 {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
528{{- end -}}
529
530{{/*
531Generate list of ingress service paths based on deployment type
532*/}}
533{{- define "loki.ingress.servicePaths" -}}
534{{- if (eq (include "loki.deployment.isScalable" .) "true") -}}
535{{- include "loki.ingress.scalableServicePaths" . }}
536{{- else -}}
537{{- include "loki.ingress.singleBinaryServicePaths" . }}
538{{- end -}}
539{{- end -}}
540
541{{/*
542Ingress service paths for scalable deployment
543*/}}
544{{- define "loki.ingress.scalableServicePaths" -}}
545{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "read" "paths" .Values.ingress.paths.read )}}
546{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "write" "paths" .Values.ingress.paths.write )}}
547{{- end -}}
548
549{{/*
550Ingress service paths for single binary deployment
551*/}}
552{{- define "loki.ingress.singleBinaryServicePaths" -}}
553{{- include "loki.ingress.servicePath" (dict "ctx" . "svcName" "singleBinary" "paths" .Values.ingress.paths.singleBinary )}}
554{{- end -}}
555
556{{/*
557Ingress service path helper function
558Params:
559 ctx = . context
560 svcName = service name without the "loki.fullname" part (ie. read, write)
561 paths = list of url paths to allow ingress for
562*/}}
563{{- define "loki.ingress.servicePath" -}}
564{{- $ingressApiIsStable := eq (include "loki.ingress.isStable" .ctx) "true" -}}
565{{- $ingressSupportsPathType := eq (include "loki.ingress.supportsPathType" .ctx) "true" -}}
566{{- range .paths }}
567- path: {{ . }}
568 {{- if $ingressSupportsPathType }}
569 pathType: Prefix
570 {{- end }}
571 backend:
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000572 {{- $serviceName := include "loki.ingress.serviceName" (dict "ctx" $.ctx "svcName" $.svcName) }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300573 {{- if $ingressApiIsStable }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000574 service:
575 name: {{ $serviceName }}
576 port:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300577 number: {{ $.ctx.Values.loki.server.http_listen_port }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000578 {{- else }}
579 serviceName: {{ $serviceName }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300580 servicePort: {{ $.ctx.Values.loki.server.http_listen_port }}
581 {{- end -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000582{{- end -}}
583{{- end -}}
584
585{{/*
586Ingress service name helper function
587Params:
588 ctx = . context
589 svcName = service name without the "loki.fullname" part (ie. read, write)
590*/}}
591{{- define "loki.ingress.serviceName" -}}
592{{- if (eq .svcName "singleBinary") }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300593{{- printf "%s" (include "loki.singleBinaryFullname" .ctx) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000594{{- else }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300595{{- printf "%s-%s" (include "loki.name" .ctx) .svcName }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000596{{- end -}}
597{{- end -}}
598
599{{/*
600Create the service endpoint including port for MinIO.
601*/}}
602{{- define "loki.minio" -}}
603{{- if .Values.minio.enabled -}}
Mohammed Naser65cda132024-05-02 14:34:08 -0400604{{- .Values.minio.address | default (printf "%s-%s.%s.svc:%s" .Release.Name "minio" .Release.Namespace (.Values.minio.service.port | toString)) -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000605{{- end -}}
606{{- end -}}
607
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000608{{/* Determine if deployment is using object storage */}}
609{{- define "loki.isUsingObjectStorage" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300610{{- or (eq .Values.loki.storage.type "gcs") (eq .Values.loki.storage.type "s3") (eq .Values.loki.storage.type "azure") (eq .Values.loki.storage.type "swift") (eq .Values.loki.storage.type "alibabacloud") -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000611{{- end -}}
612
613{{/* Configure the correct name for the memberlist service */}}
614{{- define "loki.memberlist" -}}
615{{ include "loki.name" . }}-memberlist
616{{- end -}}
617
618{{/* Determine the public host for the Loki cluster */}}
619{{- define "loki.host" -}}
620{{- $isSingleBinary := eq (include "loki.deployment.isSingleBinary" .) "true" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300621{{- $url := printf "%s.%s.svc.%s.:%s" (include "loki.gatewayFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.gateway.service.port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000622{{- if and $isSingleBinary (not .Values.gateway.enabled) }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300623 {{- $url = printf "%s.%s.svc.%s.:%s" (include "loki.singleBinaryFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000624{{- end }}
625{{- printf "%s" $url -}}
626{{- end -}}
627
628{{/* Determine the public endpoint for the Loki cluster */}}
629{{- define "loki.address" -}}
630{{- printf "http://%s" (include "loki.host" . ) -}}
631{{- end -}}
632
633{{/* Name of the cluster */}}
634{{- define "loki.clusterName" -}}
635{{- $name := .Values.enterprise.cluster_name | default .Release.Name }}
636{{- printf "%s" $name -}}
637{{- end -}}
638
639{{/* Name of kubernetes secret to persist GEL admin token to */}}
640{{- define "enterprise-logs.adminTokenSecret" }}
641{{- .Values.enterprise.adminToken.secret | default (printf "%s-admin-token" (include "loki.name" . )) -}}
642{{- end -}}
643
644{{/* Prefix for provisioned secrets created for each provisioned tenant */}}
645{{- define "enterprise-logs.provisionedSecretPrefix" }}
646{{- .Values.enterprise.provisioner.provisionedSecretPrefix | default (printf "%s-provisioned" (include "loki.name" . )) -}}
647{{- end -}}
648
649{{/* Name of kubernetes secret to persist canary credentials in */}}
650{{- define "enterprise-logs.selfMonitoringTenantSecret" }}
651{{- .Values.enterprise.canarySecret | default (printf "%s-%s" (include "enterprise-logs.provisionedSecretPrefix" . ) .Values.monitoring.selfMonitoring.tenant.name) -}}
652{{- end -}}
653
654{{/* Snippet for the nginx file used by gateway */}}
655{{- define "loki.nginxFile" }}
656worker_processes 5; ## Default: 1
657error_log /dev/stderr;
658pid /tmp/nginx.pid;
659worker_rlimit_nofile 8192;
660
661events {
662 worker_connections 4096; ## Default: 1024
663}
664
665http {
666 client_body_temp_path /tmp/client_temp;
667 proxy_temp_path /tmp/proxy_temp_path;
668 fastcgi_temp_path /tmp/fastcgi_temp;
669 uwsgi_temp_path /tmp/uwsgi_temp;
670 scgi_temp_path /tmp/scgi_temp;
671
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300672 client_max_body_size 4M;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000673
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300674 proxy_read_timeout 600; ## 10 minutes
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000675 proxy_send_timeout 600;
676 proxy_connect_timeout 600;
677
678 proxy_http_version 1.1;
679
680 default_type application/octet-stream;
681 log_format {{ .Values.gateway.nginxConfig.logFormat }}
682
683 {{- if .Values.gateway.verboseLogging }}
684 access_log /dev/stderr main;
685 {{- else }}
686
687 map $status $loggable {
688 ~^[23] 0;
689 default 1;
690 }
691 access_log /dev/stderr main if=$loggable;
692 {{- end }}
693
694 sendfile on;
695 tcp_nopush on;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300696 {{- if .Values.gateway.nginxConfig.resolver }}
697 resolver {{ .Values.gateway.nginxConfig.resolver }};
698 {{- else }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000699 resolver {{ .Values.global.dnsService }}.{{ .Values.global.dnsNamespace }}.svc.{{ .Values.global.clusterDomain }}.;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300700 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000701
702 {{- with .Values.gateway.nginxConfig.httpSnippet }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300703 {{- tpl . $ | nindent 2 }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000704 {{- end }}
705
706 server {
Mohammed Naser65cda132024-05-02 14:34:08 -0400707 {{- if (.Values.gateway.nginxConfig.ssl) }}
708 listen 8080 ssl;
709 {{- if .Values.gateway.nginxConfig.enableIPv6 }}
710 listen [::]:8080 ssl;
711 {{- end }}
712 {{- else }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000713 listen 8080;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300714 {{- if .Values.gateway.nginxConfig.enableIPv6 }}
715 listen [::]:8080;
716 {{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -0400717 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000718
719 {{- if .Values.gateway.basicAuth.enabled }}
720 auth_basic "Loki";
721 auth_basic_user_file /etc/nginx/secrets/.htpasswd;
722 {{- end }}
723
724 location = / {
725 return 200 'OK';
726 auth_basic off;
727 }
728
Mohammed Naser65cda132024-05-02 14:34:08 -0400729 ########################################################
730 # Configure backend targets
731
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000732 {{- $backendHost := include "loki.backendFullname" .}}
733 {{- $readHost := include "loki.readFullname" .}}
734 {{- $writeHost := include "loki.writeFullname" .}}
735
736 {{- if .Values.read.legacyReadTarget }}
737 {{- $backendHost = include "loki.readFullname" . }}
738 {{- end }}
739
Mohammed Naser65cda132024-05-02 14:34:08 -0400740 {{- $httpSchema := .Values.gateway.nginxConfig.schema }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000741
Mohammed Naser65cda132024-05-02 14:34:08 -0400742 {{- $writeUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $writeHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
743 {{- $readUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $readHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
744 {{- $backendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $backendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000745
746 {{- if .Values.gateway.nginxConfig.customWriteUrl }}
747 {{- $writeUrl = .Values.gateway.nginxConfig.customWriteUrl }}
748 {{- end }}
749 {{- if .Values.gateway.nginxConfig.customReadUrl }}
750 {{- $readUrl = .Values.gateway.nginxConfig.customReadUrl }}
751 {{- end }}
752 {{- if .Values.gateway.nginxConfig.customBackendUrl }}
753 {{- $backendUrl = .Values.gateway.nginxConfig.customBackendUrl }}
754 {{- end }}
755
Mohammed Naser65cda132024-05-02 14:34:08 -0400756 {{- $singleBinaryHost := include "loki.singleBinaryFullname" . }}
757 {{- $singleBinaryUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $singleBinaryHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
758
759 {{- $distributorHost := include "loki.distributorFullname" .}}
760 {{- $ingesterHost := include "loki.ingesterFullname" .}}
761 {{- $queryFrontendHost := include "loki.queryFrontendFullname" .}}
762 {{- $indexGatewayHost := include "loki.indexGatewayFullname" .}}
763 {{- $rulerHost := include "loki.rulerFullname" .}}
764 {{- $compactorHost := include "loki.compactorFullname" .}}
765 {{- $schedulerHost := include "loki.querySchedulerFullname" .}}
766
767
768 {{- $distributorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $distributorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) -}}
769 {{- $ingesterUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $ingesterHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
770 {{- $queryFrontendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $queryFrontendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
771 {{- $indexGatewayUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $indexGatewayHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
772 {{- $rulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $rulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
773 {{- $compactorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $compactorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
774 {{- $schedulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $schedulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
775
776 {{- if eq (include "loki.deployment.isSingleBinary" .) "true"}}
777 {{- $distributorUrl = $singleBinaryUrl }}
778 {{- $ingesterUrl = $singleBinaryUrl }}
779 {{- $queryFrontendUrl = $singleBinaryUrl }}
780 {{- $indexGatewayUrl = $singleBinaryUrl }}
781 {{- $rulerUrl = $singleBinaryUrl }}
782 {{- $compactorUrl = $singleBinaryUrl }}
783 {{- $schedulerUrl = $singleBinaryUrl }}
784 {{- else if eq (include "loki.deployment.isScalable" .) "true"}}
785 {{- $distributorUrl = $writeUrl }}
786 {{- $ingesterUrl = $writeUrl }}
787 {{- $queryFrontendUrl = $readUrl }}
788 {{- $indexGatewayUrl = $backendUrl }}
789 {{- $rulerUrl = $backendUrl }}
790 {{- $compactorUrl = $backendUrl }}
791 {{- $schedulerUrl = $backendUrl }}
792 {{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300793
794 # Distributor
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000795 location = /api/prom/push {
Mohammed Naser65cda132024-05-02 14:34:08 -0400796 proxy_pass {{ $distributorUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000797 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300798 location = /loki/api/v1/push {
Mohammed Naser65cda132024-05-02 14:34:08 -0400799 proxy_pass {{ $distributorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300800 }
801 location = /distributor/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400802 proxy_pass {{ $distributorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300803 }
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000804
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300805 # Ingester
806 location = /flush {
Mohammed Naser65cda132024-05-02 14:34:08 -0400807 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300808 }
809 location ^~ /ingester/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400810 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300811 }
812 location = /ingester {
813 internal; # to suppress 301
814 }
815
816 # Ring
817 location = /ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400818 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300819 }
820
821 # MemberListKV
822 location = /memberlist {
Mohammed Naser65cda132024-05-02 14:34:08 -0400823 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300824 }
825
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300826 # Ruler
827 location = /ruler/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400828 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300829 }
830 location = /api/prom/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400831 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300832 }
833 location ^~ /api/prom/rules/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400834 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300835 }
836 location = /loki/api/v1/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400837 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300838 }
839 location ^~ /loki/api/v1/rules/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400840 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300841 }
842 location = /prometheus/api/v1/alerts {
Mohammed Naser65cda132024-05-02 14:34:08 -0400843 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300844 }
845 location = /prometheus/api/v1/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400846 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300847 }
848
849 # Compactor
850 location = /compactor/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400851 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300852 }
853 location = /loki/api/v1/delete {
Mohammed Naser65cda132024-05-02 14:34:08 -0400854 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300855 }
856 location = /loki/api/v1/cache/generation_numbers {
Mohammed Naser65cda132024-05-02 14:34:08 -0400857 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300858 }
859
860 # IndexGateway
861 location = /indexgateway/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400862 proxy_pass {{ $indexGatewayUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300863 }
864
865 # QueryScheduler
866 location = /scheduler/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400867 proxy_pass {{ $schedulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300868 }
869
870 # Config
871 location = /config {
Mohammed Naser65cda132024-05-02 14:34:08 -0400872 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300873 }
874
875 {{- if and .Values.enterprise.enabled .Values.enterprise.adminApi.enabled }}
876 # Admin API
877 location ^~ /admin/api/ {
878 proxy_pass {{ $backendUrl }}$request_uri;
879 }
880 location = /admin/api {
881 internal; # to suppress 301
882 }
883 {{- end }}
884
885
886 # QueryFrontend, Querier
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000887 location = /api/prom/tail {
Mohammed Naser65cda132024-05-02 14:34:08 -0400888 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000889 proxy_set_header Upgrade $http_upgrade;
890 proxy_set_header Connection "upgrade";
891 }
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000892 location = /loki/api/v1/tail {
Mohammed Naser65cda132024-05-02 14:34:08 -0400893 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000894 proxy_set_header Upgrade $http_upgrade;
895 proxy_set_header Connection "upgrade";
896 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300897 location ^~ /api/prom/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400898 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000899 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300900 location = /api/prom {
901 internal; # to suppress 301
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000902 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300903 location ^~ /loki/api/v1/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400904 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300905 }
906 location = /loki/api/v1 {
907 internal; # to suppress 301
908 }
909
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000910 {{- with .Values.gateway.nginxConfig.serverSnippet }}
911 {{ . | nindent 4 }}
912 {{- end }}
913 }
914}
915{{- end }}
916
917{{/* Configure enableServiceLinks in pod */}}
918{{- define "loki.enableServiceLinks" -}}
919{{- if semverCompare ">=1.13-0" .Capabilities.KubeVersion.Version -}}
920{{- if or (.Values.loki.enableServiceLinks) (ne .Values.loki.enableServiceLinks false) -}}
921enableServiceLinks: true
922{{- else -}}
923enableServiceLinks: false
924{{- end -}}
925{{- end -}}
926{{- end -}}
927
928{{/* Determine compactor address based on target configuration */}}
929{{- define "loki.compactorAddress" -}}
930{{- $isSimpleScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
931{{- $compactorAddress := include "loki.backendFullname" . -}}
932{{- if and $isSimpleScalable .Values.read.legacyReadTarget -}}
933{{/* 2 target configuration */}}
934{{- $compactorAddress = include "loki.readFullname" . -}}
935{{- else if (not $isSimpleScalable) -}}
936{{/* single binary */}}
937{{- $compactorAddress = include "loki.singleBinaryFullname" . -}}
938{{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300939{{- printf "http://%s:%s" $compactorAddress (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000940{{- end }}
941
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300942{{/* Determine query-scheduler address */}}
943{{- define "loki.querySchedulerAddress" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300944{{- $schedulerAddress := ""}}
Mohammed Naser65cda132024-05-02 14:34:08 -0400945{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
946{{- if $isDistributed -}}
947{{- $schedulerAddress = printf "%s.%s.svc.%s:%s" (include "loki.querySchedulerFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300948{{- end -}}
949{{- printf "%s" $schedulerAddress }}
950{{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -0400951
952{{/* Determine querier address */}}
953{{- define "loki.querierAddress" -}}
954{{- $querierAddress := "" }}
955{{- if "loki.deployment.isDistributed "}}
956{{- $querierHost := include "loki.querierFullname" .}}
957{{- $querierUrl := printf "http://%s.%s.svc.%s:3100" $querierHost .Release.Namespace .Values.global.clusterDomain }}
958{{- $querierAddress = $querierUrl }}
959{{- end -}}
960{{- printf "%s" $querierAddress }}
961{{- end }}
962
963{{/* Determine index-gateway address */}}
964{{- define "loki.indexGatewayAddress" -}}
965{{- $idxGatewayAddress := ""}}
966{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
967{{- $isScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
968{{- if $isDistributed -}}
969{{- $idxGatewayAddress = printf "dns+%s-headless.%s.svc.%s:%s" (include "loki.indexGatewayFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
970{{- end -}}
971{{- if $isScalable -}}
972{{- $idxGatewayAddress = printf "dns+%s-headless.%s.svc.%s:%s" (include "loki.backendFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
973{{- end -}}
974{{- printf "%s" $idxGatewayAddress }}
975{{- end }}
976
977{{- define "loki.config.checksum" -}}
978checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
979{{- end -}}
980
981{{/*
982Return the appropriate apiVersion for PodDisruptionBudget.
983*/}}
984{{- define "loki.pdb.apiVersion" -}}
985 {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">=1.21-0" .Capabilities.KubeVersion.Version) -}}
986 {{- print "policy/v1" -}}
987 {{- else -}}
988 {{- print "policy/v1beta1" -}}
989 {{- end -}}
990{{- end -}}
991
992{{/*
993Return the object store type for use with the test schema.
994*/}}
995{{- define "loki.testSchemaObjectStore" -}}
996 {{- if .Values.minio.enabled -}}
997 s3
998 {{- else -}}
999 filesystem
1000 {{- end -}}
1001{{- end -}}