forked from memgraph/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_helpers.tpl
More file actions
354 lines (322 loc) · 11.1 KB
/
Copy path_helpers.tpl
File metadata and controls
354 lines (322 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
{{/* Full name of the application */}}
{{- define "memgraph.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end -}}
{{- end -}}
{{/* Define the chart version and app version */}}
{{- define "memgraph.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end -}}
{{/* Define the name of the application */}}
{{- define "memgraph.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end -}}
{{/* Common labels */}}
{{- define "memgraph.labels" -}}
app.kubernetes.io/name: {{ include "memgraph.name" . }}
helm.sh/chart: {{ include "memgraph.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "memgraph.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "memgraph.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create the name for mg-exporter resources.
*/}}
{{- define "memgraph.mgExporterName" -}}
{{- printf "%s-mg-exporter" (include "memgraph.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}
{{/*
Create the config map name for mg-exporter resources.
*/}}
{{- define "memgraph.mgExporterConfigName" -}}
{{- printf "%s-config" (include "memgraph.mgExporterName" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}
{{- define "container.data.readinessProbe" -}}
{{- $p := .Values.container.data.readinessProbe -}}
readinessProbe:
tcpSocket:
port: {{ .Values.ports.boltPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{- define "container.data.livenessProbe" -}}
{{- $p := .Values.container.data.livenessProbe -}}
livenessProbe:
tcpSocket:
port: {{ .Values.ports.boltPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{- define "container.data.startupProbe" -}}
{{- $p := .Values.container.data.startupProbe -}}
startupProbe:
tcpSocket:
port: {{ .Values.ports.boltPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{- define "container.coordinators.readinessProbe" -}}
{{- $p := .Values.container.coordinators.readinessProbe -}}
readinessProbe:
tcpSocket:
port: {{ .Values.ports.coordinatorPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{- define "container.coordinators.livenessProbe" -}}
{{- $p := .Values.container.coordinators.livenessProbe -}}
livenessProbe:
tcpSocket:
port: {{ .Values.ports.coordinatorPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{- define "memgraph.commonLoggingArgs" -}}
{{- $logging := .logging -}}
{{- if not $logging.log_level -}}{{- fail (printf "%s.log_level must not be empty" .path) -}}{{- end -}}
{{- if not (kindIs "bool" $logging.also_log_to_stderr) -}}{{- fail (printf "%s.also_log_to_stderr must be a boolean (true or false)" .path) -}}{{- end -}}
- "--log-level={{ $logging.log_level }}"
{{- if $logging.also_log_to_stderr }}
- "--also-log-to-stderr"
{{- end }}
- "--log-file={{ $logging.log_file }}"
{{- end }}
{{- define "container.coordinators.startupProbe" -}}
{{- $p := .Values.container.coordinators.startupProbe -}}
startupProbe:
tcpSocket:
port: {{ .Values.ports.coordinatorPort }}
failureThreshold: {{ $p.failureThreshold }}
timeoutSeconds: {{ $p.timeoutSeconds }}
periodSeconds: {{ $p.periodSeconds }}
{{- end }}
{{/*
Core dump uploader sidecar container.
Expects a dict with keys: volumeName, mountPath, values (coreDumpUploader values block).
*/}}
{{- define "memgraph.coreDumpUploader" -}}
- name: core-dump-uploader
image: "{{ .values.image.repository }}:{{ .values.image.tag }}"
imagePullPolicy: {{ .values.image.pullPolicy }}
command: ["/bin/sh", "-c"]
args:
- |
WATCH_DIR="$WATCH_DIR"
UPLOADED="/tmp/uploaded_files"
touch "$UPLOADED"
echo "Core dump uploader started. Watching $WATCH_DIR every ${POLL_INTERVAL}s."
while true; do
for f in "$WATCH_DIR"/core.*; do
[ -e "$f" ] || continue
fname=$(basename "$f")
if grep -qxF "$fname" "$UPLOADED"; then
continue
fi
echo "New core dump detected: $fname. Waiting 5s for write to complete..."
sleep 5
echo "Uploading $fname to s3://${S3_BUCKET}/${S3_PREFIX}/${HOSTNAME}/${fname}"
aws s3 cp "$f" "s3://${S3_BUCKET}/${S3_PREFIX}/${HOSTNAME}/${fname}" --region "$AWS_REGION"
if [ $? -eq 0 ]; then
echo "$fname" >> "$UPLOADED"
echo "Upload complete: $fname"
else
echo "Upload failed: $fname. Will retry next cycle."
fi
done
sleep "$POLL_INTERVAL"
done
env:
- name: WATCH_DIR
value: {{ .mountPath | quote }}
- name: S3_BUCKET
value: {{ .values.s3BucketName | quote }}
- name: S3_PREFIX
value: {{ .values.s3Prefix | quote }}
- name: AWS_REGION
value: {{ .values.awsRegion | quote }}
- name: POLL_INTERVAL
value: {{ .values.pollIntervalSeconds | quote }}
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{ .values.secretName }}
key: {{ .values.accessKeySecretKey }}
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .values.secretName }}
key: {{ .values.secretAccessKeySecretKey }}
volumeMounts:
- name: {{ .volumeName }}
mountPath: {{ .mountPath }}
readOnly: true
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
readOnlyRootFilesystem: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
{{- with .values.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{/*
Vector sidecar for log export (VictoriaLogs/Loki).
Expects dict with: ctx (root context), role ("data" or "coordinator").
*/}}
{{- define "memgraph.vectorSidecar" -}}
{{- $v := .ctx.Values.vectorRemote }}
- name: memgraph-vector
image: "{{ $v.image.repository }}:{{ $v.image.tag }}"
imagePullPolicy: {{ $v.image.pullPolicy }}
command: ["/bin/sh", "-ec"]
args:
- |
# Wait for Memgraph to open the log websocket so Vector does not exit with connection errors.
echo "Waiting for Memgraph monitoring port {{ $v.websocketPort }}..."
max_wait_seconds=120
elapsed=0
until bash -c "exec 3<>/dev/tcp/127.0.0.1/{{ $v.websocketPort }}" >/dev/null 2>&1; do
if [ "$elapsed" -ge "$max_wait_seconds" ]; then
echo "Timed out waiting for Memgraph monitoring port {{ $v.websocketPort }} after ${max_wait_seconds}s" >&2
exit 1
fi
sleep 2
elapsed=$((elapsed + 2))
done
cat > /tmp/vector.yaml << VECEOF
data_dir: /tmp/vector-data
sources:
memgraph_logs:
type: websocket
uri: "ws://127.0.0.1:{{ $v.websocketPort }}"
transforms:
enrich:
type: remap
inputs: [memgraph_logs]
source: |
normalized_level = ""
if exists(.message) && is_string(.message) {
parsed, err = parse_json(.message)
if err == null && is_object(parsed) {
. = merge!(., parsed)
}
}
if exists(.level) {
normalized_level = downcase(to_string!(.level))
} else if exists(.severity) {
normalized_level = downcase(to_string!(.severity))
}
if normalized_level == "warning" {
normalized_level = "warn"
} else if normalized_level == "critical" {
normalized_level = "fatal"
}
if normalized_level == "" {
normalized_level = "unknown"
}
.level = normalized_level
if !exists(._msg) {
if exists(.message) {
._msg = to_string!(.message)
} else if exists(.msg) {
._msg = to_string!(.msg)
} else if exists(.log) {
._msg = to_string!(.log)
} else {
._msg = encode_json(.)
}
}
.message = ._msg
.app = "memgraph"
.job = "memgraph"
.role = get_env_var!("ROLE")
.namespace = get_env_var!("POD_NAMESPACE")
.pod = get_env_var!("POD_NAME")
.cluster_id = get_env_var!("CLUSTER_ID")
.service_name = get_env_var!("SERVICE_NAME")
.cluster_env = get_env_var!("CLUSTER_ENV")
sinks:
logs:
type: loki
inputs: [enrich]
endpoint: "{{ required "vectorRemote.logsEndpoint is required when vectorRemote is enabled" $v.logsEndpoint }}"
healthcheck:
enabled: false
{{- if $v.auth.secretName }}
auth:
strategy: basic
user: "{{ "$" }}{{ "{MONITORING_USERNAME}" }}"
password: "{{ "$" }}{{ "{MONITORING_PASSWORD}" }}"
{{- end }}
encoding:
codec: text
labels:
app: "{{ "{{ app }}" }}"
job: "{{ "{{ job }}" }}"
role: "{{ "{{ role }}" }}"
namespace: "{{ "{{ namespace }}" }}"
pod: "{{ "{{ pod }}" }}"
level: "{{ "{{ level }}" }}"
cluster_id: "{{ "{{ cluster_id }}" }}"
service_name: "{{ "{{ service_name }}" }}"
cluster_env: "{{ "{{ cluster_env }}" }}"
remove_label_fields: true
VECEOF
mkdir -p /tmp/vector-data
exec vector -c /tmp/vector.yaml
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if $v.auth.secretName }}
- name: MONITORING_USERNAME
valueFrom:
secretKeyRef:
name: {{ $v.auth.secretName }}
key: {{ $v.auth.usernameKey }}
- name: MONITORING_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $v.auth.secretName }}
key: {{ $v.auth.passwordKey }}
{{- end }}
- name: ROLE
value: {{ .role | quote }}
- name: CLUSTER_ID
value: {{ $v.extraLabels.cluster_id | default "" | quote }}
- name: SERVICE_NAME
value: {{ $v.extraLabels.service_name | default "" | quote }}
- name: CLUSTER_ENV
value: {{ $v.extraLabels.cluster_env | default "" | quote }}
{{- with $v.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}