[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]>
This commit is contained in:
Mahdi Khashan
2025-01-28 00:32:50 +00:00
committed by GitHub
parent 666fac60e7
commit bcdbce7e0f
2 changed files with 15 additions and 10 deletions
@@ -569,16 +569,14 @@ class KatibClient(object):
),
)
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}")
@@ -310,6 +310,13 @@ test_tune_data = [
},
ValueError,
),
(
"invalid name format",
{
"name": "Llama3.1-fine-tune",
},
ValueError,
),
(
"invalid hybrid parameters - objective and model_provider_parameters",
{