Skip to content

Commit e5952c0

Browse files
Fix error: no matching resources found when waiting for pods in workload cluster
Signed-off-by: michal.gubricky <[email protected]>
1 parent d5910f1 commit e5952c0

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Tests/kaas/plugin/plugin_cluster_stacks.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def wait_for_cso_pods_ready(timeout=240, interval=15):
114114
raise TimeoutError(f"Timed out after {timeout} seconds waiting for CSO pods in 'cso-system' namespace to become ready.")
115115

116116

117-
def wait_for_workload_pods_ready(namespace="kube-system", timeout=600, kubeconfig_path=None):
117+
def wait_for_workload_pods_ready(namespace="kube-system", timeout=600, kubeconfig_path=None, max_retries=3, delay=30):
118118
"""
119119
Waits for all pods in a specific namespace on a workload Kubernetes cluster to become ready.
120120
@@ -123,18 +123,23 @@ def wait_for_workload_pods_ready(namespace="kube-system", timeout=600, kubeconfi
123123
:param kubeconfig_path: Path to the kubeconfig file for the target Kubernetes cluster.
124124
:raises RuntimeError: If pods are not ready within the specified timeout.
125125
"""
126-
try:
127-
kubeconfig_option = f"--kubeconfig {kubeconfig_path}" if kubeconfig_path else ""
128-
wait_pods_command = (
129-
f"kubectl wait -n {namespace} --for=condition=Ready --timeout={timeout}s pod --all {kubeconfig_option}"
130-
)
126+
for attempt in range(max_retries):
127+
try:
128+
kubeconfig_option = f"--kubeconfig {kubeconfig_path}" if kubeconfig_path else ""
129+
wait_pods_command = (
130+
f"kubectl wait -n {namespace} --for=condition=Ready --timeout={timeout}s pod --all {kubeconfig_option}"
131+
)
131132

132-
# Run the command
133-
subprocess.run(wait_pods_command, shell=True, check=True)
134-
logger.info("All pods in namespace '{namespace}' in the workload Kubernetes cluster are ready.")
133+
# Run the command
134+
subprocess.run(wait_pods_command, shell=True, check=True)
135+
logger.info(f"All pods in namespace {namespace} in the workload Kubernetes cluster are ready.")
136+
return True
137+
138+
except subprocess.CalledProcessError as error:
139+
logger.warning(f"Attempt {attempt+1}/{max_retries} failed with error: {error}. Retrying in {delay} seconds...")
140+
time.sleep(delay)
135141

136-
except subprocess.CalledProcessError as error:
137-
raise RuntimeError(f"Error waiting for pods in namespace '{namespace}' to become ready: {error}")
142+
raise RuntimeError(f"Error waiting for pods in namespace '{namespace}' to become ready.")
138143

139144

140145
def load_config(config_path):
@@ -270,7 +275,7 @@ def create_cluster(self, cluster_name="scs-cluster", version=None, kubeconfig_fi
270275
print(self.kubeconfig_cs_cluster_filename)
271276
wait_for_workload_pods_ready(kubeconfig_path=self.kubeconfig_cs_cluster_filename)
272277

273-
def delete_cluster(self, cluster_name=None, kubeconfig_filepath=None):
278+
def delete_cluster(self, cluster_name=None, version=None, kubeconfig_filepath=None):
274279
kubeconfig_cs_cluster_filename = f"kubeconfig-{cluster_name}.yaml"
275280
try:
276281
# Check if the cluster exists

0 commit comments

Comments
 (0)