Use read_namespaced_pod to get a pod

Use read_namespaced_pod instead of list_namespaced_pod

Change-Id: Ic01a0f5e75fb1f4228d508a2e9e67b55567311e4
This commit is contained in:
Itzik Brown 2018-09-20 12:59:45 +00:00
parent 3bfaa82c66
commit 3432ed77c5
1 changed files with 25 additions and 22 deletions

View File

@ -151,35 +151,38 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
@classmethod @classmethod
def get_pod_ip(cls, pod_name, namespace="default"): def get_pod_ip(cls, pod_name, namespace="default"):
pod_list = cls.k8s_client.CoreV1Api().list_namespaced_pod( try:
namespace=namespace) pod = cls.k8s_client.CoreV1Api().read_namespaced_pod(pod_name,
for pod in pod_list.items: namespace)
if pod.metadata.name == pod_name: return pod.status.pod_ip
return pod.status.pod_ip except kubernetes.client.rest.ApiException:
return None
@classmethod @classmethod
def get_pod_status(cls, pod_name, namespace="default"): def get_pod_status(cls, pod_name, namespace="default"):
pod_list = cls.k8s_client.CoreV1Api().list_namespaced_pod( try:
namespace=namespace) pod = cls.k8s_client.CoreV1Api().read_namespaced_pod(pod_name,
for pod in pod_list.items: namespace)
if pod.metadata.name == pod_name: return pod.status.phase
return pod.status.phase except kubernetes.client.rest.ApiException:
return None
@classmethod @classmethod
def get_readiness_state(cls, pod_name, namespace="default", def get_readiness_state(cls, pod_name, namespace="default",
container_name=None): container_name=None):
pod_list = cls.k8s_client.CoreV1Api().list_namespaced_pod( try:
namespace=namespace) pod = cls.k8s_client.CoreV1Api().read_namespaced_pod(pod_name,
for pod in pod_list.items: namespace)
if pod.metadata.name == pod_name: if container_name:
if container_name: for container in pod.status.container_statuses:
for container in pod.status.container_statuses: if container.name == container_name:
if container.name == container_name: return container.ready
return container.ready else:
else: for condition in pod.status.conditions:
for condition in pod.status.conditions: if condition.type == 'Ready':
if condition.type == 'Ready': return condition.status
return condition.status except kubernetes.client.rest.ApiException:
return None
@classmethod @classmethod
def get_pod_readiness(cls, pod_name, namespace="default"): def get_pod_readiness(cls, pod_name, namespace="default"):