Skip to content
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

allow migration jobs and init containers to be optional #22195

Merged
merged 2 commits into from
Mar 22, 2022
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
2 changes: 2 additions & 0 deletions chart/templates/jobs/migrate-database-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
################################
## Airflow Run Migrations
#################################
{{- if .Values.migrateDatabaseJob.enabled }}
{{- $nodeSelector := or .Values.migrateDatabaseJob.nodeSelector .Values.nodeSelector }}
{{- $affinity := or .Values.migrateDatabaseJob.affinity .Values.affinity }}
{{- $tolerations := or .Values.migrateDatabaseJob.tolerations .Values.tolerations }}
Expand Down Expand Up @@ -113,3 +114,4 @@ spec:
{{- if .Values.migrateDatabaseJob.extraVolumes }}
{{ toYaml .Values.migrateDatabaseJob.extraVolumes | nindent 8 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions chart/templates/scheduler/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ spec:
- name: {{ template "registry_secret" . }}
{{- end }}
initContainers:
{{- if .Values.scheduler.waitForMigrations.enabled }}
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
- name: wait-for-airflow-migrations
resources:
{{ toYaml .Values.scheduler.resources | indent 12 }}
Expand All @@ -136,6 +137,7 @@ spec:
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- end }}
{{- if .Values.dags.gitSync.enabled }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | nindent 8 }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions chart/templates/triggerer/triggerer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ spec:
- name: {{ template "registry_secret" . }}
{{- end }}
initContainers:
{{- if .Values.triggerer.waitForMigrations.enabled }}
- name: wait-for-airflow-migrations
resources:
{{- toYaml .Values.triggerer.resources | nindent 12 }}
Expand All @@ -119,6 +120,7 @@ spec:
env:
{{- include "custom_airflow_environment" . | nindent 10 }}
{{- include "standard_airflow_environment" . | nindent 10 }}
{{- end }}
{{- if and (.Values.dags.gitSync.enabled) (not .Values.dags.persistence.enabled) }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | nindent 8 }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions chart/templates/webserver/webserver-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ spec:
- name: {{ template "registry_secret" . }}
{{- end }}
initContainers:
{{- if .Values.webserver.waitForMigrations.enabled }}
- name: wait-for-airflow-migrations
resources:
{{ toYaml .Values.webserver.resources | indent 12 }}
Expand All @@ -131,6 +132,7 @@ spec:
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- end }}
{{- if and (.Values.dags.gitSync.enabled) (not .Values.dags.persistence.enabled) (semverCompare "<2.0.0" .Values.airflowVersion) }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | nindent 8 }}
{{- end }}
Expand Down
41 changes: 41 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,18 @@
"fsGroup": 0
}
]
},
"waitForMigrations": {
"description": "wait-for-airflow-migrations init container.",
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"description": "Enable wait-for-airflow-migrations init container.",
"type": "boolean",
"default": true
}
}
}
}
},
Expand Down Expand Up @@ -2023,6 +2035,18 @@
"fsGroup": 0
}
]
},
"waitForMigrations": {
"description": "wait-for-airflow-migrations init container.",
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"description": "Enable wait-for-airflow-migrations init container.",
"type": "boolean",
"default": true
}
}
}
}
},
Expand Down Expand Up @@ -2206,6 +2230,11 @@
"x-docsSection": "Jobs",
"additionalProperties": false,
"properties": {
"enabled": {
"description": "Enable migrate database job.",
"type": "boolean",
"default": true
},
"command": {
"description": "Command to use when running migrate database job (templated).",
"type": [
Expand Down Expand Up @@ -2807,6 +2836,18 @@
"additionalProperties": {
"type": "string"
}
},
"waitForMigrations": {
"description": "wait-for-airflow-migrations init container.",
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"description": "Enable wait-for-airflow-migrations init container.",
"type": "boolean",
"default": true
}
}
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ scheduler:
# cpu: 100m
# memory: 128Mi

waitForMigrations:
# Whether to create init container to wait for db migrations
enabled: true

# Airflow create user job settings
createUserJob:
# Command to use when running the create user job (templated).
Expand Down Expand Up @@ -733,6 +737,7 @@ createUserJob:

# Airflow database migration job settings
migrateDatabaseJob:
enabled: true
# Command to use when running the migrate database job (templated).
command: ~
# Args to use when running the migrate database job (templated).
Expand Down Expand Up @@ -928,6 +933,10 @@ webserver:

podAnnotations: {}

waitForMigrations:
# Whether to create init container to wait for db migrations
enabled: true

# Airflow Triggerer Config
triggerer:
enabled: true
Expand Down Expand Up @@ -1013,6 +1022,10 @@ triggerer:

podAnnotations: {}

waitForMigrations:
# Whether to create init container to wait for db migrations
enabled: true

# Flower settings
flower:
# Enable flower.
Expand Down
17 changes: 17 additions & 0 deletions tests/charts/test_migrate_database_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ def test_should_run_by_default(self):
assert "run-airflow-migrations" == jmespath.search("spec.template.spec.containers[0].name", docs[0])
assert 50000 == jmespath.search("spec.template.spec.securityContext.runAsUser", docs[0])

@pytest.mark.parametrize(
"migrate_database_job_enabled,created",
[
(False, False),
(True, True),
],
)
def test_enable_migrate_database_job(self, migrate_database_job_enabled, created):
docs = render_chart(
values={
"migrateDatabaseJob": {"enabled": migrate_database_job_enabled},
},
show_only=["templates/jobs/migrate-database-job.yaml"],
)

assert bool(docs) is created

def test_should_support_annotations(self):
docs = render_chart(
values={"migrateDatabaseJob": {"annotations": {"foo": "bar"}, "jobAnnotations": {"fiz": "fuz"}}},
Expand Down
12 changes: 12 additions & 0 deletions tests/charts/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def test_should_add_extra_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.containers[-1]", docs[0])

def test_disable_wait_for_migration(self):
docs = render_chart(
values={
"scheduler": {
"waitForMigrations": {"enabled": False},
},
},
show_only=["templates/scheduler/scheduler-deployment.yaml"],
)
actual = jmespath.search("spec.template.spec.initContainers", docs[0])
assert actual is None

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
Expand Down
12 changes: 12 additions & 0 deletions tests/charts/test_triggerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_can_be_disabled(self):

assert 0 == len(docs)

def test_disable_wait_for_migration(self):
docs = render_chart(
values={
"triggerer": {
"waitForMigrations": {"enabled": False},
},
},
show_only=["templates/triggerer/triggerer-deployment.yaml"],
)
actual = jmespath.search("spec.template.spec.initContainers", docs[0])
assert actual is None

def test_should_add_extra_containers(self):
docs = render_chart(
values={
Expand Down
12 changes: 12 additions & 0 deletions tests/charts/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def test_wait_for_migration_airflow_version(self, airflow_version, expected_arg)
actual = jmespath.search("spec.template.spec.initContainers[0].args", docs[0])
assert expected_arg == actual[: len(expected_arg)]

def test_disable_wait_for_migration(self):
docs = render_chart(
values={
"webserver": {
"waitForMigrations": {"enabled": False},
},
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)
actual = jmespath.search("spec.template.spec.initContainers", docs[0])
assert actual is None

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
Expand Down