Skip to content
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: 3 additions & 1 deletion task_processing/plugins/kubernetes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ def get_sanitised_kubernetes_name(
# the part of the name that does fit in the limit in order to replace them with
# -- (2 characters) and then a 4 character hash (which should help ensure uniqueness
# after truncation).
truncated_name = name[0 : length_limit - 6]
name = (
name[0 : length_limit - 6]
# Avoid splitting the suffix into a subdomain as it would not meet RFC1123 requirements
truncated_name.rstrip(".")
+ "--"
+ hashlib.md5(name.encode("ascii")).hexdigest()[:4]
)
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/plugins/kubernetes/kubernetes_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,39 @@ def test_get_capabilities_for_capability_changes(cap_add, cap_drop, expected):


@pytest.mark.parametrize(
"name,expected_name",
"name,expected_name,length_limit",
(
(
"hello_world",
"hello--world",
0,
),
(
"hello_world",
"hello--world",
0,
),
(
"--hello_world",
"underscore-hello--world",
0,
),
(
"TeSt",
"test",
0,
),
(
"hello--world.123.run",
"hello--world--cf28",
19,
),
),
)
def test_get_sanitised_kubernetes_name(name, expected_name):
assert get_sanitised_kubernetes_name(name) == expected_name
def test_get_sanitised_kubernetes_name(name, expected_name, length_limit):
assert (
get_sanitised_kubernetes_name(name, length_limit=length_limit) == expected_name
)


@pytest.mark.parametrize(
Expand Down