From 1102aa8470e420b0569cde4c0726857365c2a5fc Mon Sep 17 00:00:00 2001 From: hzeng21 Date: Mon, 16 Oct 2023 17:08:56 -0400 Subject: [PATCH] Add simple counter to bypass infinite loop for cluster set up testing --- acto/kubernetes_engine/kind.py | 7 ++++--- acto/kubernetes_engine/minikube.py | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/acto/kubernetes_engine/kind.py b/acto/kubernetes_engine/kind.py index bcdc37b110..44af39a879 100644 --- a/acto/kubernetes_engine/kind.py +++ b/acto/kubernetes_engine/kind.py @@ -94,11 +94,12 @@ def create_cluster(self, name: str, kubeconfig: str): if self._k8s_version != "": cmd.extend(['--image', f"kindest/node:{self._k8s_version}"]) - + i = 3 + p = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - while p.returncode != 0: - # TODO: retry for three times + while p.returncode != 0 and i != 0: logging.error('Failed to create kind cluster, retrying') + i -= 1 self.delete_cluster(name, kubeconfig) time.sleep(5) p = subprocess.run(cmd) diff --git a/acto/kubernetes_engine/minikube.py b/acto/kubernetes_engine/minikube.py index 011a120ba2..d600637e26 100644 --- a/acto/kubernetes_engine/minikube.py +++ b/acto/kubernetes_engine/minikube.py @@ -60,8 +60,11 @@ def create_cluster(self, name: str, kubeconfig: str): if self._k8s_version != "": cmd.extend(['--kubernetes-version', str(self._k8s_version)]) p = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - while p.returncode != 0: + + i = 1 + while p.returncode != 0 and i != 0: logging.error('Failed to create minikube cluster, retrying') + i -= 1 self.delete_cluster(name, kubeconfig) time.sleep(5) p = subprocess.run(cmd)