From 8ebd35989c2b63ef6c328ddb2ab547d09e181aff Mon Sep 17 00:00:00 2001 From: Mahdi Khashan <58775404+mahdikhashan@users.noreply.github.com> Date: Tue, 28 Jan 2025 01:32:50 +0100 Subject: [PATCH] [SDK] improve PVC creation name error (#2496) * improve pvc name error message by failing early and clear message with correct name example Signed-off-by: mahdikhashan * fix lint Signed-off-by: mahdikhashan * fix lint Signed-off-by: mahdikhashan * raise value error for wrong name format by reconciliation Signed-off-by: mahdikhashan * revert created utils Signed-off-by: mahdikhashan * improve test case name Signed-off-by: mahdikhashan * improve value error message Signed-off-by: mahdikhashan * improve code flow Signed-off-by: mahdikhashan --------- Signed-off-by: mahdikhashan Signed-off-by: Gary Miguel --- .../v1beta1/kubeflow/katib/api/katib_client.py | 18 ++++++++---------- .../kubeflow/katib/api/katib_client_test.py | 7 +++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py b/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py index b641800290f..caf2a45aaca 100644 --- a/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py +++ b/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py @@ -569,16 +569,14 @@ class name in this argument. ), ) except Exception as e: - pvc_list = self.core_api.list_namespaced_persistent_volume_claim( - namespace=namespace - ) - # Check if the PVC with the specified name exists. - for pvc in pvc_list.items: - if pvc.metadata.name == name: - print( - f"PVC '{name}' already exists in namespace " f"{namespace}." - ) - break + if hasattr(e, "status") and e.status == 422: + raise ValueError( + f"The Experiment name '{name}' is invalid. It must use only lowercase " + f"alphanumeric characters ('a-z', '0-9'), hyphens ('-'), or periods ('.'). " + f"It must also start and end with an alphanumeric character." + ) + elif hasattr(e, "status") and e.status == 409: + print(f"PVC '{name}' already exists in namespace " f"{namespace}.") else: raise RuntimeError(f"failed to create PVC. Error: {e}") diff --git a/sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py b/sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py index 0a78d75f3bb..f6a17017c34 100644 --- a/sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py +++ b/sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py @@ -310,6 +310,13 @@ def create_experiment( }, ValueError, ), + ( + "invalid name format", + { + "name": "Llama3.1-fine-tune", + }, + ValueError, + ), ( "invalid hybrid parameters - objective and model_provider_parameters", {