jscheffl commented on code in PR #58155:
URL: https://github.com/apache/airflow/pull/58155#discussion_r2519789548
##########
chart/values.schema.json:
##########
@@ -8952,6 +8952,325 @@
}
}
},
+ "databaseCleanup": {
+ "description": "This runs as a CronJob to cleanup the database
after the retention period.",
+ "type": "object",
+ "x-docsSection": "Jobs",
+ "additionalProperties": false,
+ "properties": {
+ "enabled": {
+ "description": "Enable database cleanup.",
+ "type": "boolean",
+ "default": false
+ },
+ "schedule": {
+ "description": "Database cleanup schedule (templated).",
+ "type": "string",
+ "default": "0 0 * * 0"
+ },
+ "retentionDays": {
+ "description": "Number of days to retain records in the
metadata database.",
+ "type": "integer",
+ "default": 90
+ },
+ "command": {
+ "description": "Command to use when running the database
cleanup cronjob (templated).",
+ "type": [
+ "array",
+ "null"
+ ],
+ "items": {
+ "type": "string"
+ },
+ "default": null
Review Comment:
Would not `"bash"` go into here from args below?
##########
chart/templates/database-cleanup/database-cleanup-cronjob.yaml:
##########
@@ -0,0 +1,121 @@
+{{/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/}}
+
+################################
+## Airflow Database Cleanup CronJob
+#################################
+{{- if .Values.databaseCleanup.enabled }}
+{{- $nodeSelector := or .Values.databaseCleanup.nodeSelector
.Values.nodeSelector }}
+{{- $affinity := or .Values.databaseCleanup.affinity .Values.affinity }}
+{{- $tolerations := or .Values.databaseCleanup.tolerations .Values.tolerations
}}
+{{- $topologySpreadConstraints := or
.Values.databaseCleanup.topologySpreadConstraints
.Values.topologySpreadConstraints }}
+{{- $securityContext := include "airflowPodSecurityContext" (list .
.Values.databaseCleanup) }}
+{{- $containerSecurityContext := include "containerSecurityContext" (list .
.Values.databaseCleanup) }}
+apiVersion: batch/v1
+kind: CronJob
+metadata:
+ name: {{ include "airflow.fullname" . }}-database-cleanup
+ labels:
+ tier: airflow
+ component: airflow-database-cleanup-pods
+ release: {{ .Release.Name }}
+ chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+ heritage: {{ .Release.Service }}
+ {{- with .Values.labels }}
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+ {{- with .Values.databaseCleanup.jobAnnotations }}
+ annotations: {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ schedule: "{{ tpl .Values.databaseCleanup.schedule . }}"
+ # The cron job does not allow concurrent runs; if it is time for a new job
run and the previous job run hasn't finished yet, the cron job skips the new
job run
+ concurrencyPolicy: Forbid
+ {{- if not ( eq .Values.databaseCleanup.failedJobsHistoryLimit nil) }}
+ failedJobsHistoryLimit: {{ .Values.databaseCleanup.failedJobsHistoryLimit }}
+ {{- end }}
+ {{- if not (eq .Values.databaseCleanup.successfulJobsHistoryLimit nil) }}
+ successfulJobsHistoryLimit: {{
.Values.databaseCleanup.successfulJobsHistoryLimit }}
+ {{- end }}
+ jobTemplate:
+ spec:
+ backoffLimit: 1
+ template:
+ metadata:
+ labels:
+ tier: airflow
+ component: airflow-database-cleanup-pods
+ release: {{ .Release.Name }}
+ {{- if or (.Values.labels) (.Values.databaseCleanup.labels) }}
+ {{- mustMerge .Values.databaseCleanup.labels .Values.labels |
toYaml | nindent 12 }}
+ {{- end }}
+ annotations:
+ sidecar.istio.io/inject: "false"
+ {{- if .Values.airflowPodAnnotations }}
+ {{- toYaml .Values.airflowPodAnnotations | nindent 12 }}
+ {{- end }}
+ {{- if .Values.databaseCleanup.podAnnotations }}
+ {{- toYaml .Values.databaseCleanup.podAnnotations | nindent 12 }}
+ {{- end }}
+ spec:
+ restartPolicy: Never
+ {{- if .Values.databaseCleanup.priorityClassName }}
+ priorityClassName: {{ .Values.databaseCleanup.priorityClassName }}
+ {{- end }}
+ nodeSelector: {{- toYaml $nodeSelector | nindent 12 }}
+ affinity: {{- toYaml $affinity | nindent 12 }}
+ {{- if .Values.schedulerName }}
+ schedulerName: {{ .Values.schedulerName }}
+ {{- end }}
+ tolerations: {{- toYaml $tolerations | nindent 12 }}
+ topologySpreadConstraints: {{- toYaml $topologySpreadConstraints |
nindent 12 }}
+ serviceAccountName: {{ include "databaseCleanup.serviceAccountName"
. }}
+ {{- if or .Values.registry.secretName .Values.registry.connection }}
+ imagePullSecrets:
+ - name: {{ template "registry_secret" . }}
+ {{- end }}
+ securityContext: {{ $securityContext | nindent 12 }}
+ containers:
+ - name: airflow-database-cleanup
+ image: {{ template "airflow_image" . }}
+ imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
+ securityContext: {{ $containerSecurityContext | nindent 16 }}
+ {{- if .Values.databaseCleanup.command }}
+ command: {{ tpl (toYaml .Values.databaseCleanup.command) . |
nindent 16 }}
+ {{- end }}
+ {{- if .Values.databaseCleanup.args }}
+ args: {{ tpl (toYaml .Values.databaseCleanup.args) . | nindent
16 }}
+ {{- end }}
Review Comment:
I _think_ the conditional construct does not make very much sense. Calling
the container without args or command would not make a successful job to
execute.
I'd propose if command/args not given then it should use a fallback or not
rendering the cron job at all.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]