Skip to content

Commit

Permalink
[SDK] improve PVC creation name error (#2496)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mahdikhashan authored Jan 28, 2025
1 parent 0133983 commit 09523cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 8 additions & 10 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
7 changes: 7 additions & 0 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down

0 comments on commit 09523cd

Please sign in to comment.