Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,17 @@ server_tls_key_file = /etc/pgbouncer/server.key
readOnly: True
{{- end }}

{{- define "airflow_api_server_config_configmap_name" -}}
{{- default (printf "%s-api-server-config" .Release.Name) .Values.webserver.webserverConfigConfigMapName }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This points to the wrong section in the values file. I'll include the fix in a new MR

{{- end }}

{{- define "airflow_api_server_config_mount" -}}
- name: api-server-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
8 changes: 8 additions & 0 deletions chart/templates/api-server/api-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ spec:
resources: {{- toYaml .Values.apiServer.resources | nindent 12 }}
volumeMounts:
{{- include "airflow_config_mount" . | nindent 12 }}
{{- if or .Values.apiServer.apiServerConfig .Values.apiServer.apiServerConfigConfigMapName }}
{{- include "airflow_api_server_config_mount" . | nindent 12 }}
{{- end }}
{{- if .Values.logs.persistence.enabled }}
- name: logs
mountPath: {{ template "airflow_logs" . }}
Expand Down Expand Up @@ -225,6 +228,11 @@ spec:
- name: config
configMap:
name: {{ template "airflow_config" . }}
{{- if or .Values.apiServer.apiServerConfig .Values.apiServer.apiServerConfigConfigMapName }}
- name: api-server-config
configMap:
name: {{ template "airflow_api_server_config_configmap_name" . }}
{{- end }}
{{- if (semverCompare "<2.0.0" .Values.airflowVersion) }}
{{- end }}
{{- if .Values.logs.persistence.enabled }}
Expand Down
46 changes: 46 additions & 0 deletions chart/templates/configmaps/api-server-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/}}

################################
## Airflow ConfigMap
#################################
{{- if semverCompare ">=3.0.0" .Values.airflowVersion }}
{{- if and .Values.apiServer.apiServerConfig (not .Values.apiServer.apiServerConfigConfigMapName) }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "airflow_api_server_config_configmap_name" . }}
labels:
tier: airflow
component: config
release: {{ .Release.Name }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.apiServer.configMapAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data:
webserver_config.py: |-
{{- tpl .Values.apiServer.apiServerConfig . | nindent 4 }}
{{- end }}
{{- end }}
24 changes: 24 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5065,6 +5065,30 @@
],
"$ref": "#/definitions/io.k8s.api.core.v1.ResourceRequirements"
},
"apiServerConfig": {
"description": "This string (templated) will be mounted into the Airflow API Server 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"
],
"x-docsSection": "Common",
"default": null,
"examples": [
"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"
]
},
"apiServerConfigConfigMapName": {
"description": "The configmap name containing the webserver_config.py.",
"type": [
"string",
"null"
],
"x-docsSection": "Common",
"default": null,
"examples": [
"my-webserver-configmap"
]
},
"defaultUser": {
"description": "Optional default Airflow user information",
"type": "object",
Expand Down
18 changes: 18 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,24 @@ apiServer:
# cpu: 100m
# memory: 128Mi

# Add custom annotations to the apiServer configmap
configMapAnnotations: {}

# This string (templated) will be mounted into the Airflow API Server
# 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.
apiServerConfig: ~
# apiServerConfig: |
# from airflow import configuration as conf

# # The SQLAlchemy connection string.
# SQLALCHEMY_DATABASE_URI = conf.get('database', 'SQL_ALCHEMY_CONN')

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

livenessProbe:
initialDelaySeconds: 15
timeoutSeconds: 5
Expand Down
77 changes: 77 additions & 0 deletions helm-tests/tests/helm_tests/apiserver/test_apiserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import jmespath
from chart_utils.helm_template_generator import render_chart


class TestAPIServerDeployment:
"""Tests API Server deployment."""

def test_airflow_2(self):
"""
API Server only supports Airflow 3.0.0 and later.
"""
docs = render_chart(
values={"airflowVersion": "2.10.5"},
show_only=["templates/api-server/api-server-deployment.yaml"],
)
assert len(docs) == 0

def test_should_not_create_api_server_configmap_when_lower_than_3(self):
"""
API Server configmap is only created for Airflow 3.0.0 and later.
"""
docs = render_chart(
values={"airflowVersion": "2.10.5"},
show_only=["templates/configmaps/api-server-configmap.yaml"],
)
assert len(docs) == 0

def test_should_add_annotations_to_api_server_configmap(self):
docs = render_chart(
values={
"airflowVersion": "3.0.0",
"apiServer": {
"apiServerConfig": "CSRF_ENABLED = True # {{ .Release.Name }}",
"configMapAnnotations": {"test_annotation": "test_annotation_value"},
},
},
show_only=["templates/configmaps/api-server-configmap.yaml"],
)

assert "annotations" in jmespath.search("metadata", docs[0])
assert jmespath.search("metadata.annotations", docs[0])["test_annotation"] == "test_annotation_value"

def test_should_add_volume_and_volume_mount_when_exist_api_server_config(self):
docs = render_chart(
values={"apiServer": {"apiServerConfig": "CSRF_ENABLED = True"}, "airflowVersion": "3.0.0"},
show_only=["templates/api-server/api-server-deployment.yaml"],
)

assert {
"name": "api-server-config",
"configMap": {"name": "release-name-api-server-config"},
} in jmespath.search("spec.template.spec.volumes", docs[0])

assert {
"name": "api-server-config",
"mountPath": "/opt/airflow/webserver_config.py",
"subPath": "webserver_config.py",
"readOnly": True,
} in jmespath.search("spec.template.spec.containers[0].volumeMounts", docs[0])