Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fce2a60
Add webserverConfigConfigmapName to Helm chart to use an existing con…
Oct 31, 2022
b34b3fb
Add missing mounts in optional worker sidecars and containers with ex…
Oct 31, 2022
8b38f24
Add Helm tests for webserverConfigConfigmapName
Oct 31, 2022
d9b2bc3
Add missing commas in test_webserver.py
Nov 1, 2022
0ca6ed7
Add missing argument to include directives
Nov 1, 2022
9c62b24
Correct readOnly value for the webserver-config volumeMount
Nov 1, 2022
827c2ab
Correct rendered templates for test_webserver_config_configmap_name_v…
Nov 1, 2022
9bc57a6
Correct jmespath queries for test_webserver_config_configmap_name_vol…
Nov 1, 2022
5dba900
Correct the webserver-config volumeMount indentation in templates
Nov 1, 2022
8fc08ed
Rename webserverConfigConfigmapName to webserverConfigConfigMapName
JulesTriomphe Dec 2, 2022
b20b379
Move test_webserver_config_configmap_name_volume_mounts to test_airfl…
Dec 2, 2022
2986e05
Merge branch 'main' into feature/webserverConfigConfigmapName
Dec 2, 2022
fd6ae72
Rename webserverConfigConfigmapName to webserverConfigConfigMapName i…
Dec 2, 2022
e9c1cd7
Remove configurations that are true by default in test_webserver_conf…
Dec 2, 2022
e851f74
Rename webserverConfigConfigmapName to webserverConfigConfigMapName i…
Dec 3, 2022
4e95b6c
Rename webserverConfigConfigmapName to webserverConfigConfigMapName i…
Dec 3, 2022
8db8108
Merge branch 'apache:main' into feature/webserverConfigConfigmapName
JulesTriomphe Dec 3, 2022
654a176
Merge branch 'main' into feature/webserverConfigConfigmapName
JulesTriomphe Dec 4, 2022
1c3c937
Revert unwanted comment in breeze's docker command utils
Dec 4, 2022
37774ab
Merge branch 'main' into feature/webserverConfigConfigmapName
JulesTriomphe Dec 4, 2022
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
11 changes: 11 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ server_tls_key_file = /etc/pgbouncer/server.key
{{ (printf "%s/webserver_config.py" .Values.airflowHome) | quote }}
{{- end }}

{{ define "airflow_webserver_config_configmap_name" -}}
{{ default (printf "%s-webserver-config" .Release.Name) .Values.webserver.webserverConfigConfigMapName }}
{{- end }}

{{ define "airflow_webserver_config_mount" -}}
- name: webserver-config
mountPath: {{ template "airflow_webserver_config_path" . }}
subPath: webserver_config.py
readOnly: True
{{- end -}}

