diff --git a/chart/templates/cleanup/cleanup-cronjob.yaml b/chart/templates/cleanup/cleanup-cronjob.yaml index 2a7dd3d608181..adbce47a8a724 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 4772a1f3c6db8..856243b80add4 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 4131ec60d7863..5d055386bd086 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 7b157acda6765..e07b74c1df611 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 f6b15a5f6b462..c7d3956506ca0 100644 --- a/tests/charts/test_cleanup_pods.py +++ b/tests/charts/test_cleanup_pods.py @@ -200,6 +200,33 @@ def test_should_add_component_specific_labels(self): == "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 7e7dbbab7c90d..4358342cd52c4 100644 --- a/tests/charts/test_statsd.py +++ b/tests/charts/test_statsd.py @@ -222,3 +222,21 @@ def test_statsd_args_can_be_overridden(self): ) 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" + )