This is an automated email from the ASF dual-hosted git repository. jedcunningham pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push: new 35f3bf8 Chart: Allow disabling the Helm hooks in the helm chart (#18776) 35f3bf8 is described below commit 35f3bf8fb447be0ed581cc317897180b541c63ce Author: Gilles Marin <mrngil...@gmail.com> AuthorDate: Fri Nov 5 17:04:19 2021 +0100 Chart: Allow disabling the Helm hooks in the helm chart (#18776) --- chart/templates/jobs/create-user-job.yaml | 15 +++++++++------ chart/templates/jobs/migrate-database-job.yaml | 15 +++++++++------ chart/tests/test_create_user_job.py | 8 ++++++++ chart/tests/test_migrate_database_job.py | 8 ++++++++ chart/values.schema.json | 10 ++++++++++ chart/values.yaml | 6 ++++++ docs/helm-chart/index.rst | 11 +++++++++++ 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/chart/templates/jobs/create-user-job.yaml b/chart/templates/jobs/create-user-job.yaml index b3f65a9..1766d74 100644 --- a/chart/templates/jobs/create-user-job.yaml +++ b/chart/templates/jobs/create-user-job.yaml @@ -35,13 +35,16 @@ metadata: {{- with .Values.labels }} {{ toYaml . | indent 4 }} {{- end }} + {{- $annotations := dict }} + {{- if .Values.createUserJob.useHelmHooks }} + {{- $_ := set $annotations "helm.sh/hook" "post-install,post-upgrade" }} + {{- $_ := set $annotations "helm.sh/hook-weight" "1" }} + {{- $_ := set $annotations "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }} + {{- end }} + {{- with $annotations := merge $annotations .Values.createUserJob.jobAnnotations }} annotations: - "helm.sh/hook": post-install - "helm.sh/hook-weight": "2" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded - {{- if .Values.createUserJob.jobAnnotations }} - {{- toYaml .Values.createUserJob.jobAnnotations | nindent 4 }} - {{- end }} + {{- $annotations | toYaml | nindent 4 }} + {{- end }} spec: template: metadata: diff --git a/chart/templates/jobs/migrate-database-job.yaml b/chart/templates/jobs/migrate-database-job.yaml index 577abb6..8b748ea 100644 --- a/chart/templates/jobs/migrate-database-job.yaml +++ b/chart/templates/jobs/migrate-database-job.yaml @@ -34,13 +34,16 @@ metadata: {{- with .Values.labels }} {{ toYaml . | indent 4 }} {{- end }} + {{- $annotations := dict }} + {{- if .Values.migrateDatabaseJob.useHelmHooks }} + {{- $_ := set $annotations "helm.sh/hook" "post-install,post-upgrade" }} + {{- $_ := set $annotations "helm.sh/hook-weight" "1" }} + {{- $_ := set $annotations "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }} + {{- end }} + {{- with $annotations := merge $annotations .Values.migrateDatabaseJob.jobAnnotations }} annotations: - "helm.sh/hook": post-install,post-upgrade - "helm.sh/hook-weight": "1" - "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded - {{- if .Values.migrateDatabaseJob.jobAnnotations }} - {{- toYaml .Values.migrateDatabaseJob.jobAnnotations | nindent 4 }} - {{- end }} + {{- $annotations | toYaml | nindent 4 }} + {{- end }} spec: template: metadata: diff --git a/chart/tests/test_create_user_job.py b/chart/tests/test_create_user_job.py index 2d526fd..d65b025 100644 --- a/chart/tests/test_create_user_job.py +++ b/chart/tests/test_create_user_job.py @@ -106,3 +106,11 @@ class CreateUserJobTest(unittest.TestCase): ) assert resources == jmespath.search("spec.template.spec.containers[0].resources", docs[0]) + + def test_should_disable_default_helm_hooks(self): + docs = render_chart( + values={"createUserJob": {"useHelmHooks": False}}, + show_only=["templates/jobs/create-user-job.yaml"], + ) + annotations = jmespath.search("spec.template.metadata.annotations", docs[0]) + assert annotations is None diff --git a/chart/tests/test_migrate_database_job.py b/chart/tests/test_migrate_database_job.py index 28cbb7a..fec95c9 100644 --- a/chart/tests/test_migrate_database_job.py +++ b/chart/tests/test_migrate_database_job.py @@ -155,3 +155,11 @@ class TestMigrateDatabaseJob: "memory": "512Mi", }, } == jmespath.search("spec.template.spec.containers[0].resources", docs[0]) + + def test_should_disable_default_helm_hooks(self): + docs = render_chart( + values={"migrateDatabaseJob": {"useHelmHooks": False}}, + show_only=["templates/jobs/migrate-database-job.yaml"], + ) + annotations = jmespath.search("spec.template.metadata.annotations", docs[0]) + assert annotations is None diff --git a/chart/values.schema.json b/chart/values.schema.json index 0960df3..d847a3d 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -1712,6 +1712,11 @@ } } ] + }, + "useHelmHooks": { + "description": "Specify if you want to use the default Helm Hook annotations", + "type": "boolean", + "default": true } } }, @@ -1795,6 +1800,11 @@ "description": "Specify Tolerations for the migrate database job pod.", "type": "array", "default": [] + }, + "useHelmHooks": { + "description": "Specify if you want to use the default Helm Hook annotations", + "type": "boolean", + "default": true } } }, diff --git a/chart/values.yaml b/chart/values.yaml index 69ed6a8..3c5b04c 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -621,6 +621,9 @@ createUserJob: nodeSelector: {} affinity: {} tolerations: [] + # In case you need to disable the helm hooks that create the jobs after install. + # Disable this if you are using ArgoCD for example + useHelmHooks: true resources: {} # limits: @@ -661,6 +664,9 @@ migrateDatabaseJob: nodeSelector: {} affinity: {} tolerations: [] + # In case you need to disable the helm hooks that create the jobs after install. + # Disable this if you are using ArgoCD for example + useHelmHooks: true # Airflow webserver settings webserver: diff --git a/docs/helm-chart/index.rst b/docs/helm-chart/index.rst index ac9b41f..efde5b8 100644 --- a/docs/helm-chart/index.rst +++ b/docs/helm-chart/index.rst @@ -118,3 +118,14 @@ To uninstall/delete the ``airflow`` deployment: helm delete airflow --namespace airflow The command removes all the Kubernetes components associated with the chart and deletes the release. + +Installing the Chart with ArgoCD +-------------------------------- + +When installing the chart using ArgoCD, you MUST set the two following values, or your application +will not start as the migrations will not be run: + +.. code-block:: yaml + + createUserJob.useHelmHooks: false + migrateDatabaseJob.useHelmHooks: false