{{ define "airflow_local_setting_path" -}}
{{ (printf "%s/config/airflow_local_settings.py" .Values.airflowHome) | quote }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/configmaps/webserver-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
################################
## Airflow ConfigMap
#################################
{{- if .Values.webserver.webserverConfig }}
{{- if and .Values.webserver.webserverConfig (not .Values.webserver.webserverConfigConfigMapName) }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-webserver-config
name: {{ template "airflow_webserver_config_configmap_name" . }}
labels:
tier: airflow
component: config
Expand Down
14 changes: 14 additions & 0 deletions chart/templates/scheduler/scheduler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ spec:
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if .Values.scheduler.extraVolumeMounts }}
{{ toYaml .Values.scheduler.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
args:
{{- include "wait-for-migrations-command" . | indent 10 }}
Expand Down Expand Up @@ -204,6 +207,9 @@ spec:
- name: logs
mountPath: {{ template "airflow_logs" . }}
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
{{- if and $localOrDagProcessorDisabled (or .Values.dags.persistence.enabled .Values.dags.gitSync.enabled) }}
{{- include "airflow_dags_mount" . | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -235,6 +241,9 @@ spec:
mountPath: {{ template "airflow_logs" . }}
{{- if .Values.scheduler.extraVolumeMounts }}
{{ toYaml .Values.scheduler.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
{{- end }}
{{- if .Values.scheduler.extraContainers }}
Expand All @@ -244,6 +253,11 @@ spec:
- name: config
configMap:
name: {{ template "airflow_config" . }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
- name: webserver-config
configMap:
name: {{ template "airflow_webserver_config_configmap_name" . }}
{{- end }}
{{- if $localOrDagProcessorDisabled }}
{{- if .Values.dags.persistence.enabled }}
- name: dags
Expand Down
11 changes: 11 additions & 0 deletions chart/templates/triggerer/triggerer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ spec:
{{- if .Values.triggerer.extraVolumeMounts }}
{{ toYaml .Values.triggerer.extraVolumeMounts | nindent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
args:
{{- include "wait-for-migrations-command" . | nindent 10 }}
envFrom:
Expand Down Expand Up @@ -156,6 +159,9 @@ spec:
- name: logs
mountPath: {{ template "airflow_logs" . }}
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
{{- if or .Values.dags.persistence.enabled .Values.dags.gitSync.enabled }}
{{- include "airflow_dags_mount" . | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -187,6 +193,11 @@ spec:
- name: config
configMap:
name: {{ template "airflow_config" . }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
- name: webserver-config
configMap:
name: {{ template "airflow_webserver_config_configmap_name" . }}
{{- end }}
{{- if .Values.dags.persistence.enabled }}
- name: dags
persistentVolumeClaim:
Expand Down
14 changes: 7 additions & 7 deletions chart/templates/webserver/webserver-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ spec:
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if .Values.webserver.extraVolumeMounts }}
{{ toYaml .Values.webserver.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
args:
{{- include "wait-for-migrations-command" . | indent 10 }}
Expand Down Expand Up @@ -169,11 +172,8 @@ spec:
readOnly: true
{{- end }}
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if .Values.webserver.webserverConfig }}
- name: webserver-config
mountPath: {{ template "airflow_webserver_config_path" . }}
subPath: webserver_config.py
readOnly: true
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
{{- if and (semverCompare "<2.0.0" .Values.airflowVersion) (or .Values.dags.gitSync.enabled .Values.dags.persistence.enabled) }}
{{- include "airflow_dags_mount" . | nindent 12 }}
Expand Down Expand Up @@ -232,10 +232,10 @@ spec:
- name: config
configMap:
name: {{ template "airflow_config" . }}
{{- if .Values.webserver.webserverConfig }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
- name: webserver-config
configMap:
name: {{ .Release.Name }}-webserver-config
name: {{ template "airflow_webserver_config_configmap_name" . }}
{{- end }}
{{- if (semverCompare "<2.0.0" .Values.airflowVersion) }}
{{- if .Values.dags.persistence.enabled }}
Expand Down
17 changes: 17 additions & 0 deletions chart/templates/workers/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ spec:
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if .Values.workers.extraVolumeMounts }}
{{ toYaml .Values.workers.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
args:
{{- include "wait-for-migrations-command" . | indent 10 }}
Expand Down Expand Up @@ -216,6 +219,9 @@ spec:
{{- if or .Values.dags.persistence.enabled .Values.dags.gitSync.enabled }}
{{- include "airflow_dags_mount" . | nindent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
envFrom:
{{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
env:
Expand Down Expand Up @@ -257,6 +263,9 @@ spec:
{{- if .Values.workers.extraVolumeMounts }}
{{ toYaml .Values.workers.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
{{- end }}
{{- if .Values.workers.kerberosSidecar.enabled }}
- name: worker-kerberos
Expand All @@ -282,6 +291,9 @@ spec:
readOnly: false
{{- if .Values.workers.extraVolumeMounts }}
{{ toYaml .Values.workers.extraVolumeMounts | indent 12 }}
{{- end }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
{{ include "airflow_webserver_config_mount" . | indent 12 }}
{{- end }}
envFrom:
{{- include "custom_airflow_environment_from" . | default "\n []" | indent 10 }}
Expand All @@ -303,6 +315,11 @@ spec:
- name: config
configMap:
name: {{ template "airflow_config" . }}
{{- if or .Values.webserver.webserverConfig .Values.webserver.webserverConfigConfigMapName }}
- name: webserver-config
configMap:
name: {{ template "airflow_webserver_config_configmap_name" . }}
{{- end }}
{{- if .Values.kerberos.enabled }}
- name: kerberos-keytab
secret:
Expand Down
14 changes: 13 additions & 1 deletion chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3429,7 +3429,7 @@
}
},
"webserverConfig": {
"description": "This string (can be templated) will be mounted into the Airflow webserver as a custom `webserver_config.py`. You can bake a `webserver_config.py` in to your image instead.",
"description": "This string (can be templated) will be mounted into the Airflow webserver as a custom `webserver_config.py`. You can bake a `webserver_config.py` in to your image instead or specify a configmap containing the webserver_config.py.",
"type": [
"string",
"null"
Expand All @@ -3440,6 +3440,18 @@
"from airflow import configuration as conf\n\n# The SQLAlchemy connection string.\nSQLALCHEMY_DATABASE_URI = conf.get('database', 'SQL_ALCHEMY_CONN')\n\n# Flask-WTF flag for CSRF\nCSRF_ENABLED = True"
]
},
"webserverConfigConfigMapName": {
"description": "The configmap name containing the webserver_config.py.",
"type": [
"string",
"null"
],
"x-docsSection": "Common",
"default": null,
"examples": [
"my-webserver-configmap"
]
},
"service": {
"description": "Webserver Service configuration.",
"type": "object",
Expand Down
7 changes: 5 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,10 @@ webserver:
extraVolumes: []
extraVolumeMounts: []

# This string (can be templated) will be mounted into the Airflow Webserver as a custom
# webserver_config.py. You can bake a webserver_config.py in to your image instead.
# This string (can be templated) will be mounted into the Airflow Webserver
# as a custom webserver_config.py. You can bake a webserver_config.py in to
# your image instead or specify a configmap containing the
# webserver_config.py.
webserverConfig: ~
# webserverConfig: |
# from airflow import configuration as conf
Expand All @@ -981,6 +983,7 @@ webserver:

# # Flask-WTF flag for CSRF
# CSRF_ENABLED = True
webserverConfigConfigMapName: ~

service:
type: ClusterIP
Expand Down
36 changes: 36 additions & 0 deletions tests/charts/test_airflow_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ def test_dags_mount(self, dag_values, expected_mount):
for doc in docs:
assert expected_mount in jmespath.search("spec.template.spec.containers[0].volumeMounts", doc)

def test_webserver_config_configmap_name_volume_mounts(self):
configmap_name = "my-configmap"
docs = render_chart(
values={
"webserver": {
"webserverConfig": "CSRF_ENABLED = True # {{ .Release.Name }}",
"webserverConfigConfigMapName": configmap_name,
},
"workers": {"kerberosSidecar": {"enabled": True}},
},
show_only=[
"templates/scheduler/scheduler-deployment.yaml",
"templates/triggerer/triggerer-deployment.yaml",
"templates/webserver/webserver-deployment.yaml",
"templates/workers/worker-deployment.yaml",
],
)
for index in range(len(docs)):
print(docs[index])
assert "webserver-config" in [
c["name"]
for r in jmespath.search(
"spec.template.spec.initContainers[?name=='wait-for-airflow-migrations'].volumeMounts",
docs[index],
)
for c in r
]
for container in jmespath.search("spec.template.spec.containers", docs[index]):
assert "webserver-config" in [c["name"] for c in jmespath.search("volumeMounts", container)]
assert "webserver-config" in [
c["name"] for c in jmespath.search("spec.template.spec.volumes", docs[index])
]
assert configmap_name == jmespath.search(
"spec.template.spec.volumes[?name=='webserver-config'].configMap.name | [0]", docs[index]
)

def test_annotations(self):
"""
Test Annotations are correctly applied on all pods created Scheduler, Webserver & Worker
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 @@ -758,6 +758,18 @@ def test_no_webserver_config_configmap_by_default(self):
docs = render_chart(show_only=["templates/configmaps/webserver-configmap.yaml"])
assert 0 == len(docs)

def test_no_webserver_config_configmap_with_configmap_name(self):
docs = render_chart(
values={
"webserver": {
"webserverConfig": "CSRF_ENABLED = True # {{ .Release.Name }}",
"webserverConfigConfigMapName": "my-configmap",
}
},
show_only=["templates/configmaps/webserver-configmap.yaml"],
)
assert 0 == len(docs)

def test_webserver_config_configmap(self):
docs = render_chart(
values={"webserver": {"webserverConfig": "CSRF_ENABLED = True # {{ .Release.Name }}"}},
Expand Down