Skip to content

Commit

Permalink
Chart: Make cleanup cronjob cmd/args configurable (#17970)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedcunningham committed Sep 1, 2021
1 parent 4d52207 commit 617fed9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
8 changes: 6 additions & 2 deletions chart/templates/cleanup/cleanup-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ spec:
- name: airflow-cleanup-pods
image: {{ template "airflow_image" . }}
imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
# Don't use entry point here, we don't need to wait on pg-bouncer etc being available.
args: ["kubernetes", "cleanup-pods", "--namespace={{ .Release.Namespace }}"]
{{- if .Values.cleanup.command }}
command: {{ tpl (toYaml .Values.cleanup.command) . | nindent 16 }}
{{- end }}
{{- if .Values.cleanup.args }}
args: {{ tpl (toYaml .Values.cleanup.args) . | nindent 16 }}
{{- end }}
env:
{{- include "standard_airflow_environment" . | indent 12 }}
volumeMounts:
Expand Down
47 changes: 47 additions & 0 deletions chart/tests/test_cleanup_pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest

import jmespath
from parameterized import parameterized

from tests.helm_template_generator import render_chart

Expand Down Expand Up @@ -104,3 +105,49 @@ def test_should_create_valid_affinity_tolerations_and_node_selector(self):
"spec.jobTemplate.spec.template.spec.tolerations[0].key",
docs[0],
)

def test_default_command_and_args(self):
docs = render_chart(
values={"cleanup": {"enabled": True}}, show_only=["templates/cleanup/cleanup-cronjob.yaml"]
)

assert jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].command", docs[0]) is None
assert ["bash", "-c", "exec airflow kubernetes cleanup-pods --namespace=default"] == jmespath.search(
"spec.jobTemplate.spec.template.spec.containers[0].args", docs[0]
)

@parameterized.expand(
[
(None, None),
(None, ["custom", "args"]),
(["custom", "command"], None),
(["custom", "command"], ["custom", "args"]),
]
)
def test_command_and_args_overrides(self, command, args):
docs = render_chart(
values={"cleanup": {"enabled": True, "command": command, "args": args}},
show_only=["templates/cleanup/cleanup-cronjob.yaml"],
)

assert command == jmespath.search(
"spec.jobTemplate.spec.template.spec.containers[0].command", docs[0]
)
assert args == jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].args", docs[0])

def test_log_groomer_command_and_args_overrides_are_templated(self):
docs = render_chart(
values={
"cleanup": {
"enabled": True,
"command": ["{{ .Release.Name }}"],
"args": ["{{ .Release.Service }}"],
}
},
show_only=["templates/cleanup/cleanup-cronjob.yaml"],
)

assert ["RELEASE-NAME"] == jmespath.search(
"spec.jobTemplate.spec.template.spec.containers[0].command", docs[0]
)
assert ["Helm"] == jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].args", docs[0])
26 changes: 26 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,32 @@
"type": "string",
"default": "*/15 * * * *"
},
"command": {
"description": "Command to use when running the cleanup cronjob (templated).",
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"default": null
},
"args": {
"description": "Args to use when running the cleanup cronjob (templated).",
"type": [
"array",
"null"
],
"items": {
"type": "string"
},
"default": [
"bash",
"-c",
"exec airflow kubernetes cleanup-pods --namespace={{ .Release.Namespace }}"
]
},
"nodeSelector": {
"description": "Select certain nodes for cleanup pods.",
"type": "object",
Expand Down
5 changes: 5 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,11 @@ cleanup:
enabled: false
# Run every 15 minutes
schedule: "*/15 * * * *"
# Command to use when running the cleanup cronjob (templated).
command: ~
# Args to use when running the cleanup cronjob (templated).
args: ["bash", "-c", "exec airflow kubernetes cleanup-pods --namespace={{ .Release.Namespace }}"]


# Select certain nodes for airflow cleanup pods.
nodeSelector: {}
Expand Down

0 comments on commit 617fed9

Please sign in to comment.