@@ -166,8 +166,13 @@ def create_cluster(self, cluster_name, version, kubeconfig_filepath):
166166
167167 wait_for_pods (self , ["cso-system" ], kubeconfig = self .kubeconfig_mgmnt )
168168
169- # Create Cluster Stack definition and workload cluster
169+ # Create cluster-stack definition
170170 self ._apply_yaml_with_envsubst ("clusterstack.yaml" , "Error applying clusterstack.yaml" , kubeconfig = self .kubeconfig_mgmnt )
171+
172+ # Wait for cluster-stack resource to be ready
173+ self ._wait_for_clusterstack_ready (namespace = self .cs_namespace , timeout = 600 )
174+
175+ # Create workload cluster
171176 self ._apply_yaml_with_envsubst ("cluster.yaml" , "Error applying cluster.yaml" , kubeconfig = self .kubeconfig_mgmnt )
172177
173178 # 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):
236241 except subprocess .CalledProcessError as error :
237242 raise RuntimeError (f"{ error_msg } : { error } " )
238243
244+ def _wait_for_clusterstack_ready (self , namespace , timeout = 600 ):
245+ """
246+ Waits for the clusterstack resource in the management cluster to reach the condition 'Ready'.
247+
248+ :param namespace: The namespace to search for the clusterstack resource.
249+ :param timeout: The maximum time to wait in seconds.
250+ :raises RuntimeError: If the clusterstack resource does not become ready within the timeout.
251+ """
252+ try :
253+ command = f"kubectl wait clusterstack/clusterstack -n { namespace } --for=condition=Ready --timeout={ timeout } s"
254+ self ._run_subprocess (
255+ command ,
256+ "Error waiting for clusterstack to be ready" ,
257+ shell = True ,
258+ kubeconfig = self .kubeconfig_mgmnt
259+ )
260+ logger .info ("Clusterstack is ready." )
261+ except subprocess .CalledProcessError as error :
262+ raise RuntimeError (f"Clusterstack did not become ready within { timeout } seconds: { error } " )
263+
239264 def _get_kubeadm_control_plane_name (self , namespace = "default" , kubeconfig = None ):
240265 """
241266 Retrieves the name of the KubeadmControlPlane resource for the Kubernetes cluster
0 commit comments