Skip to content

Commit 9e9b744

Browse files
authored
🐛 trim k8s labels to 63 characters (#97)
1 parent 16e5cb6 commit 9e9b744

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

dagster_ray/kuberay/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
def normalize_k8s_label_values(labels: dict[str, str]) -> dict[str, str]:
55
# prevent errors like:
66
# Invalid value: \"daniel@anam.ai\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
7+
# and comply with the 63 character limit
78

89
cleanup_regex = re.compile(r"[^a-zA-Z0-9-_.]+")
910

1011
for key, value in labels.items():
1112
# daniel~!@my.domain -> daniel-my-domain
12-
labels[key] = cleanup_regex.sub("", value.replace("@", "-").replace(".", "-"))
13+
labels[key] = cleanup_regex.sub("", value.replace("@", "-").replace(".", "-"))[:63]
1314

1415
return labels

tests/kuberay/test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ def test_normalize_k8s_label_values():
99
"user": "daniel@my.org",
1010
"user-dirty": "daniel!`~@my.org",
1111
"alphanumeric": "abc123",
12+
"long": 64 * "a",
1213
}
1314
) == {
1415
"foo": "bar",
1516
"my/label": "myvalue",
1617
"user": "daniel-my-org",
1718
"user-dirty": "daniel-my-org",
1819
"alphanumeric": "abc123",
20+
"long": 63 * "a",
1921
}

0 commit comments

Comments
 (0)