Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotations not getting added to cleanup pods #21484

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions chart/templates/cleanup/cleanup-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ spec:
{{- end }}
annotations:
sidecar.istio.io/inject: "false"
{{- if .Values.airflowPodAnnotations }}
{{- toYaml .Values.airflowPodAnnotations | nindent 12 }}
{{- end }}
{{- if .Values.cleanup.podAnnotations }}
{{- toYaml .Values.cleanup.podAnnotations | nindent 12 }}
{{- end }}
spec:
restartPolicy: Never
nodeSelector:
Expand Down
10 changes: 8 additions & 2 deletions chart/tests/test_airflow_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ def test_annotations(self):
name=release_name,
values={
"airflowPodAnnotations": {"test-annotation/safe-to-evict": "true"},
"cleanup": {"enabled": True},
},
show_only=[
"templates/scheduler/scheduler-deployment.yaml",
"templates/workers/worker-deployment.yaml",
"templates/webserver/webserver-deployment.yaml",
"templates/flower/flower-deployment.yaml",
"templates/triggerer/triggerer-deployment.yaml",
"templates/cleanup/cleanup-cronjob.yaml",
],
)

assert 5 == len(k8s_objects)
assert 6 == len(k8s_objects)

for k8s_object in k8s_objects:
annotations = k8s_object["spec"]["template"]["metadata"]["annotations"]
if k8s_object['kind'] == 'CronJob':
annotations = k8s_object["spec"]["jobTemplate"]["spec"]["template"]["metadata"]["annotations"]
else:
annotations = k8s_object["spec"]["template"]["metadata"]["annotations"]

assert "test-annotation/safe-to-evict" in annotations
assert "true" in annotations["test-annotation/safe-to-evict"]

Expand Down
38 changes: 34 additions & 4 deletions chart/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
from tests.helm_template_generator import render_chart


def deployment_annotations(obj):
return obj["spec"]["template"]["metadata"]["annotations"]


def cronjob_annotations(obj):
return obj["spec"]["jobTemplate"]["spec"]["template"]["metadata"]["annotations"]


def get_object_annotations(obj):
if obj["kind"] == "CronJob":
return cronjob_annotations(obj)
return deployment_annotations(obj)


class TestServiceAccountAnnotations:
@pytest.mark.parametrize(
"values,show_only,expected_annotations",
Expand Down Expand Up @@ -279,6 +293,20 @@ def test_annotations_are_added(self, values, show_only, expected_annotations):
"example": "triggerer",
},
),
(
{
"cleanup": {
"enabled": True,
"podAnnotations": {
"example": "cleanup",
},
}
},
"templates/cleanup/cleanup-cronjob.yaml",
{
"example": "cleanup",
},
),
],
)
class TestPerComponentPodAnnotations:
Expand All @@ -294,10 +322,11 @@ def test_annotations_are_added(self, values, show_only, expected_annotations):
# we hope to test on.
assert len(k8s_objects) == 1
obj = k8s_objects[0]
annotations = get_object_annotations(obj)

for k, v in expected_annotations.items():
assert k in obj["spec"]["template"]["metadata"]["annotations"]
assert v == obj["spec"]["template"]["metadata"]["annotations"][k]
assert k in annotations
assert v == annotations[k]

def test_precedence(self, values, show_only, expected_annotations):
values_global_annotations = {"airflowPodAnnotations": {k: "GLOBAL" for k in expected_annotations}}
Expand All @@ -315,7 +344,8 @@ def test_precedence(self, values, show_only, expected_annotations):
# we hope to test on.
assert len(k8s_objects) == 1
obj = k8s_objects[0]
annotations = get_object_annotations(obj)

for k, v in expected_annotations.items():
assert k in obj["spec"]["template"]["metadata"]["annotations"]
assert v == obj["spec"]["template"]["metadata"]["annotations"][k]
assert k in annotations
assert v == annotations[k]
8 changes: 8 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,14 @@
"$ref": "#/definitions/io.k8s.api.core.v1.Toleration"
}
},
"podAnnotations": {
"description": "Annotations to add to cleanup pods.",
"type": "object",
"default": {},
"additionalProperties": {
"type": "string"
}
},
"resources": {
"description": "Resources for or cleanup pods",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,8 @@ cleanup:
affinity: {}
tolerations: []

podAnnotations: {}

resources: {}
# limits:
# cpu: 100m
Expand Down