Skip to content

Commit

Permalink
Enable templating in extraContainers and extraInitContainers (apache#…
Browse files Browse the repository at this point in the history
…38507)

* Add test cases for templating extraContainers and extraInitContainers

* Use templating for extra airflow containers
  • Loading branch information
mewa authored Jun 3, 2024
1 parent 9b67a5e commit 1bf8479
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 7 deletions.
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 @@ -50,7 +50,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 4 }}
{{- end }}
{{- if .Values.workers.extraInitContainers }}
{{- toYaml .Values.workers.extraInitContainers | nindent 4 }}
{{- tpl (toYaml .Values.workers.extraInitContainers) . | nindent 4 }}
{{- end }}
{{- if and (semverCompare ">=2.8.0" .Values.airflowVersion) .Values.workers.kerberosInitContainer.enabled }}
- name: kerberos-init
Expand Down Expand Up @@ -180,7 +180,7 @@ spec:
{{- include "standard_airflow_environment" . | indent 6 }}
{{- end }}
{{- if .Values.workers.extraContainers }}
{{- toYaml .Values.workers.extraContainers | nindent 4 }}
{{- tpl (toYaml .Values.workers.extraContainers) . | nindent 4 }}
{{- end }}
{{- if .Values.workers.priorityClassName }}
priorityClassName: {{ .Values.workers.priorityClassName }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }}
{{- end }}
{{- if .Values.dagProcessor.extraInitContainers }}
{{- toYaml .Values.dagProcessor.extraInitContainers | nindent 8 }}
{{- tpl (toYaml .Values.dagProcessor.extraInitContainers) . | nindent 8 }}
{{- end }}
containers:
- name: dag-processor
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/scheduler/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }}
{{- end }}
{{- if .Values.scheduler.extraInitContainers }}
{{- toYaml .Values.scheduler.extraInitContainers | nindent 8 }}
{{- tpl (toYaml .Values.scheduler.extraInitContainers) . | nindent 8 }}
{{- end }}
containers:
# Always run the main scheduler container.
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/triggerer/triggerer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }}
{{- end }}
{{- if .Values.triggerer.extraInitContainers }}
{{- toYaml .Values.triggerer.extraInitContainers | nindent 8 }}
{{- tpl (toYaml .Values.triggerer.extraInitContainers) . | nindent 8 }}
{{- end }}
containers:
- name: triggerer
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/webserver/webserver-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }}
{{- end }}
{{- if .Values.webserver.extraInitContainers }}
{{- toYaml .Values.webserver.extraInitContainers | nindent 8 }}
{{- tpl (toYaml .Values.webserver.extraInitContainers) . | nindent 8 }}
{{- end }}
containers:
- name: webserver
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/workers/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ spec:
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }}
{{- end }}
{{- if .Values.workers.extraInitContainers }}
{{- toYaml .Values.workers.extraInitContainers | nindent 8 }}
{{- tpl (toYaml .Values.workers.extraInitContainers) . | nindent 8 }}
{{- end }}
containers:
- name: worker
Expand Down
14 changes: 14 additions & 0 deletions helm_tests/airflow_aux/test_create_user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"createUserJob": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/jobs/create-user-job.yaml"],
)

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

def test_should_add_extra_volumes(self):
docs = render_chart(
values={
Expand Down
14 changes: 14 additions & 0 deletions helm_tests/airflow_aux/test_migrate_database_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"migrateDatabaseJob": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/jobs/migrate-database-job.yaml"],
)

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

def test_set_resources(self):
docs = render_chart(
values={
Expand Down
30 changes: 30 additions & 0 deletions helm_tests/airflow_aux/test_pod_template_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,21 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.initContainers[-1]", docs[0])

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

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

def test_should_add_extra_containers(self):
docs = render_chart(
values={
Expand All @@ -720,6 +735,21 @@ def test_should_add_extra_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.containers[-1]", docs[0])

def test_should_template_extra_containers(self):
docs = render_chart(
values={
"workers": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/pod-template-file.yaml"],
chart_dir=self.temp_chart_dir,
)

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

def test_should_add_pod_labels(self):
docs = render_chart(
values={"labels": {"label1": "value1", "label2": "value2"}},
Expand Down
30 changes: 30 additions & 0 deletions helm_tests/airflow_core/test_dag_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"dagProcessor": {
"enabled": True,
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/dag-processor/dag-processor-deployment.yaml"],
)

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

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
Expand All @@ -128,6 +143,21 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.initContainers[-1]", docs[0])

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"dagProcessor": {
"enabled": True,
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
},
},
show_only=["templates/dag-processor/dag-processor-deployment.yaml"],
)

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
values={
Expand Down
29 changes: 29 additions & 0 deletions helm_tests/airflow_core/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"executor": "CeleryExecutor",
"scheduler": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/scheduler/scheduler-deployment.yaml"],
)

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

def test_disable_wait_for_migration(self):
docs = render_chart(
values={
Expand Down Expand Up @@ -100,6 +115,20 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.initContainers[-1]", docs[0])

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"scheduler": {
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
},
},
show_only=["templates/scheduler/scheduler-deployment.yaml"],
)

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
values={
Expand Down
28 changes: 28 additions & 0 deletions helm_tests/airflow_core/test_triggerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"triggerer": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/triggerer/triggerer-deployment.yaml"],
)

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

def test_should_add_extra_init_containers(self):
docs = render_chart(
values={
Expand All @@ -124,6 +138,20 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.initContainers[-1]", docs[0])

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"triggerer": {
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
},
},
show_only=["templates/triggerer/triggerer-deployment.yaml"],
)

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
values={
Expand Down
29 changes: 29 additions & 0 deletions helm_tests/airflow_core/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"executor": "CeleryExecutor",
"workers": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/workers/worker-deployment.yaml"],
)

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

def test_disable_wait_for_migration(self):
docs = render_chart(
values={
Expand Down Expand Up @@ -113,6 +128,20 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.initContainers[-1]", docs[0])

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

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

def test_should_add_extra_volume_and_extra_volume_mount(self):
docs = render_chart(
values={
Expand Down
29 changes: 29 additions & 0 deletions helm_tests/webserver/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ 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_should_template_extra_containers(self):
docs = render_chart(
values={
"executor": "CeleryExecutor",
"webserver": {
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
},
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)

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

def test_should_add_extraEnvs(self):
docs = render_chart(
values={
Expand Down Expand Up @@ -315,6 +330,20 @@ def test_should_add_extra_init_containers(self):
"image": "test-registry/test-repo:test-tag",
} == jmespath.search("spec.template.spec.initContainers[-1]", docs[0])

def test_should_template_extra_init_containers(self):
docs = render_chart(
values={
"webserver": {
"extraInitContainers": [{"name": "{{ .Release.Name }}-init-container"}],
},
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)

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

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

0 comments on commit 1bf8479

Please sign in to comment.