Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chart/templates/jobs/create-user-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ spec:
{{- if .Values.createUserJob.args }}
args: {{ tpl (toYaml .Values.createUserJob.args) . | nindent 12 }}
{{- end }}
{{- if .Values.createUserJob.applyCustomEnv }}
envFrom:
{{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{ else }}
env:
{{- end }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- include "container_extra_envs" (list . .Values.createUserJob.env) | indent 10 }}
resources:
Expand Down
6 changes: 5 additions & 1 deletion chart/templates/jobs/migrate-database-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ spec:
{{- if .Values.migrateDatabaseJob.args }}
args: {{ tpl (toYaml .Values.migrateDatabaseJob.args) . | nindent 12 }}
{{- end }}
{{- if .Values.migrateDatabaseJob.applyCustomEnv }}
envFrom:
{{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{ else }}
env:
{{- end }}
- name: PYTHONUNBUFFERED
value: "1"
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
resources:
{{ toYaml .Values.migrateDatabaseJob.resources | indent 12 }}
Expand Down
10 changes: 10 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2885,6 +2885,11 @@
"type": "boolean",
"default": true
},
"applyCustomEnv": {
"description": "Specify if you want additional configured env vars applied to this job",
"type": "boolean",
"default": true
},
"env": {
"description": "Add additional env vars to the create user job pod.",
"type": "array",
Expand Down Expand Up @@ -3079,6 +3084,11 @@
"description": "Specify if you want to use the default Helm Hook annotations",
"type": "boolean",
"default": true
},
"applyCustomEnv": {
"description": "Specify if you want additional configured env vars applied to this job",
"type": "boolean",
"default": true
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ createUserJob:
# 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
applyCustomEnv: true

env: []

resources: {}
Expand Down Expand Up @@ -872,6 +874,7 @@ migrateDatabaseJob:
# 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
applyCustomEnv: true

# Airflow webserver settings
webserver:
Expand Down
6 changes: 5 additions & 1 deletion docs/helm-chart/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ The command removes all the Kubernetes components associated with the chart and
Installing the Chart with Argo CD, Flux or Terraform
-----------------------------------------------------

When installing the chart using Argo CD, Flux, or Terraform, you MUST set the two following values, or your application
When installing the chart using Argo CD, Flux, or Terraform, you MUST set the four following values, or your application
will not start as the migrations will not be run:

.. code-block:: yaml

createUserJob:
useHelmHooks: false
applyCustomEnv: false
migrateDatabaseJob:
useHelmHooks: false
applyCustomEnv: false

This is so these CI/CD services can perform updates without issues and preserve the immutability of Kubernetes Job manifests.

This also applies if you install the chart using ``--wait`` in your ``helm install`` command.
30 changes: 30 additions & 0 deletions tests/charts/test_create_user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ def test_should_add_extraEnvs(self):
"spec.template.spec.containers[0].env", docs[0]
)

def test_should_enable_custom_env(self):
docs = render_chart(
values={
"env": [
{"name": "foo", "value": "bar"},
],
"extraEnv": "- name: extraFoo\n value: extraBar\n",
"createUserJob": {"applyCustomEnv": True},
},
show_only=["templates/jobs/create-user-job.yaml"],
)
envs = jmespath.search("spec.template.spec.containers[0].env", docs[0])
assert {"name": "foo", "value": "bar"} in envs
assert {"name": "extraFoo", "value": "extraBar"} in envs

def test_should_disable_custom_env(self):
docs = render_chart(
values={
"env": [
{"name": "foo", "value": "bar"},
],
"extraEnv": "- name: extraFoo\n value: extraBar\n",
"createUserJob": {"applyCustomEnv": False},
},
show_only=["templates/jobs/create-user-job.yaml"],
)
envs = jmespath.search("spec.template.spec.containers[0].env", docs[0])
assert {"name": "foo", "value": "bar"} not in envs
assert {"name": "extraFoo", "value": "extraBar"} not in envs

@pytest.mark.parametrize(
"airflow_version, expected_arg",
[
Expand Down