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
2 changes: 1 addition & 1 deletion chart/docs/using-additional-containers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Init Containers
---------------

You can also deploy extra init containers through the ``extraInitContainers`` parameter.
You can define different containers for the scheduler, webserver, api server, worker, triggerer, dag processor, create user job and migrate database job pods.
You can define different containers for the scheduler, webserver/api-server, Celery/Kubernetes workers, triggerer, dag processor, create user job and migrate database job pods.

For example, an init container that just says hello:

Expand Down
4 changes: 2 additions & 2 deletions chart/files/pod-template-file.kubernetes-helm-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ spec:
{{- if and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled) }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 4 }}
{{- end }}
{{- if .Values.workers.extraInitContainers }}
{{- tpl (toYaml .Values.workers.extraInitContainers) . | nindent 4 }}
{{- if or .Values.workers.kubernetes.extraInitContainers .Values.workers.extraInitContainers }}
{{- tpl (toYaml (.Values.workers.kubernetes.extraInitContainers | default .Values.workers.extraInitContainers)) . | nindent 4 }}
{{- end }}
{{- if or .Values.workers.kubernetes.kerberosInitContainer.enabled .Values.workers.kerberosInitContainer.enabled }}
- name: kerberos-init
Expand Down
1 change: 1 addition & 0 deletions chart/newsfragments/64741.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``workers.extraInitContainers`` field is now deprecated in favor of ``workers.celery.extraInitContainers`` and ``workers.kubernetes.extraInitContainers``. Please update your configuration accordingly.
8 changes: 8 additions & 0 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,14 @@ DEPRECATION WARNING:

{{- end }}

{{- if not (empty .Values.workers.extraInitContainers) }}

DEPRECATION WARNING:
`workers.extraInitContainers` has been renamed to `workers.celery.extraInitContainers`/`workers.kubernetes.extraInitContainers`.
Please change your values as support for the old name will be dropped in a future release.

{{- end }}

{{- if not (empty .Values.workers.runtimeClassName) }}

DEPRECATION WARNING:
Expand Down
18 changes: 17 additions & 1 deletion chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@
}
},
"extraInitContainers": {
"description": "Add additional init containers into Airflow Celery workers and pods created with pod-template-file (templated).",
"description": "Add additional init containers into Airflow Celery workers and pods created with pod-template-file (templated) (deprecated, use ``workers.celery.extraInitContainers`` and/or ``workers.kubernetes.extraInitContainers`` instead).",
"type": "array",
"default": [],
"items": {
Expand Down Expand Up @@ -3388,6 +3388,14 @@
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
}
},
"extraInitContainers": {
"description": "Add additional init containers into Airflow Celery workers (templated).",
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
}
},
"extraPorts": {
"description": "Expose additional ports of Airflow Celery worker container.",
"type": "array",
Expand Down Expand Up @@ -3886,6 +3894,14 @@
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
}
},
"extraInitContainers": {
"description": "Add additional init containers into pods created with pod-template-file (templated).",
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
}
},
"nodeSelector": {
"description": "Select certain nodes for pods created with pod-template-file.",
"type": "object",
Expand Down
10 changes: 10 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ workers:

# Add additional init containers into Airflow Celery workers
# and pods created with pod-template-file (templated).
# (deprecated, use
# `workers.celery.extraInitContainers` and/or
# `workers.kubernetes.extraInitContainers`
# instead)
extraInitContainers: []

# Additional volumes and volume mounts attached to the
Expand Down Expand Up @@ -1450,6 +1454,9 @@ workers:
# Launch additional containers into Airflow Celery worker (templated)
extraContainers: []

# Add additional init containers into Airflow Celery workers (templated)
extraInitContainers: []

# Expose additional ports of Airflow Celery workers. These can be used for additional metric collection.
extraPorts: []

Expand Down Expand Up @@ -1617,6 +1624,9 @@ workers:
# container finishes so Airflow can continue the worker shutdown process!
extraContainers: []

# Add additional init containers into pods created with pod-template-file (templated)
extraInitContainers: []

# Select certain nodes for pods created with pod-template-file
nodeSelector: {}

Expand Down
66 changes: 48 additions & 18 deletions helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,38 +1067,68 @@ def test_airflow_and_workers_pod_annotations(self):
assert "my_annotation" in annotations
assert "workerPodAnnotations" in annotations["my_annotation"]

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
"workers": {
@pytest.mark.parametrize(
"workers_values",
[
{
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
]
},
{
"kubernetes": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
],
]
}
},
{
"extraInitContainers": [{"name": "test", "image": "repo:tag"}],
"kubernetes": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
]
},
},
],
)
def test_should_add_extra_init_containers(self, workers_values):
docs = render_chart(
values={"workers": workers_values},
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)

