code: def wait_pods_ready(
      namespace, label_selector, expected_num=None, timeout=360
  ):
      """
      wait pods with label selector all ready
  
      :param namespace: the namespace where the release
      :type namespace: str
  
      :param label_selector: labels to restrict which pods are waiting to be ready
      :type label_selector: str
  
      :param expected_num: expected the minimum number of pods to be ready if not None
      :type expected_num: int
  
      :param timeout: limits the duration of the call
      :type timeout: int
  
      :example:
              >>> wait_pods_ready("default", "app.kubernetes.io/instance=scale-query", expected_num=9)
      """
      init_k8s_client_config()
      api_instance = client.CoreV1Api()
      try:
          all_pos_ready_flag = False
          t0 = time.time()
          while not all_pos_ready_flag and time.time() - t0 < timeout:
              api_response = api_instance.list_namespaced_pod(
                  namespace=namespace, label_selector=label_selector
              )
              all_pos_ready_flag = True
              if (
                  expected_num is not None
                  and len(api_response.items) < expected_num
              ):
                  all_pos_ready_flag = False
              else:
                  for item in api_response.items:
                      if item.status.phase != "Running":
                          all_pos_ready_flag = False
                          break
                      for c in item.status.container_statuses:
                          log.debug(f"{c.name} status is {c.ready}")
                          if c.ready is False:
                              all_pos_ready_flag = False
                              break
              if not all_pos_ready_flag:
                  log.debug("all pods are not ready, please wait")
                  time.sleep(5)
          if all_pos_ready_flag:
              log.info(
                  f"all pods in namespace {namespace} with label {label_selector} are ready"
              )
          else:
              log.info(
                  f"timeout for waiting all pods in namespace {namespace} with label {label_selector} ready"
              )
      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
  
imports: import json
  import os.path
  import time
  import pyetcd
  import requests
  from pymilvus import connections
  from kubernetes import client, config
  from kubernetes.client.rest import ApiException
  from common.milvus_sys import MilvusSys
  from utils.util_log import test_log
  from chaos import chaos_commons
  from common.common_type import in_cluster_env
label_desc: Use image node_id 3 for calling a global function with example usage: wait_pods_ready(namespace, label_selector, expected_num, timeout) and returns: all_pos_ready_flag