Skip to content

Commit

Permalink
[k8s] Handle long node names in GPU Labeler (#2795)
Browse files Browse the repository at this point in the history
* Fix long nodename

* lint
  • Loading branch information
romilbhardwaj authored Nov 18, 2023
1 parent 623c10d commit 77a32d2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sky/utils/kubernetes/gpu_labeler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Script to label GPU nodes in a Kubernetes cluster for use with SkyPilot"""
import argparse
import hashlib
import os
import subprocess
from typing import Tuple
Expand Down Expand Up @@ -54,6 +55,12 @@ def cleanup() -> Tuple[bool, str]:
return success, reason


def get_node_hash(node_name: str):
# Generates a 32 character md5 hash from a string
md5_hash = hashlib.md5(node_name.encode()).hexdigest()
return md5_hash[:32]


def label():
deletion_success, reason = cleanup()
if not deletion_success:
Expand Down Expand Up @@ -102,7 +109,8 @@ def label():
node_name = node.metadata.name

# Modify the job manifest for the current node
job_manifest['metadata']['name'] = f'sky-gpu-labeler-{node_name}'
job_manifest['metadata']['name'] = ('sky-gpu-labeler-'
f'{get_node_hash(node_name)}')
job_manifest['spec']['template']['spec']['nodeSelector'] = {
'kubernetes.io/hostname': node_name
}
Expand Down

0 comments on commit 77a32d2

Please sign in to comment.