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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,20 @@ class name in this argument.
# Create PVC for the Storage Initializer.
# TODO (helenxie-bit): PVC Creation should be part of Katib Controller.
try:
if not utils.is_valid_pvc_name(name):
raise ValueError(
f"""
Invalid PVC name '{name}'. It must comply with RFC 1123.

A lowercase RFC 1123 subdomain must consist of lowercase
alphanumeric characters, '-' or '.',
and must start and end with an alphanumeric character.
For example, 'example.com' is valid.
The regex used for validation is:
'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
"""
)

self.core_api.create_namespaced_persistent_volume_claim(
namespace=namespace,
body=training_utils.get_pvc_spec(
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/v1beta1/kubeflow/katib/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
import logging
import os
import re
import textwrap
from typing import Any, Callable, Dict, List, Optional, Union

Expand Down Expand Up @@ -267,3 +268,12 @@ def get_exec_script_from_objective(

# Return executable script to execute objective function.
return exec_script


def is_valid_pvc_name(name: str) -> bool:
# RFC 1123 regex for valid PVC names: lowercase alphanumeric, '-', or '.'.
return bool(
re.match(
r"^[a-z0-9]([a-z0-9\-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9\-]*[a-z0-9])?)*$", name
Copy link
Contributor

Choose a reason for hiding this comment

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

Would using the same regex format as shown in the error message improve readability and maintainability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would you please elaborate what you mean here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean using this regex format in the ValueError message: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*', since it took me a while to compare if they stand for the same thing. Or is there specific reason you changed the format a little bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, thanks for bringing this to my attention. shall i add any unit test for it? please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, there are two failing ci tests, i'm guessing they are flaky tests, would there be any problem that this change have caused?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the unit tests for tune API is still under review, I think you can add your unit test after that one is merged.

Copy link
Contributor

@helenxie-bit helenxie-bit Jan 21, 2025

Choose a reason for hiding this comment

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

I think the CI test failures are caused by resource problems. I've rerun the tests once, but one of them still failed due to network connectivity issue. Maybe we can try running them again later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for your time and help in this matter.

)
)
Loading