Skip to content

Commit

Permalink
Add event log trim cron job (#28)
Browse files Browse the repository at this point in the history
feat: add event log trim cron job
  • Loading branch information
echozio authored May 28, 2024
1 parent c9f8653 commit 944f130
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
112 changes: 112 additions & 0 deletions templates/event-log-trim/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{{- if .Values.eventLogTrim.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "jitsu.fullname" . }}-event-log-trim-{{ sha1sum (toJson .Values) | substr 0 8 }}
labels:
{{- include "jitsu.labels" . | nindent 4 }}
{{- with .Values.eventLogTrim.jobAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
schedule: {{ .Values.eventLogTrim.schedule | quote }}
jobTemplate:
spec:
backoffLimit: 1
template:
metadata:
labels:
{{- include "jitsu.selectorLabels" . | nindent 12 }}
{{- with (merge (deepCopy .Values.eventLogTrim.podAnnotations) .Values.global.podAnnotations) }}
annotations:
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
restartPolicy: "Never"
serviceAccountName: {{ include "jitsu.serviceAccountName" . }}
{{- with (.Values.eventLogTrim.podSecurityContext | default .Values.global.podSecurityContext) }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
initContainers:
{{- if .Values.tokenGenerator.enabled }}
- name: wait-for-tokens
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
securityContext:
{{- toYaml . | nindent 16 }}
{{- end }}
image: ghcr.io/groundnuty/k8s-wait-for:v2.0
args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"]
{{- end }}
{{- if .Values.console.enabled }}
- name: wait-for-console
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
securityContext:
{{- toYaml . | nindent 16 }}
{{- end }}
image: ghcr.io/groundnuty/k8s-wait-for:v2.0
args: ["service", "{{ .Release.Name }}-console"]
{{- end }}
containers:
- name: {{ .Chart.Name }}
{{- with (.Values.eventLogTrim.securityContext | default .Values.global.securityContext) }}
securityContext:
{{- toYaml . | nindent 16 }}
{{- end }}
image: "{{ .Values.eventLogTrim.image.repository }}:{{ .Values.eventLogTrim.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.eventLogTrim.image.pullPolicy }}
command:
- sh
- -c
- >
curl --silent --output /dev/null --show-error -H "Authorization: Bearer $CONSOLE_AUTH_TOKEN" "$CONSOLE_ENDPOINT"
{{- if .Values.eventLogTrim.envFrom }}
envFrom:
{{- toYaml .Values.eventLogTrim.envFrom | nindent 16 }}
{{- end }}
env:
{{- if and .Values.config.enabled .Values.eventLogTrim.config.enabled }}
- name: CONSOLE_ENDPOINT
value: {{ printf "http://%s-console:%d/api/admin/events-log-trim"
(include "jitsu.fullname" .)
(int $.Values.console.service.port)
}}
{{- if .Values.eventLogTrim.config.consoleAuthTokenFrom }}
- name: CONSOLE_AUTH_TOKEN
valueFrom:
{{- toYaml .Values.eventLogTrim.config.consoleAuthTokenFrom | nindent 20 }}
{{- else }}
{{- if and (not .Values.eventLogTrim.config.consoleAuthToken) .Values.console.enabled .Values.tokenGenerator.enabled }}
- name: CONSOLE_AUTH_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "jitsu.fullname" . }}-tokens
key: consoleAuthToken
{{- end }}
{{- with .Values.eventLogTrim.config.consoleAuthToken }}
- name: CONSOLE_AUTH_TOKEN
value: {{ .Values.eventLogTrim.config.consoleAuthToken | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.eventLogTrim.env }}
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with (.Values.eventLogTrim.nodeSelector | default .Values.global.nodeSelector) }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with (.Values.eventLogTrim.affinity | default .Values.global.affinity) }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with (.Values.eventLogTrim.tolerations | default .Values.global.affinity) }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
29 changes: 29 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,35 @@ eventLogInit:
tolerations: []
affinity: {}

eventLogTrim:
enabled: true
schedule: '0 0 * * *'
config:
# Set to false to disable config abstractions in order to configure manually.
enabled: true

# Leave empty to configure automatically
consoleEndpoint: ""

# Configured automatically when using the token generator
consoleAuthToken: ""
consoleAuthTokenFrom: {}
image:
repository: jitsucom/console
pullPolicy: IfNotPresent
tag: ""
restartPolicy: Never
env: []
envFrom: []
jobAnnotations: {}
podAnnotations: {}
podSecurityContext: {}
securityContext: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}

imagePullSecrets: []

serviceAccount:
Expand Down

0 comments on commit 944f130

Please sign in to comment.