Skip to content

Commit e832967

Browse files
author
Vitaliy Zakaznikov
committed
Converting to treat composite labels as meta labels.
1 parent 5943922 commit e832967

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

testflows/github/hetzner/runners/scale_up.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,12 @@ def get_server_types(labels: set[str], default: ServerType, label_prefix: str =
272272
for label in labels:
273273
label = label.lower()
274274
if label.startswith(label_prefix):
275-
server_type_names = label.split(label_prefix, 1)[-1].lower().split("-")
276-
for server_type_name in server_type_names:
277-
server_type = ServerType(name=server_type_name)
278-
server_types.append(server_type)
275+
server_type_name = label.split(label_prefix, 1)[-1].lower()
276+
if "-" in server_type_name:
277+
# skip composite label
278+
continue
279+
server_type = ServerType(name=server_type_name)
280+
server_types.append(server_type)
279281

280282
if not server_types:
281283
server_types = [default]
@@ -301,10 +303,12 @@ def get_server_locations(
301303
for label in labels:
302304
label = label.lower()
303305
if label.startswith(label_prefix):
304-
server_location_names = label.split(label_prefix, 1)[-1].lower().split("-")
305-
for server_location_name in server_location_names:
306-
server_location = Location(name=server_location_name)
307-
server_locations.append(server_location)
306+
server_location_name = label.split(label_prefix, 1)[-1].lower()
307+
if "-" in server_location_name:
308+
# skip composite label
309+
continue
310+
server_location = Location(name=server_location_name)
311+
server_locations.append(server_location)
308312

309313
if not server_locations:
310314
server_locations = [default]
@@ -499,6 +503,10 @@ def expand_meta_label(
499503
"""Expand any meta labels."""
500504
expanded_labels = []
501505
label_prefix = label_prefix.lower()
506+
composite_labels = ["type-", "in-"]
507+
508+
if label_prefix and not label_prefix.endswith("-"):
509+
label_prefix += "-"
502510

503511
for label in labels:
504512
label = label.lower()
@@ -507,6 +515,15 @@ def expand_meta_label(
507515
raw_label = label.split(label_prefix, 1)[-1] if label_prefix else label
508516
if raw_label in meta_label:
509517
expanded_labels += list(meta_label[label])
518+
for composite_label in composite_labels:
519+
if raw_label.startswith(composite_label):
520+
composite_values = (
521+
raw_label.split(composite_label, 1)[-1].lower().split("-")
522+
)
523+
for composite_value in composite_values:
524+
expanded_labels.append(
525+
f"{label_prefix}{composite_label}{composite_value}"
526+
)
510527

511528
return set(expanded_labels)
512529

0 commit comments

Comments
 (0)