diff --git a/Tests/kaas/plugin/plugin_cluster_stacks.py b/Tests/kaas/plugin/plugin_cluster_stacks.py index 5183127d8..e25a63780 100644 --- a/Tests/kaas/plugin/plugin_cluster_stacks.py +++ b/Tests/kaas/plugin/plugin_cluster_stacks.py @@ -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 @@ -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