mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
[skip ci]Add func to wait pods ready (#12408)
Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
This commit is contained in:
parent
2f1bc9a170
commit
cbfa446062
@ -2,6 +2,7 @@ from __future__ import print_function
|
||||
from kubernetes import client, config
|
||||
from kubernetes.client.rest import ApiException
|
||||
from utils.util_log import test_log as log
|
||||
import time
|
||||
|
||||
_GROUP = 'milvus.io'
|
||||
_VERSION = 'v1alpha1'
|
||||
@ -96,3 +97,36 @@ class CustomResourceOperations(object):
|
||||
for item in cus_objects["items"]:
|
||||
metadata_name = item["metadata"]["name"]
|
||||
self.delete(metadata_name)
|
||||
|
||||
def wait_pods_ready(self, namespace, label_selector):
|
||||
"""wait pods with label selector all ready"""
|
||||
config.load_kube_config()
|
||||
api_instance = client.CoreV1Api()
|
||||
try:
|
||||
all_pos_ready_flag = False
|
||||
timeout = 0
|
||||
while (not all_pos_ready_flag and timeout < 360):
|
||||
api_response = api_instance.list_namespaced_pod(namespace=namespace,label_selector=label_selector)
|
||||
all_pos_ready_flag = True
|
||||
for item in api_response.items:
|
||||
print(item.status.phase)
|
||||
for c in item.status.container_statuses:
|
||||
print(c.name)
|
||||
print(c.ready)
|
||||
log.info(f"{c.name} statu is {c.ready}")
|
||||
if c.ready is False:
|
||||
all_pos_ready_flag = False
|
||||
break
|
||||
if not all_pos_ready_flag:
|
||||
log.info("all pods are not ready, please wait")
|
||||
time.sleep(30)
|
||||
timeout += 30
|
||||
if all_pos_ready_flag:
|
||||
log.info(f"all pods in namespace {namespace} with label {label_selector} are ready")
|
||||
else:
|
||||
log.info("timeout for waiting all pods in namespace {namespace} with label {label_selector} ready")
|
||||
log.debug(f"list pods response: {api_response}")
|
||||
except ApiException as e:
|
||||
log.error("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e)
|
||||
raise Exception(str(e))
|
||||
return all_pos_ready_flag
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user