diff --git a/chart/templates/create-user-job.yaml b/chart/templates/create-user-job.yaml index d9e41b6171..27a0363a02 100644 --- a/chart/templates/create-user-job.yaml +++ b/chart/templates/create-user-job.yaml @@ -34,6 +34,7 @@ metadata: {{- end }} annotations: "helm.sh/hook": post-install + "helm.sh/hook-weight": "2" "helm.sh/hook-delete-policy": hook-succeeded spec: template: @@ -57,14 +58,6 @@ spec: - name: {{ template "registry_secret" . }} {{- end }} containers: - - name: run-airflow-migrations - image: {{ template "airflow_image" . }} - imagePullPolicy: {{ .Values.images.airflow.pullPolicy }} - # Support running against 1.10.x and 2.0.0dev/master - args: ["bash", "-c", "airflow upgradedb || airflow db upgrade"] - env: - {{- include "custom_airflow_environment" . | indent 10 }} - {{- include "standard_airflow_environment" . | indent 10 }} - name: create-user image: {{ template "airflow_image" . }} imagePullPolicy: {{ .Values.images.airflow.pullPolicy }} diff --git a/chart/templates/migrate-database-job.yaml b/chart/templates/migrate-database-job.yaml new file mode 100644 index 0000000000..37a9b2d325 --- /dev/null +++ b/chart/templates/migrate-database-job.yaml @@ -0,0 +1,76 @@ +# 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 Run Migrations +################################# +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ .Release.Name }}-run-airflow-migrations + labels: + tier: airflow + component: run-airflow-migrations + release: {{ .Release.Name }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: {{ .Release.Service }} +{{- with .Values.labels }} +{{ toYaml . | indent 4 }} +{{- end }} + annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + labels: + tier: airflow + component: run-airflow-migrations + release: {{ .Release.Name }} + spec: + securityContext: + runAsUser: {{ .Values.uid }} + restartPolicy: OnFailure + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + affinity: +{{ toYaml .Values.affinity | indent 8 }} + tolerations: +{{ toYaml .Values.tolerations | indent 8 }} + {{- if or .Values.registry.secretName .Values.registry.connection }} + imagePullSecrets: + - name: {{ template "registry_secret" . }} + {{- end }} + containers: + - name: run-airflow-migrations + image: {{ template "airflow_image" . }} + imagePullPolicy: {{ .Values.images.airflow.pullPolicy }} + # Support running against 1.10.x and 2.0.0dev/master + args: ["bash", "-c", "airflow upgradedb || airflow db upgrade"] + env: + {{- include "custom_airflow_environment" . | indent 10 }} + {{- include "standard_airflow_environment" . | indent 10 }} + volumeMounts: + - name: config + mountPath: {{ template "airflow_config_path" . }} + subPath: airflow.cfg + readOnly: true + volumes: + - name: config + configMap: + name: {{ template "airflow_config" . }} diff --git a/chart/tests/migrate-database-job_test.yaml b/chart/tests/migrate-database-job_test.yaml new file mode 100644 index 0000000000..117b7a7794 --- /dev/null +++ b/chart/tests/migrate-database-job_test.yaml @@ -0,0 +1,27 @@ +# 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. + +templates: + - migrate-database-job.yaml +tests: + - it: should run by default + asserts: + - isKind: + of: Job + - equal: + path: spec.template.spec.containers[0].name + value: run-airflow-migrations