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 5 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
5 changes: 5 additions & 0 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ class name in this argument.
),
)
except Exception as e:
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"An Experiment with the name {name} is not valid."
)

pvc_list = self.core_api.list_namespaced_persistent_volume_claim(
Copy link
Member

Choose a reason for hiding this comment

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

Should we also simplify this logic similar to this one:

raise Exception(
f"A Katib Experiment with the name "
f"{namespace}/{experiment_name} already exists."
)

E.g. if status_code is 409 we just print that PVC already exists.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

If we add more details to the error message, it’ll make it easier for users to understand, which is the goal of this PR. But you’re right—Kubernetes API will also return detailed error reasons. So it depends on whether we want to keep the error messages consistent across the board.

Copy link
Member Author

Choose a reason for hiding this comment

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

My opinion is a bit more leaned to Helens. But I'm open to any changes.

Copy link
Member

Choose a reason for hiding this comment

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

I just meant that all of these:

                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
                else:
                    raise RuntimeError(f"failed to create PVC. Error: {e}")

can be replaced to

                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}")

Does it make sense ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, SGTM 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, agreed.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

namespace=namespace
)
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,
),
(
"wrong name format",
{
"name": "Llama3.1-fine-tune",
},
ValueError,
),
(
"invalid hybrid parameters - objective and model_provider_parameters",
{
Expand Down
Loading