Skip to content

Commit 944f130

Browse files
authored
Add event log trim cron job (#28)
feat: add event log trim cron job
1 parent c9f8653 commit 944f130

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

templates/event-log-trim/cronjob.yaml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{{- if .Values.eventLogTrim.enabled }}
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: {{ include "jitsu.fullname" . }}-event-log-trim-{{ sha1sum (toJson .Values) | substr 0 8 }}
6+
labels:
7+
{{- include "jitsu.labels" . | nindent 4 }}
8+
{{- with .Values.eventLogTrim.jobAnnotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
schedule: {{ .Values.eventLogTrim.schedule | quote }}
14+
jobTemplate:
15+
spec:
16+
backoffLimit: 1
17+
template:
18+
metadata:
19+
labels:
20+
{{- include "jitsu.selectorLabels" . | nindent 12 }}
21+
{{- with (merge (deepCopy .Values.eventLogTrim.podAnnotations) .Values.global.podAnnotations) }}
22+
annotations:
23+
{{- toYaml . | nindent 12 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 12 }}
29+
{{- end }}
30+
restartPolicy: "Never"
31+
serviceAccountName: {{ include "jitsu.serviceAccountName" . }}
32+
{{- with (.Values.eventLogTrim.podSecurityContext | default .Values.global.podSecurityContext) }}
33+
securityContext:
34+
{{- toYaml . | nindent 12 }}
35+
{{- end }}
36+
initContainers:
37+
{{- if .Values.tokenGenerator.enabled }}
38+
- name: wait-for-tokens
39+
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
40+
securityContext:
41+
{{- toYaml . | nindent 16 }}
42+
{{- end }}
43+
image: ghcr.io/groundnuty/k8s-wait-for:v2.0
44+
args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"]
45+
{{- end }}
46+
{{- if .Values.console.enabled }}
47+
- name: wait-for-console
48+
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
49+
securityContext:
50+
{{- toYaml . | nindent 16 }}
51+
{{- end }}
52+
image: ghcr.io/groundnuty/k8s-wait-for:v2.0
53+
args: ["service", "{{ .Release.Name }}-console"]
54+
{{- end }}
55+
containers:
56+
- name: {{ .Chart.Name }}
57+
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
58+
securityContext:
59+
{{- toYaml . | nindent 16 }}
60+
{{- end }}
61+
image: "{{ .Values.eventLogTrim.image.repository }}:{{ .Values.eventLogTrim.image.tag | default .Chart.AppVersion }}"
62+
imagePullPolicy: {{ .Values.eventLogTrim.image.pullPolicy }}
63+
command:
64+
- sh
65+
- -c
66+
- >
67+
curl --silent --output /dev/null --show-error -H "Authorization: Bearer $CONSOLE_AUTH_TOKEN" "$CONSOLE_ENDPOINT"
68+
{{- if .Values.eventLogTrim.envFrom }}
69+
envFrom:
70+
{{- toYaml .Values.eventLogTrim.envFrom | nindent 16 }}
71+
{{- end }}
72+
env:
73+
{{- if and .Values.config.enabled .Values.eventLogTrim.config.enabled }}
74+
- name: CONSOLE_ENDPOINT
75+
value: {{ printf "http://%s-console:%d/api/admin/events-log-trim"
76+
(include "jitsu.fullname" .)
77+
(int $.Values.console.service.port)
78+
}}
79+
{{- if .Values.eventLogTrim.config.consoleAuthTokenFrom }}
80+
- name: CONSOLE_AUTH_TOKEN
81+
valueFrom:
82+
{{- toYaml .Values.eventLogTrim.config.consoleAuthTokenFrom | nindent 20 }}
83+
{{- else }}
84+
{{- if and (not .Values.eventLogTrim.config.consoleAuthToken) .Values.console.enabled .Values.tokenGenerator.enabled }}
85+
- name: CONSOLE_AUTH_TOKEN
86+
valueFrom:
87+
secretKeyRef:
88+
name: {{ include "jitsu.fullname" . }}-tokens
89+
key: consoleAuthToken
90+
{{- end }}
91+
{{- with .Values.eventLogTrim.config.consoleAuthToken }}
92+
- name: CONSOLE_AUTH_TOKEN
93+
value: {{ .Values.eventLogTrim.config.consoleAuthToken | quote }}
94+
{{- end }}
95+
{{- end }}
96+
{{- end }}
97+
{{- with .Values.eventLogTrim.env }}
98+
{{- toYaml . | nindent 16 }}
99+
{{- end }}
100+
{{- with (.Values.eventLogTrim.nodeSelector | default .Values.global.nodeSelector) }}
101+
nodeSelector:
102+
{{- toYaml . | nindent 12 }}
103+
{{- end }}
104+
{{- with (.Values.eventLogTrim.affinity | default .Values.global.affinity) }}
105+
affinity:
106+
{{- toYaml . | nindent 12 }}
107+
{{- end }}
108+
{{- with (.Values.eventLogTrim.tolerations | default .Values.global.affinity) }}
109+
tolerations:
110+
{{- toYaml . | nindent 12 }}
111+
{{- end }}
112+
{{- end }}

values.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,35 @@ eventLogInit:
870870
tolerations: []
871871
affinity: {}
872872

873+
eventLogTrim:
874+
enabled: true
875+
schedule: '0 0 * * *'
876+
config:
877+
# Set to false to disable config abstractions in order to configure manually.
878+
enabled: true
879+
880+
# Leave empty to configure automatically
881+
consoleEndpoint: ""
882+
883+
# Configured automatically when using the token generator
884+
consoleAuthToken: ""
885+
consoleAuthTokenFrom: {}
886+
image:
887+
repository: jitsucom/console
888+
pullPolicy: IfNotPresent
889+
tag: ""
890+
restartPolicy: Never
891+
env: []
892+
envFrom: []
893+
jobAnnotations: {}
894+
podAnnotations: {}
895+
podSecurityContext: {}
896+
securityContext: {}
897+
resources: {}
898+
nodeSelector: {}
899+
tolerations: []
900+
affinity: {}
901+
873902
imagePullSecrets: []
874903

875904
serviceAccount:

0 commit comments

Comments
 (0)