From bbcd7073352cd1945b1078f307833340d2546b5b Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Fri, 8 Mar 2024 15:35:56 +0800 Subject: [PATCH] fix(negative): ApiException during node_exec.launch_pod Signed-off-by: Chin-Ya Huang --- e2e/libs/node_exec/node_exec.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/e2e/libs/node_exec/node_exec.py b/e2e/libs/node_exec/node_exec.py index b8e5bb2543..5c8ec008d5 100644 --- a/e2e/libs/node_exec/node_exec.py +++ b/e2e/libs/node_exec/node_exec.py @@ -1,6 +1,7 @@ import time from kubernetes import client +from kubernetes.client.rest import ApiException from kubernetes.stream import stream from node_exec.constant import DEFAULT_POD_INTERVAL @@ -91,13 +92,17 @@ def issue_cmd(self, node_name, cmd): def launch_pod(self, node_name): if node_name in self.node_exec_pod: - for i in range(DEFAULT_POD_TIMEOUT): - pod = self.core_api.read_namespaced_pod( - name=node_name, - namespace=self.namespace - ) - if pod is not None and pod.status.phase == 'Running': - break + for _ in range(DEFAULT_POD_TIMEOUT): + try: + pod = self.core_api.read_namespaced_pod( + name=node_name, + namespace=self.namespace + ) + if pod is not None and pod.status.phase == 'Running': + break + except ApiException as e: + assert e.status == 404 + time.sleep(DEFAULT_POD_INTERVAL) return pod else: