# 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 Cleanup Pods CronJob ################################# {{- if .Values.cleanup.enabled }} {{- $nodeSelector := or .Values.cleanup.nodeSelector .Values.nodeSelector }} {{- $affinity := or .Values.cleanup.affinity .Values.affinity }} {{- $tolerations := or .Values.cleanup.tolerations .Values.tolerations }} {{- $topologySpreadConstraints := or .Values.cleanup.topologySpreadConstraints .Values.topologySpreadConstraints }} {{- $securityContext := include "airflowSecurityContext" (list . .Values.cleanup) }} {{- if semverCompare ">= 1.21.x" (include "kubeVersion" .) }} apiVersion: batch/v1 {{- else }} apiVersion: batch/v1beta1 {{- end }} kind: CronJob metadata: name: {{ .Release.Name }}-cleanup labels: tier: airflow component: airflow-cleanup-pods chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: {{ .Release.Name }} heritage: {{ .Release.Service }} {{- with .Values.labels }} {{ toYaml . | indent 4 }} {{- end }} spec: schedule: "{{ .Values.cleanup.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 jobTemplate: spec: backoffLimit: 1 template: metadata: labels: tier: airflow component: airflow-cleanup-pods release: {{ .Release.Name }} {{- with .Values.labels }} {{ toYaml . | indent 12 }} {{- end }} annotations: sidecar.istio.io/inject: "false" {{- if .Values.airflowPodAnnotations }} {{- toYaml .Values.airflowPodAnnotations | nindent 12 }} {{- end }} {{- if .Values.cleanup.podAnnotations }} {{- toYaml .Values.cleanup.podAnnotations | nindent 12 }} {{- end }} spec: restartPolicy: Never nodeSelector: {{ toYaml $nodeSelector | indent 12 }} affinity: {{ toYaml $affinity | indent 12 }} tolerations: {{ toYaml $tolerations | indent 12 }} topologySpreadConstraints: {{ toYaml $topologySpreadConstraints | indent 12 }} serviceAccountName: {{ include "cleanup.serviceAccountName" . }} {{- if or .Values.registry.secretName .Values.registry.connection }} imagePullSecrets: - name: {{ template "registry_secret" . }} {{- end }} securityContext: {{ $securityContext | nindent 12 }} containers: - name: airflow-cleanup-pods image: {{ template "airflow_image" . }} imagePullPolicy: {{ .Values.images.airflow.pullPolicy }} {{- if .Values.cleanup.command }} command: {{ tpl (toYaml .Values.cleanup.command) . | nindent 16 }} {{- end }} {{- if .Values.cleanup.args }} args: {{ tpl (toYaml .Values.cleanup.args) . | nindent 16 }} {{- end }} env: {{- include "standard_airflow_environment" . | indent 12 }} volumeMounts: - name: config mountPath: {{ template "airflow_config_path" . }} subPath: airflow.cfg readOnly: true resources: {{ toYaml .Values.cleanup.resources | indent 16 }} volumes: - name: config configMap: name: {{ template "airflow_config" . }} {{- end }}