-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom command and args in jobs
- Loading branch information
1 parent
6e5c9c8
commit d630155
Showing
6 changed files
with
261 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import unittest | ||
|
||
import jmespath | ||
from parameterized import parameterized | ||
|
||
from chart.tests.helm_template_generator import render_chart | ||
|
||
|
@@ -168,3 +169,102 @@ def test_should_add_extra_volume_mounts(self): | |
assert {"name": "foobar", "mountPath": "foo/bar"} == jmespath.search( | ||
"spec.template.spec.containers[0].volumeMounts[-1]", docs[0] | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
("1.10.14", "airflow create_user"), | ||
("2.0.2", "airflow users create"), | ||
], | ||
) | ||
def test_default_command_and_args_airflow_version(self, airflow_version, expected_arg): | ||
docs = render_chart( | ||
values={ | ||
"airflowVersion": airflow_version, | ||
}, | ||
show_only=["templates/jobs/create-user-job.yaml"], | ||
) | ||
|
||
assert jmespath.search("spec.template.spec.containers[0].command", docs[0]) is None | ||
assert [ | ||
"bash", | ||
"-c", | ||
f"exec \\\n{expected_arg} \"$@\"", | ||
"--", | ||
"-r", | ||
"Admin", | ||
"-u", | ||
"admin", | ||
"-e", | ||
"[email protected]", | ||
"-f", | ||
"admin", | ||
"-l", | ||
"user", | ||
"-p", | ||
"admin", | ||
] == jmespath.search("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={"createUserJob": {"command": command, "args": args}}, | ||
show_only=["templates/jobs/create-user-job.yaml"], | ||
) | ||
|
||
assert command == jmespath.search("spec.template.spec.containers[0].command", docs[0]) | ||
assert args == jmespath.search("spec.template.spec.containers[0].args", docs[0]) | ||
|
||
def test_command_and_args_overrides_are_templated(self): | ||
docs = render_chart( | ||
values={ | ||
"createUserJob": {"command": ["{{ .Release.Name }}"], "args": ["{{ .Release.Service }}"]} | ||
}, | ||
show_only=["templates/jobs/create-user-job.yaml"], | ||
) | ||
|
||
assert ["RELEASE-NAME"] == jmespath.search("spec.template.spec.containers[0].command", docs[0]) | ||
assert ["Helm"] == jmespath.search("spec.template.spec.containers[0].args", docs[0]) | ||
|
||
def test_default_user_overrides(self): | ||
docs = render_chart( | ||
values={ | ||
"webserver": { | ||
"defaultUser": { | ||
"role": "SomeRole", | ||
"username": "jdoe", | ||
"email": "[email protected]", | ||
"firstName": "John", | ||
"lastName": "Doe", | ||
"password": "whereisjane?", | ||
} | ||
} | ||
}, | ||
show_only=["templates/jobs/create-user-job.yaml"], | ||
) | ||
|
||
assert jmespath.search("spec.template.spec.containers[0].command", docs[0]) is None | ||
assert [ | ||
"bash", | ||
"-c", | ||
"exec \\\nairflow users create \"$@\"", | ||
"--", | ||
"-r", | ||
"SomeRole", | ||
"-u", | ||
"jdoe", | ||
"-e", | ||
"[email protected]", | ||
"-f", | ||
"John", | ||
"-l", | ||
"Doe", | ||
"-p", | ||
"whereisjane?", | ||
] == jmespath.search("spec.template.spec.containers[0].args", docs[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters