-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Add database cleanup cronjob to clean old records #58155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
52da082
Database cleanup cron job
ronaldorcampos e987173
Merge branch 'main' into feature/cleanup
ronaldorcampos cdbce3e
fix scc
ronaldorcampos 8fc7884
fix tests
ronaldorcampos 781f4e5
linting
ronaldorcampos 929ead4
Merge branch 'main' into feature/cleanup
ronaldorcampos baa8d50
linting
ronaldorcampos e02c886
Database cleanup cron job
ronaldorcampos c96345e
fix scc
ronaldorcampos 3c54d83
fix tests
ronaldorcampos cda7021
linting
ronaldorcampos 8281c58
linting
ronaldorcampos 30abc97
Merge remote-tracking branch 'origin/feature/cleanup' into feature/cl…
ronaldorcampos d647341
review
ronaldorcampos 42bac90
fix tests and typing
ronaldorcampos cb30675
comment
ronaldorcampos a01d927
Apply suggestions from code review
ronaldorcampos 95b1892
Update helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup_…
ronaldorcampos e410ad3
Update helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup_…
ronaldorcampos 178b242
Update chart/templates/database-cleanup/database-cleanup-cronjob.yaml
ronaldorcampos fdc6642
Merge branch 'main' into feature/cleanup
ronaldorcampos 5a3e6bb
fix
ronaldorcampos 7a0673f
lint
ronaldorcampos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
chart/templates/database-cleanup/database-cleanup-cronjob.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| {{/* | ||
| 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 and .Values.databaseCleanup.enabled (or .Values.databaseCleanup.command .Values.databaseCleanup.args) }} | ||
| {{- $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: database-cleanup | ||
| 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: database-cleanup | ||
| release: {{ .Release.Name }} | ||
| {{- if or (.Values.labels) (.Values.databaseCleanup.labels) }} | ||
| {{- mustMerge .Values.databaseCleanup.labels .Values.labels | toYaml | nindent 12 }} | ||
| {{- end }} | ||
| annotations: | ||
| {{- 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: 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 }} | ||
| env: | ||
| {{- include "standard_airflow_environment" . | indent 12 }} | ||
| {{- include "container_extra_envs" (list . .Values.databaseCleanup.env) | indent 12 }} | ||
| volumeMounts: | ||
| {{- include "airflow_config_mount" . | nindent 16 }} | ||
| {{- if .Values.volumeMounts }} | ||
| {{- toYaml .Values.volumeMounts | nindent 16 }} | ||
| {{- end }} | ||
| resources: {{- toYaml .Values.databaseCleanup.resources | nindent 16 }} | ||
| volumes: | ||
| - name: config | ||
| configMap: | ||
| name: {{ template "airflow_config" . }} | ||
| {{- if .Values.volumes }} | ||
| {{- toYaml .Values.volumes | nindent 12 }} | ||
| {{- end }} | ||
| {{- end }} | ||
41 changes: 41 additions & 0 deletions
41
chart/templates/database-cleanup/database-cleanup-serviceaccount.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {{/* | ||
| 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 ServiceAccount | ||
| ################################# | ||
| {{- if and .Values.databaseCleanup.serviceAccount.create .Values.databaseCleanup.enabled }} | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| automountServiceAccountToken: {{ .Values.databaseCleanup.serviceAccount.automountServiceAccountToken }} | ||
| metadata: | ||
| name: {{ include "databaseCleanup.serviceAccountName" . }} | ||
| labels: | ||
| tier: airflow | ||
| component: database-cleanup | ||
| release: {{ .Release.Name }} | ||
| chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" | ||
| heritage: {{ .Release.Service }} | ||
| {{- if or (.Values.labels) (.Values.databaseCleanup.labels) }} | ||
| {{- mustMerge .Values.databaseCleanup.labels .Values.labels | toYaml | nindent 4 }} | ||
| {{- end }} | ||
| {{- with .Values.databaseCleanup.serviceAccount.annotations }} | ||
| annotations: {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| {{/* | ||
| 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 Role | ||
| ################################# | ||
| {{- if and .Values.rbac.create .Values.databaseCleanup.enabled }} | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: {{ include "airflow.fullname" . }}-database-cleanup-role | ||
| labels: | ||
| tier: airflow | ||
| release: {{ .Release.Name }} | ||
| chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" | ||
| heritage: {{ .Release.Service }} | ||
| {{- with .Values.labels }} | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| rules: [] | ||
| {{- end }} |
44 changes: 44 additions & 0 deletions
44
chart/templates/rbac/pod-database-cleanup-rolebinding.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| {{/* | ||
| 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 Role Binding | ||
| ################################# | ||
| {{- if and .Values.rbac.create .Values.databaseCleanup.enabled }} | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: {{ include "airflow.fullname" . }}-database-cleanup-rolebinding | ||
| labels: | ||
| tier: airflow | ||
| release: {{ .Release.Name }} | ||
| chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" | ||
| heritage: {{ .Release.Service }} | ||
| {{- with .Values.labels }} | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: {{ include "airflow.fullname" . }}-database-cleanup-role | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: {{ include "databaseCleanup.serviceAccountName" . }} | ||
| namespace: "{{ .Release.Namespace }}" | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.