From 30adda1745d5d36a71c70d0be7287008ff49d699 Mon Sep 17 00:00:00 2001 From: Sakari Ikonen Date: Fri, 13 Dec 2024 00:05:05 +0200 Subject: [PATCH] revert kubernetes annotation validation changes --- metaflow/plugins/kubernetes/kube_utils.py | 2 +- metaflow/plugins/kubernetes/kubernetes_decorator.py | 7 ++++--- test/unit/test_kubernetes.py | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/metaflow/plugins/kubernetes/kube_utils.py b/metaflow/plugins/kubernetes/kube_utils.py index 31606046397..d41f613be00 100644 --- a/metaflow/plugins/kubernetes/kube_utils.py +++ b/metaflow/plugins/kubernetes/kube_utils.py @@ -61,7 +61,7 @@ def qos_requests_and_limits(qos: str, cpu: int, memory: int, storage: int): return qos_requests, qos_limits -def validate_kube_labels_or_annotations( +def validate_kube_labels( labels: Optional[Dict[str, Optional[str]]], ) -> bool: """Validate label values. diff --git a/metaflow/plugins/kubernetes/kubernetes_decorator.py b/metaflow/plugins/kubernetes/kubernetes_decorator.py index c818c2d62e5..0142db6f4f2 100644 --- a/metaflow/plugins/kubernetes/kubernetes_decorator.py +++ b/metaflow/plugins/kubernetes/kubernetes_decorator.py @@ -37,7 +37,7 @@ from ..aws.aws_utils import get_docker_registry, get_ec2_instance_metadata from .kubernetes import KubernetesException -from .kube_utils import validate_kube_labels_or_annotations, parse_kube_keyvalue_list +from .kube_utils import validate_kube_labels, parse_kube_keyvalue_list try: unicode @@ -409,8 +409,9 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge size=self.attributes["shared_memory"], step=step ) ) - validate_kube_labels_or_annotations(self.attributes["labels"]) - validate_kube_labels_or_annotations(self.attributes["annotations"]) + + validate_kube_labels(self.attributes["labels"]) + # TODO: add validation to annotations as well? def package_init(self, flow, step_name, environment): try: diff --git a/test/unit/test_kubernetes.py b/test/unit/test_kubernetes.py index c9dcb0a3bc4..302267f6400 100644 --- a/test/unit/test_kubernetes.py +++ b/test/unit/test_kubernetes.py @@ -3,7 +3,7 @@ from metaflow.plugins.kubernetes.kubernetes import KubernetesException from metaflow.plugins.kubernetes.kube_utils import ( - validate_kube_labels_or_annotations, + validate_kube_labels, parse_kube_keyvalue_list, ) @@ -41,8 +41,8 @@ }, ], ) -def test_kubernetes_decorator_validate_kube_labels_or_annotations(labels): - assert validate_kube_labels_or_annotations(labels) +def test_kubernetes_decorator_validate_kube_labels(labels): + assert validate_kube_labels(labels) @pytest.mark.parametrize( @@ -66,10 +66,10 @@ def test_kubernetes_decorator_validate_kube_labels_or_annotations(labels): {"valid": "test", "invalid": "bißchen"}, ], ) -def test_kubernetes_decorator_validate_kube_labels_or_annotations_fail(labels): +def test_kubernetes_decorator_validate_kube_labels_fail(labels): """Fail if label contains invalid characters or is too long""" with pytest.raises(KubernetesException): - validate_kube_labels_or_annotations(labels) + validate_kube_labels(labels) @pytest.mark.parametrize(