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", {