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

Allow underscores in custom GCP tags #2065

Merged
merged 1 commit into from
Dec 6, 2024
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
4 changes: 2 additions & 2 deletions src/dstack/_internal/core/backends/gcp/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def _is_valid_label(key: str, value: str) -> bool:
return is_valid_resource_name(key) and is_valid_label_value(value)


NAME_PATTERN = re.compile(r"^[a-z]([-a-z0-9]*[a-z0-9])?$")
LABEL_VALUE_PATTERN = re.compile(r"^[-a-z0-9]{0,63}$")
NAME_PATTERN = re.compile(r"^[a-z][_\-a-z0-9]{0,62}$")
LABEL_VALUE_PATTERN = re.compile(r"^[_\-a-z0-9]{0,63}$")


def is_valid_resource_name(name: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/tests/_internal/core/backends/aws/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestIsValidTagKey:
[
"Environment",
"Project123",
"special-chars-+/@=:",
"special-chars-+/@=:_",
"a" * 128,
],
)
Expand Down
4 changes: 1 addition & 3 deletions src/tests/_internal/core/backends/gcp/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class TestIsValidResourceName:
"a" * 64,
"-startswithdash",
"1startswithdigit",
"asd_asd",
"Uppercase",
],
)
def test_invalid_name(self, name):
assert not gcp_resources.is_valid_resource_name(name)

@pytest.mark.parametrize("name", ["a", "some-name-with-dashes-123"])
@pytest.mark.parametrize("name", ["a", "some-name-with-dashes-123", "asd_asd"])
def test_valid_name(self, name):
assert gcp_resources.is_valid_resource_name(name)

Expand All @@ -47,7 +46,6 @@ class TestIsValidLabelValue:
"name",
[
"a" * 64,
"asd_asd",
"Uppercase",
],
)
Expand Down
Loading