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

Add extraInitContainers to scheduler/webserver/workers #16098

Merged
merged 1 commit into from
May 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions chart/files/pod-template-file.kubernetes-helm-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ metadata:
{{- toYaml .Values.airflowPodAnnotations | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled) }}
{{- if or (and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled)) .Values.workers.extraInitContainers }}
initContainers:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | indent 4 }}
{{- end }}
{{- if and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled) }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true") | nindent 4 }}
{{- end }}
{{- if .Values.workers.extraInitContainers }}
{{- toYaml .Values.workers.extraInitContainers | nindent 4 }}
{{- end }}
{{- end }}
containers:
- args: []
command: []
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/scheduler/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ spec:
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- if .Values.scheduler.extraInitContainers }}
{{- toYaml .Values.scheduler.extraInitContainers | nindent 8 }}
{{- end }}
containers:
# Always run the main scheduler container.
- name: scheduler
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/webserver/webserver-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ spec:
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- if .Values.webserver.extraInitContainers }}
{{- toYaml .Values.webserver.extraInitContainers | nindent 8 }}
{{- end }}
containers:
- name: webserver
image: {{ template "airflow_image" . }}
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/workers/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ spec:
env:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
{{- if .Values.workers.extraInitContainers }}
{{- toYaml .Values.workers.extraInitContainers | nindent 8 }}
{{- end }}
containers:
- name: worker
image: {{ template "airflow_image" . }}
Expand Down
18 changes: 18 additions & 0 deletions chart/tests/test_pod_template_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,21 @@ def test_airflow_pod_annotations(self):
annotations = jmespath.search("metadata.annotations", docs[0])
assert "my_annotation" in annotations
assert "annotated!" in annotations["my_annotation"]

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

assert {
"name": "test-init-container",
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.initContainers[-1]", docs[0])
28 changes: 22 additions & 6 deletions chart/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,34 @@ def test_should_add_extra_containers(self):
"executor": "CeleryExecutor",
"scheduler": {
"extraContainers": [
{
"name": "test-container",
"image": "test-registry/test-repo:test-tag",
"imagePullPolicy": "Always",
}
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
],
},
},
show_only=["templates/scheduler/scheduler-deployment.yaml"],
)

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

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
"scheduler": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
],
},
},
show_only=["templates/scheduler/scheduler-deployment.yaml"],
)

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
Expand Down
28 changes: 22 additions & 6 deletions chart/tests/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,34 @@ def test_should_add_extra_containers(self):
"executor": "CeleryExecutor",
"webserver": {
"extraContainers": [
{
"name": "test-container",
"image": "test-registry/test-repo:test-tag",
"imagePullPolicy": "Always",
}
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
],
},
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)

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

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
"webserver": {
"extraInitContainers": [
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
],
},
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)

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

def test_should_create_valid_affinity_tolerations_and_node_selector(self):
docs = render_chart(
Expand Down
28 changes: 22 additions & 6 deletions chart/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,34 @@ def test_should_add_extra_containers(self):
"executor": "CeleryExecutor",
"workers": {
"extraContainers": [
{
"name": "test-container",
"image": "test-registry/test-repo:test-tag",
"imagePullPolicy": "Always",
}
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
],
},
},
show_only=["templates/workers/worker-deployment.yaml"],
)

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

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

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
Expand Down
15 changes: 15 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@
"type": "array",
"default": []
},
"extraInitContainers": {
"description": "Add additional init containers into workers.",
"type": "array",
"default": []
},
"extraVolumes": {
"description": "Mount additional volumes into workers.",
"type": "array",
Expand Down Expand Up @@ -1179,6 +1184,11 @@
"type": "array",
"default": []
},
"extraInitContainers": {
"description": "Add additional init containers into scheduler.",
"type": "array",
"default": []
},
"extraVolumes": {
"description": "Mount additional volumes into scheduler.",
"type": "array",
Expand Down Expand Up @@ -1455,6 +1465,11 @@
"type": "array",
"default": []
},
"extraInitContainers": {
"description": "Add additional init containers into webserver.",
"type": "array",
"default": []
},
"extraVolumes": {
"description": "Mount additional volumes into webserver.",
"type": "array",
Expand Down
6 changes: 6 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ workers:

# Launch additional containers into worker.
extraContainers: []
# Add additional init containers into workers.
extraInitContainers: []

# Mount additional volumes into worker.
extraVolumes: []
Expand Down Expand Up @@ -469,6 +471,8 @@ scheduler:

# Launch additional containers into scheduler.
extraContainers: []
# Add additional init containers into scheduler.
extraInitContainers: []

# Mount additional volumes into scheduler.
extraVolumes: []
Expand Down Expand Up @@ -566,6 +570,8 @@ webserver:

# Launch additional containers into webserver.
extraContainers: []
# Add additional init containers into webserver.
extraInitContainers: []

# Mount additional volumes into webserver.
extraVolumes: []
Expand Down
38 changes: 33 additions & 5 deletions docs/helm-chart/using-additional-containers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,48 @@
under the License.

Using additional containers
----------------------------
===========================

If you are using your own sidecar container, you can add it through the ``extraContainers`` value.
You can define different containers for scheduler, webserver and worker pods.
Sidecar Containers
------------------

For example, a sidecar that syncs DAGs from object storage.
If you want to deploy your own sidecar container, you can add it through the ``extraContainers`` parameter.
You can define different containers for the scheduler, webserver and worker pods.

For example, sidecars that sync DAGs from object storage.

.. note::

``extraContainers`` value supports CeleryExecutor only.
``workers.extraContainers`` is only functional with ``CeleryExecutor``.

.. code-block:: yaml

scheduler:
extraContainers:
- name: s3-sync
image: my-company/s3-sync:latest
imagePullPolicy: Always
workers:
extraContainers:
- name: s3-sync
image: my-company/s3-sync:latest
imagePullPolicy: Always


Init Containers
---------------

You can also deploy extra init containers through the ``extraInitContainers`` parameter.
You can define different containers for the scheduler, webserver and worker pods.

For example, an init container that just says hello:

.. code-block:: yaml

scheduler:
extraInitContainers:
- name: hello
image: debian
args:
- echo
- hello