This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 8b634ffa6a Add Helm chart controller annotations (#30126)
8b634ffa6a is described below
commit 8b634ffa6aa5a83e1f87f1a62bfa07e78147f5c5
Author: bnguyennhon <[email protected]>
AuthorDate: Thu Mar 16 20:09:20 2023 +0100
Add Helm chart controller annotations (#30126)
---------
Co-authored-by: Hussein Awala <[email protected]>
---
chart/templates/cleanup/cleanup-cronjob.yaml | 3 +++
chart/templates/statsd/statsd-deployment.yaml | 3 +++
chart/values.schema.json | 16 ++++++++++++++++
chart/values.yaml | 5 +++++
tests/charts/test_cleanup_pods.py | 27 +++++++++++++++++++++++++++
tests/charts/test_statsd.py | 18 ++++++++++++++++++
6 files changed, 72 insertions(+)
diff --git a/chart/templates/cleanup/cleanup-cronjob.yaml
b/chart/templates/cleanup/cleanup-cronjob.yaml
index 2a7dd3d608..adbce47a8a 100644
--- a/chart/templates/cleanup/cleanup-cronjob.yaml
+++ b/chart/templates/cleanup/cleanup-cronjob.yaml
@@ -41,6 +41,9 @@ metadata:
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
+ {{- with .Values.cleanup.jobAnnotations }}
+ annotations: {{- toYaml . | nindent 4 }}
+ {{- end }}
spec:
schedule: "{{ .Values.cleanup.schedule }}"
# The cron job does not allow concurrent runs; if it is time for a new job
run and the previous job run hasn't finished yet, the cron job skips the new
job run
diff --git a/chart/templates/statsd/statsd-deployment.yaml
b/chart/templates/statsd/statsd-deployment.yaml
index 4772a1f3c6..856243b80a 100644
--- a/chart/templates/statsd/statsd-deployment.yaml
+++ b/chart/templates/statsd/statsd-deployment.yaml
@@ -38,6 +38,9 @@ metadata:
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
+ {{- with .Values.statsd.annotations }}
+ annotations: {{- toYaml . | nindent 4 }}
+ {{- end }}
spec:
replicas: 1
{{- if $revisionHistoryLimit }}
diff --git a/chart/values.schema.json b/chart/values.schema.json
index 4131ec60d7..5d055386bd 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -4245,6 +4245,14 @@
"type": "string"
}
},
+ "annotations": {
+ "description": "Annotations to add to the StatsD
deployment.",
+ "type": "object",
+ "default": {},
+ "additionalProperties": {
+ "type": "string"
+ }
+ },
"args": {
"description": "Args to use when running statsd-exporter
(templated).",
"type": [
@@ -5090,6 +5098,14 @@
"exec airflow kubernetes cleanup-pods --namespace={{
.Release.Namespace }}"
]
},
+ "jobAnnotations": {
+ "description": "Annotations to add to the cleanup
cronjob.",
+ "type": "object",
+ "default": {},
+ "additionalProperties": {
+ "type": "string"
+ }
+ },
"nodeSelector": {
"description": "Select certain nodes for cleanup pods.",
"type": "object",
diff --git a/chart/values.yaml b/chart/values.yaml
index 7b157acda6..e07b74c1df 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -1470,6 +1470,9 @@ statsd:
# Arguments for StatsD exporter command.
args: ["--statsd.mapping-config=/etc/statsd-exporter/mappings.yml"]
+ # Annotations to add to the StatsD Deployment.
+ annotations: {}
+
# Create ServiceAccount
serviceAccount:
# Specifies whether a ServiceAccount should be created
@@ -1772,6 +1775,8 @@ cleanup:
# Args to use when running the cleanup cronjob (templated).
args: ["bash", "-c", "exec airflow kubernetes cleanup-pods --namespace={{
.Release.Namespace }}"]
+ # jobAnnotations are annotations on the cleanup CronJob
+ jobAnnotations: {}
# Select certain nodes for airflow cleanup pods.
nodeSelector: {}
diff --git a/tests/charts/test_cleanup_pods.py
b/tests/charts/test_cleanup_pods.py
index f6b15a5f6b..c7d3956506 100644
--- a/tests/charts/test_cleanup_pods.py
+++ b/tests/charts/test_cleanup_pods.py
@@ -200,6 +200,33 @@ class TestCleanupPods:
== "test_label_value"
)
+ def test_should_add_component_specific_annotations(self):
+ docs = render_chart(
+ values={
+ "cleanup": {
+ "enabled": True,
+ "jobAnnotations": {"test_cronjob_annotation":
"test_cronjob_annotation_value"},
+ "podAnnotations": {"test_pod_annotation":
"test_pod_annotation_value"},
+ },
+ },
+ show_only=["templates/cleanup/cleanup-cronjob.yaml"],
+ )
+
+ assert "test_cronjob_annotation" in
jmespath.search("metadata.annotations", docs[0])
+ assert (
+ "test_cronjob_annotation_value"
+ == jmespath.search("metadata.annotations",
docs[0])["test_cronjob_annotation"]
+ )
+ assert "test_pod_annotation" in jmespath.search(
+ "spec.jobTemplate.spec.template.metadata.annotations", docs[0]
+ )
+ assert (
+ "test_pod_annotation_value"
+ ==
jmespath.search("spec.jobTemplate.spec.template.metadata.annotations", docs[0])[
+ "test_pod_annotation"
+ ]
+ )
+
def test_cleanup_resources_are_configurable(self):
resources = {
"requests": {
diff --git a/tests/charts/test_statsd.py b/tests/charts/test_statsd.py
index 7e7dbbab7c..4358342cd5 100644
--- a/tests/charts/test_statsd.py
+++ b/tests/charts/test_statsd.py
@@ -222,3 +222,21 @@ class TestStatsd:
)
assert jmespath.search("spec.template.spec.containers[0].args",
docs[0]) == args
+
+ def test_should_add_component_specific_annotations(self):
+ docs = render_chart(
+ values={
+ "statsd": {
+ "annotations": {"test_annotation":
"test_annotation_value"},
+ "podAnnotations": {"test_pod_annotation":
"test_pod_annotation_value"},
+ },
+ },
+ show_only=["templates/statsd/statsd-deployment.yaml"],
+ )
+ assert "annotations" in jmespath.search("metadata", docs[0])
+ assert jmespath.search("metadata.annotations",
docs[0])["test_annotation"] == "test_annotation_value"
+ assert "test_pod_annotation" in
jmespath.search("spec.template.metadata.annotations", docs[0])
+ assert (
+ jmespath.search("spec.template.metadata.annotations",
docs[0])["test_pod_annotation"]
+ == "test_pod_annotation_value"
+ )