Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] improve PVC creation name error #2496

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should move this check after this line since the error belongs to that scenario:


Additionally, to make the error easier to understand, we could tweak the error message a bit. How about this:

if hasattr(e, "status") and e.status == 422:
    raise ValueError(
        f"An Experiment with the name {name} is not valid: the name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
    )
else:
    raise RuntimeError(f"failed to create PVC. Error: {e}")

Copy link
Member Author

@mahdikhashan mahdikhashan Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the ValueError message (with a bit of change), with combining it with else, not really - since then we need to wait for this steps first:

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

so my idea is the function fails fast when the name is invalid then if its valid, continues with the check for the existence of the name. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

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