Skip to content

Commit 6ae0ec3

Browse files
Add wait for the clusterstack resource
Signed-off-by: michal.gubricky <[email protected]>
1 parent e015cd4 commit 6ae0ec3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def create_cluster(self, cluster_name, version, kubeconfig_filepath):
139139
# Create cluster-stack resource
140140
self._apply_yaml(self.clusterstack, "Error applying clusterstack.yaml", kubeconfig=self.kubeconfig_mgmnt)
141141

142+
# Wait for cluster-stack resource to be ready
143+
self._wait_for_clusterstack_ready(namespace=self.cs_namespace, timeout=600)
144+
142145
# Create workload cluster
143146
self._apply_yaml(
144147
self.workloadclusters,
@@ -202,6 +205,26 @@ def _apply_yaml(self, yaml_file, error_msg, kubeconfig=None):
202205
except subprocess.CalledProcessError as error:
203206
raise RuntimeError(f"{error_msg}: {error}")
204207

208+
def _wait_for_clusterstack_ready(self, namespace, timeout=600):
209+
"""
210+
Waits for the clusterstack resource in the management cluster to reach the condition 'Ready'.
211+
212+
:param namespace: The namespace to search for the clusterstack resource.
213+
:param timeout: The maximum time to wait in seconds.
214+
:raises RuntimeError: If the clusterstack resource does not become ready within the timeout.
215+
"""
216+
try:
217+
command = f"kubectl wait clusterstack/clusterstack -n {namespace} --for=condition=Ready --timeout={timeout}s"
218+
self._run_subprocess(
219+
command,
220+
"Error waiting for clusterstack to be ready",
221+
shell=True,
222+
kubeconfig=self.kubeconfig_mgmnt
223+
)
224+
logger.info("Clusterstack is ready.")
225+
except subprocess.CalledProcessError as error:
226+
raise RuntimeError(f"Clusterstack did not become ready within {timeout} seconds: {error}")
227+
205228
def _get_kubeadm_control_plane_name(self, namespace="default", kubeconfig=None):
206229
"""
207230
Retrieves the name of the KubeadmControlPlane resource for the Kubernetes cluster

0 commit comments

Comments
 (0)