This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 3f74b178b4c6a9607198ca55cac20e069e0af899 Author: Daniel Imberman <[email protected]> AuthorDate: Thu Oct 15 11:10:14 2020 -0700 Create job for airflow migrations (#11533) Creating airflow migrations should run seperately from the user creation job, as many users might not want to create users on deployment. (cherry picked from commit f7e01ab29339080c77431a1fc5e4403ba2d80326) --- chart/templates/create-user-job.yaml | 9 +---- ...ate-user-job.yaml => migrate-database-job.yaml} | 43 ++++++---------------- chart/tests/migrate-database-job_test.yaml | 27 ++++++++++++++ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/chart/templates/create-user-job.yaml b/chart/templates/create-user-job.yaml index 642e36f..0f76252 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: @@ -51,14 +52,6 @@ spec: tolerations: {{ toYaml .Values.tolerations | indent 8 }} 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/create-user-job.yaml b/chart/templates/migrate-database-job.yaml similarity index 65% copy from chart/templates/create-user-job.yaml copy to chart/templates/migrate-database-job.yaml index 642e36f..37a9b2d 100644 --- a/chart/templates/create-user-job.yaml +++ b/chart/templates/migrate-database-job.yaml @@ -16,16 +16,15 @@ # under the License. ################################ -## Airflow Create User Job +## Airflow Run Migrations ################################# -{{- if .Values.webserver.defaultUser.enabled }} apiVersion: batch/v1 kind: Job metadata: - name: {{ .Release.Name }}-create-user + name: {{ .Release.Name }}-run-airflow-migrations labels: tier: airflow - component: create-user-job + component: run-airflow-migrations release: {{ .Release.Name }} chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" heritage: {{ .Release.Service }} @@ -33,16 +32,19 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} annotations: - "helm.sh/hook": post-install + "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: create-user-job + component: run-airflow-migrations release: {{ .Release.Name }} spec: + securityContext: + runAsUser: {{ .Values.uid }} restartPolicy: OnFailure nodeSelector: {{ toYaml .Values.nodeSelector | indent 8 }} @@ -50,6 +52,10 @@ spec: {{ 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" . }} @@ -59,30 +65,6 @@ spec: 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 }} - args: - - "bash" - - "-c" - # Support running against 1.10.x and 2.0.0dev/master - - 'airflow create_user "$@" || airflow users create "$@"' - - -- - - "-r" - - {{ .Values.webserver.defaultUser.role }} - - "-u" - - {{ .Values.webserver.defaultUser.username }} - - "-e" - - {{ .Values.webserver.defaultUser.email }} - - "-f" - - {{ .Values.webserver.defaultUser.firstName }} - - "-l" - - {{ .Values.webserver.defaultUser.lastName }} - - "-p" - - {{ .Values.webserver.defaultUser.password }} - env: - {{- include "custom_airflow_environment" . | indent 10 }} - {{- include "standard_airflow_environment" . | indent 10 }} volumeMounts: - name: config mountPath: {{ template "airflow_config_path" . }} @@ -92,4 +74,3 @@ spec: - name: config configMap: name: {{ template "airflow_config" . }} -{{- end }} diff --git a/chart/tests/migrate-database-job_test.yaml b/chart/tests/migrate-database-job_test.yaml new file mode 100644 index 0000000..117b7a7 --- /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
