in gke-topology-scheduler/schedule-daemon.py [0:0]
def pod_sorting_key(pod_info: dict[str, Any]) -> tuple[str, int]:
"""Returns key/rank to be used for sorting pods.
Given that numbers is often suffixed for multi-node deployments,
here we use a (prefix, number) tuple for the sorting key.
This means "xxx-pod2" should appear before "xxx-pod10"
Args:
pod_info: The pod info.
Returns:
A tuple of the pod's prefix and index.
"""
try:
index_value = pod_info.get('index')
if index_value is not None:
return int(index_value)
except (ValueError, TypeError) as e:
logging.exception(
'Error converting %s pod index to integer: %s', pod_info['name'], e
)
# if the suffix is a number, extract it from the name
name = pod_info['name']
if match := re.fullmatch(r'^(.*?)(\d+)$', name):
prefix, suffix = match.groups()
return (prefix, int(suffix))
else:
logging.warning(
'Pod %s does not have a numeric suffix. Using 0 as index.', name
)
return (name, 0) # No numeric suffix