2828from kubernetes import client , config
2929from kubernetes .client import ApiException
3030
31-
3231SIGNATURE_ANNOTATION = "dual-pods.llm-d.ai/vllm-instance-signature"
3332
3433DEFAULT_BASE_URL = "http://127.0.0.1:8001"
@@ -73,7 +72,9 @@ def canonicalize_launcher_state(payload: dict[str, Any]) -> dict[str, Any]:
7372 canonical_instances .append ({"instance_id" : instance_id , "status" : status })
7473 canonical_instances .sort (key = lambda item : (item ["instance_id" ], item ["status" ]))
7574 return {
76- "total_instances" : int (payload .get ("total_instances" , len (canonical_instances ))),
75+ "total_instances" : int (
76+ payload .get ("total_instances" , len (canonical_instances ))
77+ ),
7778 "running_instances" : int (payload .get ("running_instances" , 0 )),
7879 "instances" : canonical_instances ,
7980 }
@@ -90,7 +91,9 @@ def load_incluster_client() -> client.CoreV1Api:
9091 return client .CoreV1Api ()
9192
9293
93- def get_pod_annotations (api : client .CoreV1Api , namespace : str , pod_name : str ) -> dict [str , str ]:
94+ def get_pod_annotations (
95+ api : client .CoreV1Api , namespace : str , pod_name : str
96+ ) -> dict [str , str ]:
9497 pod = api .read_namespaced_pod (name = pod_name , namespace = namespace )
9598 return pod .metadata .annotations or {}
9699
@@ -112,7 +115,9 @@ def patch_pod_annotations(
112115 api .patch_namespaced_pod (name = pod_name , namespace = namespace , body = body )
113116
114117
115- def publish_if_changed (api : client .CoreV1Api , namespace : str , pod_name : str , signature : str ) -> None :
118+ def publish_if_changed (
119+ api : client .CoreV1Api , namespace : str , pod_name : str , signature : str
120+ ) -> None :
116121 annotations = get_pod_annotations (api , namespace , pod_name )
117122 if annotations .get (SIGNATURE_ANNOTATION , "" ) == signature :
118123 return
0 commit comments