-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add kubernetes labels * Add labels to cli * Empty labels fix * Fix labels in decorator * Allow dictionaries in decorator * Convert strings to dictionaries * Make parse node selector function more generic * Add argo labels * Clean kubernetes labels * Hash original string and use shorter hash * Fix command join * Add rename parse list and add tests for value cleaning * override spec parser * Don't reencode json objects * Strip quotes * Fix rebase error * Throw exception for invalid labels * Changes based on PR comments * Fix invalid label error message * Add code comment to kube validation function * Add tests and fix bad json * Fix pre-commit error * Remove f-strings :( * More python 3.5 fixes
- Loading branch information
Showing
6 changed files
with
216 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
|
||
from metaflow.plugins.kubernetes.kubernetes import KubernetesException | ||
from metaflow.plugins.kubernetes.kubernetes_decorator import KubernetesDecorator | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"labels", | ||
[ | ||
None, | ||
{"label": "value"}, | ||
{"label1": "val1", "label2": "val2"}, | ||
{"label1": "val1", "label2": None}, | ||
{"label": "a"}, | ||
{"label": ""}, | ||
{ | ||
"label": ( | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"123" | ||
) | ||
}, | ||
{ | ||
"label": ( | ||
"1234567890" | ||
"1234567890" | ||
"1234-_.890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"123" | ||
) | ||
}, | ||
], | ||
) | ||
def test_kubernetes_decorator_validate_kube_labels(labels): | ||
assert KubernetesDecorator.validate_kube_labels(labels) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"labels", | ||
[ | ||
{"label": "a-"}, | ||
{"label": ".a"}, | ||
{"label": "test()"}, | ||
{ | ||
"label": ( | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234567890" | ||
"1234" | ||
) | ||
}, | ||
{"label": "(){}??"}, | ||
{"valid": "test", "invalid": "bißchen"}, | ||
], | ||
) | ||
def test_kubernetes_decorator_validate_kube_labels_fail(labels): | ||
"""Fail if label contains invalid characters or is too long""" | ||
with pytest.raises(KubernetesException): | ||
KubernetesDecorator.validate_kube_labels(labels) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"items,requires_both,expected", | ||
[ | ||
(["key=value"], True, {"key": "value"}), | ||
(["key=value"], False, {"key": "value"}), | ||
(["key"], False, {"key": None}), | ||
(["key=value", "key2=value2"], True, {"key": "value", "key2": "value2"}), | ||
], | ||
) | ||
def test_kubernetes_parse_keyvalue_list(items, requires_both, expected): | ||
ret = KubernetesDecorator.parse_kube_keyvalue_list(items, requires_both) | ||
assert ret == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"items,requires_both", | ||
[ | ||
(["key=value", "key=value2"], True), | ||
(["key"], True), | ||
], | ||
) | ||
def test_kubernetes_parse_keyvalue_list(items, requires_both): | ||
with pytest.raises(KubernetesException): | ||
KubernetesDecorator.parse_kube_keyvalue_list(items, requires_both) |