Skip to content

Commit

Permalink
Chart: Allow setting annotations on Airflow pods & Configmap (#15238)
Browse files Browse the repository at this point in the history
This PR adds a new field (`airflowConfigAnnotations`) that allows users to add `annotations` to the main `configmap.yaml` file.

I ended up setting up a new testing file as I didn't find a file where this specifically fit, but if it should be moved elsewhere let me know.

closes apache/airflow#13643

GitOrigin-RevId: 6d64cc54a6b7d1b22d0de89b5815035e21bfaf8c
  • Loading branch information
DerekHeldtWerle authored and Cloud Composer Team committed Nov 27, 2021
1 parent 649a803 commit 7382948
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chart/templates/configmaps/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ metadata:
{{- with .Values.labels }}
{{ toYaml . | indent 4 }}
{{- end -}}
{{- if .Values.airflowConfigAnnotations }}
annotations:
{{- toYaml .Values.airflowConfigAnnotations | nindent 4 }}
{{- end }}
{{- $Global := . }}
data:
# These are system-specified config overrides.
Expand Down
47 changes: 47 additions & 0 deletions chart/tests/test_configmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.

import unittest

import jmespath

from tests.helm_template_generator import render_chart


class ConfigmapTest(unittest.TestCase):
def test_single_annotation(self):
docs = render_chart(
values={
"airflowConfigAnnotations": {"key": "value"},
},
show_only=["templates/configmaps/configmap.yaml"],
)

annotations = jmespath.search("metadata.annotations", docs[0])
assert "value" == annotations.get("key")

def test_multiple_annotations(self):
docs = render_chart(
values={
"airflowConfigAnnotations": {"key": "value", "key-two": "value-two"},
},
show_only=["templates/configmaps/configmap.yaml"],
)

annotations = jmespath.search("metadata.annotations", docs[0])
assert "value" == annotations.get("key")
assert "value-two" == annotations.get("key-two")
4 changes: 4 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
"description": "Extra annotations to apply to all Airflow pods.",
"type": "object"
},
"airflowConfigAnnotations": {
"description": "Extra annotations to apply to the main Airflow configmap.",
"type": "object"
},
"rbac": {
"description": "Enable RBAC (default on most clusters these days).",
"type": "object",
Expand Down
4 changes: 4 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ networkPolicies:
# Airflow pods
airflowPodAnnotations: {}

# Extra annotations to apply to
# main Airflow configmap
airflowConfigAnnotations: {}

# Enable RBAC (default on most clusters these days)
rbac:
# Specifies whether RBAC resources should be created
Expand Down
6 changes: 6 additions & 0 deletions docs/helm-chart/parameters-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ The following tables lists the configurable parameters of the Airflow chart and
* - ``rbac.create``
- Deploy pods with Kubernetes RBAC enabled
- ``true``
* - ``airflowPodAnnotations``
- Extra annotations to apply to all Airflow pods.
- ``{}``
* - ``airflowConfigAnnotations``
- Extra annotations to apply to the main Airflow configmap.
- ``{}``
* - ``executor``
- Airflow executor (eg SequentialExecutor, LocalExecutor, CeleryExecutor, KubernetesExecutor)
- ``1``
Expand Down

0 comments on commit 7382948

Please sign in to comment.