assert jmespath.search("spec.initContainers[-1]", docs[0]) == {
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
}
assert jmespath.search("spec.initContainers", docs[0]) == [
{
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
}
]

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"workers": {
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
},
@pytest.mark.parametrize(
"workers_values",
[
{"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
{"kubernetes": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]}},
{
"extraInitContainers": [{"name": "container"}],
"kubernetes": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
},
],
)
def test_should_template_extra_init_containers(self, workers_values):
docs = render_chart(
values={"workers": workers_values},
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)

assert jmespath.search("spec.initContainers[-1]", docs[0]) == {
"name": "release-name-test-init-container",
}
assert jmespath.search("spec.initContainers", docs[0]) == [
{
"name": "release-name-test-init-container",
}
]

@pytest.mark.parametrize(
"workers_values",
Expand Down
87 changes: 61 additions & 26 deletions helm-tests/tests/helm_tests/airflow_core/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,66 @@ def test_logs_mount_on_wait_for_migrations_initcontainer(self, logs_values, expe
for m in mounts
)

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
"workers": {
@pytest.mark.parametrize(
"workers_values",
[
{
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
]
},
{
"celery": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
],
]
}
},
{
"extraInitContainers": [{"name": "container", "image": "repo:tag"}],
"celery": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
]
},
},
],
)
def test_should_add_extra_init_containers(self, workers_values):
docs = render_chart(
values={"workers": workers_values},
show_only=["templates/workers/worker-deployment.yaml"],
)

assert jmespath.search("spec.template.spec.initContainers[-1]", docs[0]) == {
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
}
# [1:] -> Skipping wait-for-airflow-migrations init container
assert jmespath.search("spec.template.spec.initContainers[1:]", docs[0]) == [
{
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
}
]

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"workers": {
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
},
@pytest.mark.parametrize(
"workers_values",
[
{"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
{"celery": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]}},
{
"extraInitContainers": [{"name": "container"}],
"celery": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
},
],
)
def test_should_template_extra_init_containers(self, workers_values):
docs = render_chart(
values={"workers": workers_values},
show_only=["templates/workers/worker-deployment.yaml"],
)

assert jmespath.search("spec.template.spec.initContainers[-1]", docs[0]) == {
"name": "release-name-test-init-container"
}
# [1:] -> Skipping wait-for-airflow-migrations init container
assert jmespath.search("spec.template.spec.initContainers[1:]", docs[0]) == [
{"name": "release-name-test-init-container"}
]

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
Expand Down Expand Up @@ -940,19 +970,24 @@ def test_extra_init_container_restart_policy_is_configurable(self):
docs = render_chart(
values={
"workers": {
"extraInitContainers": [
{
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
"restartPolicy": "Always",
}
]
"celery": {
"extraInitContainers": [
{
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
"restartPolicy": "Always",
}
]
}
},
},
show_only=["templates/workers/worker-deployment.yaml"],
)

assert jmespath.search("spec.template.spec.initContainers[1].restartPolicy", docs[0]) == "Always"
# [1:] -> Skipping wait-for-airflow-migrations init container
assert jmespath.search("spec.template.spec.initContainers[1:] | [*].restartPolicy", docs[0]) == [
"Always"
]

@pytest.mark.parametrize(
("log_values", "expected_volume"),
Expand Down
14 changes: 14 additions & 0 deletions helm-tests/tests/helm_tests/airflow_core/test_worker_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,20 @@ def test_overwrite_extra_containers(self, workers_values):
],
},
},
{
"celery": {
"enableDefault": False,
"extraInitContainers": [{"name": "test", "image": "test"}],
"sets": [
{
"name": "set1",
"extraInitContainers": [
{"name": "{{ .Chart.Name }}", "image": "test-registry/test-repo:test-tag"}
],
}
],
},
},
],
)
def test_overwrite_extra_init_containers(self, workers_values):
Expand Down