Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: cronjob to delete airflow logs #306

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions charts/deps/templates/cron-airflow-logs-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- $airflow_cleanup_enabled := and
(not .Values.airflow.scheduler.logCleanup.enabled)
(not (and
(hasKey .Values.airflow "workers")
(hasKey .Values.airflow.workers "logCleanup")
(.Values.airflow.workers.logCleanup.enabled | default false)
))
}}
{{- $airflow_persistence_enabled := and
.Values.airflow.enabled
.Values.airflow.logs.persistence.enabled
}}
{{- if and
(not $airflow_cleanup_enabled)
$airflow_persistence_enabled
.Values.airflow.logs.persistence.cleanup.enabled
}}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "airflow.fullname" . }}-airflow-logs-cleanup
labels:
app: {{ include "airflow.labels.app" . }}
component: logs-cleanup
chart: {{ include "airflow.labels.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
schedule: "{{ .Values.airflow.logs.persistence.cleanup.schedule }}"
jobTemplate:
spec:
template:
spec:
containers:
- name: logs-cleanup
image: busybox:latest
command:
- sh
- -c
- |
find /var/logs -type f -mtime +{{ .Values.airflow.logs.persistence.cleanup.retainDays }} -exec rm -f {} \;
volumeMounts:
- name: logs-data
mountPath: /var/logs
restartPolicy: OnFailure
volumes:
{{- include "airflow.volumes" (dict "Release" .Release "Values" .Values.airflow "extraPipPackages" (list) "extraVolumes" (list) "extraVolumeMounts" (list)) | trim | nindent 12 }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/deps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ airflow:
storageClass: ""
accessMode: ReadWriteMany
size: 1Gi
cleanup:
enabled: false
schedule: "0 4 * * *"
retainDays: 180
Loading