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 <michal.gubricky@dnation.cloud>
  • Loading branch information
michal-gubricky committed Nov 22, 2024
1 parent 7925baa commit c7837ad
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Tests/kaas/plugin/plugin_cluster_stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ def create_cluster(self, cluster_name, version, kubeconfig_filepath):

wait_for_pods(self, ["cso-system"], kubeconfig=self.kubeconfig_mgmnt)

# Create Cluster Stack definition and workload cluster
# Create cluster-stack definition
self._apply_yaml_with_envsubst("clusterstack.yaml", "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_with_envsubst("cluster.yaml", "Error applying cluster.yaml", kubeconfig=self.kubeconfig_mgmnt)

# Get and wait on kubeadmcontrolplane and retrieve workload cluster kubeconfig
Expand Down Expand Up @@ -236,6 +241,26 @@ def _apply_yaml_with_envsubst(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 c7837ad

Please sign in to comment.