[skip ci]Add function to get pod list (#12990)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
pull/12999/head
zhuwenxing 2021-12-08 17:55:14 +08:00 committed by GitHub
parent 2e84eef229
commit ad9422ee7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 1 deletions

View File

@ -55,5 +55,29 @@ def wait_pods_ready(namespace, label_selector, expected_num=None, timeout=360):
return all_pos_ready_flag
def get_pod_list(namespace, label_selector):
"""
get pod list with label selector
:param namespace: the namespace where the release
:type namespace: str
:param label_selector: labels to restrict which pods to list
:type label_selector: str
:example:
>>> get_pod_list("chaos-testing", "app.kubernetes.io/instance=test-proxy-pod-failure, component=proxy")
"""
config.load_kube_config()
api_instance = client.CoreV1Api()
try:
api_response = api_instance.list_namespaced_pod(namespace=namespace, label_selector=label_selector)
return api_response.items
except ApiException as e:
log.error("Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e)
raise Exception(str(e))
if __name__ == '__main__':
wait_pods_ready("chaos-testing", "app.kubernetes.io/instance=scale-query")
label = "app.kubernetes.io/instance=test-proxy-pod-failure, component=proxy"
res = get_pod_list("chaos-testing", label_selector=label)