Skip to content

Commit

Permalink
Add webserverConfigConfigMapName (apache#27419)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesTriomphe authored Dec 8, 2022
1 parent a6315c2 commit 3f06efa
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 deletions.
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

0 comments on commit 3f06efa

Please sign in to comment.