Skip to content

Commit

Permalink
Add wait for the clusterstack resource
Browse files Browse the repository at this point in the history
Signed-off-by: michal.gubricky <[email protected]>
  • Loading branch information
michal-gubricky committed Nov 22, 2024
1 parent e015cd4 commit 6ae0ec3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def create_cluster(self, cluster_name, version, kubeconfig_filepath):
# Create cluster-stack resource
self._apply_yaml(self.clusterstack, "Error applying clusterstack.yaml", kubeconfig=self.kubeconfig_mgmnt)

# Wait for cluster-stack resource to be ready
self._wait_for_clusterstack_ready(namespace=self.cs_namespace, timeout=600)

# Create workload cluster
self._apply_yaml(
self.workloadclusters,
Expand Down Expand Up @@ -202,6 +205,26 @@ def _apply_yaml(self, yaml_file, error_msg, kubeconfig=None):
except subprocess.CalledProcessError as error:
raise RuntimeError(f"{error_msg}: {error}")

def _wait_for_clusterstack_ready(self, namespace, timeout=600):
"""
Waits for the clusterstack resource in the management cluster to reach the condition 'Ready'.
:param namespace: The namespace to search for the clusterstack resource.
:param timeout: The maximum time to wait in seconds.
:raises RuntimeError: If the clusterstack resource does not become ready within the timeout.
"""
try:
command = f"kubectl wait clusterstack/clusterstack -n {namespace} --for=condition=Ready --timeout={timeout}s"
self._run_subprocess(
command,
"Error waiting for clusterstack to be ready",
shell=True,
kubeconfig=self.kubeconfig_mgmnt
)
logger.info("Clusterstack is ready.")
except subprocess.CalledProcessError as error:
raise RuntimeError(f"Clusterstack did not become ready within {timeout} seconds: {error}")

def _get_kubeadm_control_plane_name(self, namespace="default", kubeconfig=None):
"""
Retrieves the name of the KubeadmControlPlane resource for the Kubernetes cluster
Expand Down

0 comments on commit 6ae0ec3

Please sign in to comment.