Skip to content

Commit a4928d1

Browse files
authored
[loki] Add service template helper (#188)
1 parent 1ea0523 commit a4928d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+493
-1005
lines changed

charts/loki/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: loki
33
description: Helm chart for Grafana Loki supporting monolithic, simple scalable, and microservices modes.
44
type: application
55
appVersion: 3.6.7
6-
version: 8.1.0
6+
version: 8.1.1
77
kubeVersion: ">=1.25.0-0"
88
home: https://grafana-community.github.io/helm-charts
99
sources:

charts/loki/templates/_service.tpl

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{{/*
2+
Service helper
3+
*/}}
4+
5+
{{- define "loki.service" }}
6+
{{- $target := .target }}
7+
{{- $ctx := .ctx }}
8+
{{- $component := .component }}
9+
{{- $name := .name }}
10+
{{- $headlessName := .headlessName }}
11+
{{- with $ctx }}
12+
apiVersion: v1
13+
kind: Service
14+
metadata:
15+
{{- if $name }}
16+
name: {{ $name }}
17+
{{- else }}
18+
name: "{{ include "loki.fullname" . }}-{{ $target }}"
19+
{{- end }}
20+
namespace: "{{ include "loki.namespace" . }}"
21+
labels:
22+
{{- include "loki.labels" . | nindent 4 }}
23+
app.kubernetes.io/component: {{ $target | quote }}
24+
{{- with (mergeOverwrite (dict) .Values.defaults.service.labels ($component.serviceLabels | default dict) $component.service.labels) }}
25+
{{- toYaml . | nindent 4 }}
26+
{{- end }}
27+
annotations:
28+
{{- with (mergeOverwrite (dict) .Values.loki.serviceAnnotations .Values.defaults.service.annotations ($component.serviceAnnotations | default dict) $component.service.annotations) }}
29+
{{- toYaml . | nindent 4 }}
30+
{{- end }}
31+
spec:
32+
type: {{ $component.serviceType | default $component.service.type | default "ClusterIP" }}
33+
publishNotReadyAddresses: true
34+
ports:
35+
- name: http-metrics
36+
port: 3100
37+
targetPort: http-metrics
38+
protocol: TCP
39+
- name: grpc
40+
port: 9095
41+
targetPort: grpc
42+
protocol: TCP
43+
{{- with (dig "appProtocol" "grpc" $component.service.appProtocol.grpc $component) }}
44+
appProtocol: {{ . }}
45+
{{- end }}
46+
- name: grpclb
47+
port: 9096
48+
targetPort: grpc
49+
protocol: TCP
50+
{{- with (dig "appProtocol" "grpc" $component.service.appProtocol.grpc $component) }}
51+
appProtocol: {{ . }}
52+
{{- end }}
53+
selector:
54+
{{ include "loki.selectorLabels" . | nindent 4 }}
55+
app.kubernetes.io/component: {{ $target | quote }}
56+
{{- with (coalesce $component.trafficDistribution $component.service.trafficDistribution .Values.defaults.service.trafficDistribution .Values.loki.service.trafficDistribution) }}
57+
trafficDistribution: {{ . }}
58+
{{- end }}
59+
{{- with $component.service.sessionAffinity }}
60+
sessionAffinity: {{ . }}
61+
{{- end }}
62+
{{- with $component.service.sessionAffinityConfig }}
63+
sessionAffinityConfig:
64+
{{- toYaml . | nindent 4 }}
65+
{{- end }}
66+
---
67+
apiVersion: v1
68+
kind: Service
69+
metadata:
70+
{{ if $headlessName }}
71+
name: {{ $headlessName }}
72+
{{ else }}
73+
name: "{{ include "loki.fullname" . }}-{{ $target }}-headless"
74+
{{- end }}
75+
namespace: {{ include "loki.namespace" . }}
76+
labels:
77+
{{- include "loki.labels" . | nindent 4 }}
78+
app.kubernetes.io/component: {{ $target | quote }}
79+
prometheus.io/service-monitor: "false"
80+
variant: headless
81+
{{- with (mergeOverwrite (dict) .Values.defaults.service.labels ($component.serviceLabels | default dict) $component.service.labels) }}
82+
{{- toYaml . | nindent 4 }}
83+
{{- end }}
84+
annotations:
85+
{{- with (mergeOverwrite (dict) .Values.loki.serviceAnnotations .Values.defaults.service.annotations ($component.serviceAnnotations | default dict) $component.service.annotations) }}
86+
{{- toYaml . | nindent 4 }}
87+
{{- end }}
88+
spec:
89+
clusterIP: None
90+
type: ClusterIP
91+
publishNotReadyAddresses: true
92+
ports:
93+
- name: http-metrics
94+
port: 3100
95+
targetPort: http-metrics
96+
protocol: TCP
97+
- name: grpc
98+
port: 9095
99+
targetPort: grpc
100+
protocol: TCP
101+
{{- with (dig "appProtocol" "grpc" $component.service.appProtocol.grpc $component) }}
102+
appProtocol: {{ . }}
103+
{{- end }}
104+
- name: grpclb
105+
port: 9096
106+
targetPort: grpc
107+
protocol: TCP
108+
{{- with (dig "appProtocol" "grpc" $component.service.appProtocol.grpc $component) }}
109+
appProtocol: {{ . }}
110+
{{- end }}
111+
selector:
112+
{{ include "loki.selectorLabels" . | nindent 4 }}
113+
app.kubernetes.io/component: {{ $target | quote }}
114+
{{- end }}
115+
{{- end }}

charts/loki/templates/bloom-builder/service-bloom-builder-headless.yaml

Lines changed: 0 additions & 46 deletions
This file was deleted.

charts/loki/templates/bloom-builder/service-bloom-builder.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
2+
{{- if (and $isDistributed (gt (int .Values.bloomBuilder.replicas) 0)) -}}
3+
{{- include "loki.service" (dict "target" "bloom-builder" "component" .Values.bloomBuilder "ctx" .) }}
4+
{{- end -}}

charts/loki/templates/bloom-gateway/service-bloom-gateway-headless.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
2+
{{- if and $isDistributed (gt (int .Values.bloomGateway.replicas) 0) -}}
3+
{{- include "loki.service" (dict "target" "bloom-gateway" "component" .Values.bloomGateway "ctx" .) }}
4+
{{- end -}}

charts/loki/templates/bloom-planner/service-bloom-planner-headless.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
2+
{{- if (and $isDistributed (gt (int .Values.bloomPlanner.replicas) 0)) -}}
3+
{{- include "loki.service" (dict "target" "bloom-planner" "component" .Values.bloomPlanner "ctx" .) }}
4+
{{- end -}}

charts/loki/templates/chunks-cache/service-chunks-cache-headless.yaml renamed to charts/loki/templates/chunks-cache/service.yaml

File renamed without changes.

0 commit comments

Comments
 (0)