cleanup-cronjob.yaml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. ################################
  18. ## Airflow Cleanup Pods CronJob
  19. #################################
  20. {{- if .Values.cleanup.enabled }}
  21. {{- $nodeSelector := or .Values.cleanup.nodeSelector .Values.nodeSelector }}
  22. {{- $affinity := or .Values.cleanup.affinity .Values.affinity }}
  23. {{- $tolerations := or .Values.cleanup.tolerations .Values.tolerations }}
  24. {{- $topologySpreadConstraints := or .Values.cleanup.topologySpreadConstraints .Values.topologySpreadConstraints }}
  25. {{- $securityContext := include "airflowSecurityContext" (list . .Values.cleanup) }}
  26. {{- if semverCompare ">= 1.21.x" (include "kubeVersion" .) }}
  27. apiVersion: batch/v1
  28. {{- else }}
  29. apiVersion: batch/v1beta1
  30. {{- end }}
  31. kind: CronJob
  32. metadata:
  33. name: {{ .Release.Name }}-cleanup
  34. labels:
  35. tier: airflow
  36. component: airflow-cleanup-pods
  37. chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  38. release: {{ .Release.Name }}
  39. heritage: {{ .Release.Service }}
  40. {{- with .Values.labels }}
  41. {{ toYaml . | indent 4 }}
  42. {{- end }}
  43. spec:
  44. schedule: "{{ .Values.cleanup.schedule }}"
  45. # 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
  46. concurrencyPolicy: Forbid
  47. jobTemplate:
  48. spec:
  49. backoffLimit: 1
  50. template:
  51. metadata:
  52. labels:
  53. tier: airflow
  54. component: airflow-cleanup-pods
  55. release: {{ .Release.Name }}
  56. {{- with .Values.labels }}
  57. {{ toYaml . | indent 12 }}
  58. {{- end }}
  59. annotations:
  60. sidecar.istio.io/inject: "false"
  61. {{- if .Values.airflowPodAnnotations }}
  62. {{- toYaml .Values.airflowPodAnnotations | nindent 12 }}
  63. {{- end }}
  64. {{- if .Values.cleanup.podAnnotations }}
  65. {{- toYaml .Values.cleanup.podAnnotations | nindent 12 }}
  66. {{- end }}
  67. spec:
  68. restartPolicy: Never
  69. nodeSelector:
  70. {{ toYaml $nodeSelector | indent 12 }}
  71. affinity:
  72. {{ toYaml $affinity | indent 12 }}
  73. tolerations:
  74. {{ toYaml $tolerations | indent 12 }}
  75. topologySpreadConstraints:
  76. {{ toYaml $topologySpreadConstraints | indent 12 }}
  77. serviceAccountName: {{ include "cleanup.serviceAccountName" . }}
  78. {{- if or .Values.registry.secretName .Values.registry.connection }}
  79. imagePullSecrets:
  80. - name: {{ template "registry_secret" . }}
  81. {{- end }}
  82. securityContext: {{ $securityContext | nindent 12 }}
  83. containers:
  84. - name: airflow-cleanup-pods
  85. image: {{ template "airflow_image" . }}
  86. imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
  87. {{- if .Values.cleanup.command }}
  88. command: {{ tpl (toYaml .Values.cleanup.command) . | nindent 16 }}
  89. {{- end }}
  90. {{- if .Values.cleanup.args }}
  91. args: {{ tpl (toYaml .Values.cleanup.args) . | nindent 16 }}
  92. {{- end }}
  93. env:
  94. {{- include "standard_airflow_environment" . | indent 12 }}
  95. volumeMounts:
  96. - name: config
  97. mountPath: {{ template "airflow_config_path" . }}
  98. subPath: airflow.cfg
  99. readOnly: true
  100. resources:
  101. {{ toYaml .Values.cleanup.resources | indent 16 }}
  102. volumes:
  103. - name: config
  104. configMap:
  105. name: {{ template "airflow_config" . }}
  106. {{- end }}