Skip to content

Commit 09523cd

Browse files
authored
[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 <[email protected]> * fix lint Signed-off-by: mahdikhashan <[email protected]> * fix lint Signed-off-by: mahdikhashan <[email protected]> * raise value error for wrong name format by reconciliation Signed-off-by: mahdikhashan <[email protected]> * revert created utils Signed-off-by: mahdikhashan <[email protected]> * improve test case name Signed-off-by: mahdikhashan <[email protected]> * improve value error message Signed-off-by: mahdikhashan <[email protected]> * improve code flow Signed-off-by: mahdikhashan <[email protected]> --------- Signed-off-by: mahdikhashan <[email protected]>
1 parent 0133983 commit 09523cd

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

sdk/python/v1beta1/kubeflow/katib/api/katib_client.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,14 @@ class name in this argument.
569569
),
570570
)
571571
except Exception as e:
572-
pvc_list = self.core_api.list_namespaced_persistent_volume_claim(
573-
namespace=namespace
574-
)
575-
# Check if the PVC with the specified name exists.
576-
for pvc in pvc_list.items:
577-
if pvc.metadata.name == name:
578-
print(
579-
f"PVC '{name}' already exists in namespace " f"{namespace}."
580-
)
581-
break
572+
if hasattr(e, "status") and e.status == 422:
573+
raise ValueError(
574+
f"The Experiment name '{name}' is invalid. It must use only lowercase "
575+
f"alphanumeric characters ('a-z', '0-9'), hyphens ('-'), or periods ('.'). "
576+
f"It must also start and end with an alphanumeric character."
577+
)
578+
elif hasattr(e, "status") and e.status == 409:
579+
print(f"PVC '{name}' already exists in namespace " f"{namespace}.")
582580
else:
583581
raise RuntimeError(f"failed to create PVC. Error: {e}")
584582

sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ def create_experiment(
310310
},
311311
ValueError,
312312
),
313+
(
314+
"invalid name format",
315+
{
316+
"name": "Llama3.1-fine-tune",
317+
},
318+
ValueError,
319+
),
313320
(
314321
"invalid hybrid parameters - objective and model_provider_parameters",
315322
{

0 commit comments

Comments
 (0)