1212
1313
1414# Helper functions
15- def wait_for_capi_pods_ready ( timeout = 240 , interval = 15 ):
15+ def wait_for_pods ( namespaces , timeout = 240 , interval = 15 ):
1616 """
17- Waits for all CAPI pods in specific namespaces to reach the 'Running' state with all containers ready.
17+ Waits for all pods in specified namespaces to reach the 'Running' state with all containers ready.
1818
19+ :param namespaces: List of namespaces to check for pod readiness.
1920 :param timeout: Total time to wait in seconds before giving up.
2021 :param interval: Time to wait between checks in seconds.
2122 """
22- namespaces = [
23- "capi-kubeadm-bootstrap-system" ,
24- "capi-kubeadm-control-plane-system" ,
25- "capi-system" ,
26- ]
27-
2823 start_time = time .time ()
2924
3025 while time .time () - start_time < timeout :
@@ -49,69 +44,21 @@ def wait_for_capi_pods_ready(timeout=240, interval=15):
4944 all_pods_ready = False
5045 logger .info (f"Pod { pod_name } in { namespace } is not ready. Phase: { phase } , Ready: { readiness_states } " )
5146 else :
52- logger .info (f"Error fetching pods in { namespace } : { result .stderr } " )
47+ logger .error (f"Error fetching pods in { namespace } : { result .stderr } " )
5348 all_pods_ready = False
5449
5550 except subprocess .CalledProcessError as error :
5651 logger .error (f"Error checking pods in { namespace } : { error } " )
5752 all_pods_ready = False
5853
5954 if all_pods_ready :
60- logger .info ("All CAPI system pods are ready." )
61- return True
62-
63- logger .info ("Waiting for all CAPI pods to become ready..." )
64- time .sleep (interval )
65-
66- raise TimeoutError (f"Timed out after { timeout } seconds waiting for CAPI and CAPO system pods to become ready." )
67-
68-
69- def wait_for_cso_pods_ready (timeout = 240 , interval = 15 ):
70- """
71- Waits for all CSO (Cluster Stack Operator) pods in the 'cso-system' namespace to reach 'Running' with containers ready.
72-
73- :param timeout: Total time to wait in seconds before giving up.
74- :param interval: Time to wait between checks in seconds.
75- """
76- cso_namespace = "cso-system"
77- start_time = time .time ()
78-
79- while time .time () - start_time < timeout :
80- all_pods_ready = True
81-
82- try :
83- # Get pod status in the 'cso-system' namespace
84- result = subprocess .run (
85- f"kubectl get pods -n { cso_namespace } -o=jsonpath='{{range .items[*]}}{{.metadata.name}} {{.status.phase}} {{range .status.containerStatuses[*]}}{{.ready}} {{end}}{{\" \\ n\" }}{{end}}'" ,
86- shell = True , capture_output = True , text = True , check = True
87- )
88-
89- if result .returncode == 0 :
90- pods_status = result .stdout .strip ().splitlines ()
91- for pod_status in pods_status :
92- pod_info = pod_status .split ()
93- pod_name , phase , * readiness_states = pod_info
94-
95- # Check pod phase and all containers readiness
96- if phase != "Running" or "false" in readiness_states :
97- all_pods_ready = False
98- logger .info (f"Pod { pod_name } in { cso_namespace } is not ready. Phase: { phase } , Ready: { readiness_states } " )
99- else :
100- logger .error (f"Error fetching pods in { cso_namespace } : { result .stderr } " )
101- all_pods_ready = False
102-
103- except subprocess .CalledProcessError as error :
104- logger .error (f"Error checking pods in { cso_namespace } : { error } " )
105- all_pods_ready = False
106-
107- if all_pods_ready :
108- logger .info ("All CSO pods in 'cso-system' namespace are ready." )
55+ logger .info ("All specified pods are ready in all namespaces." )
10956 return True
11057
111- logger .info ("Waiting for CSO pods in 'cso-system' namespace to become ready..." )
58+ logger .info ("Waiting for all pods in specified namespaces to become ready..." )
11259 time .sleep (interval )
11360
114- raise TimeoutError (f"Timed out after { timeout } seconds waiting for CSO pods in 'cso-system' namespace to become ready." )
61+ raise TimeoutError (f"Timed out after { timeout } seconds waiting for pods in namespaces { namespaces } to become ready." )
11562
11663
11764def wait_for_workload_pods_ready (namespace = "kube-system" , timeout = 600 , kubeconfig_path = None , max_retries = 3 , delay = 30 ):
@@ -245,7 +192,7 @@ def create_cluster(self, cluster_name="scs-cluster", version=None, kubeconfig_fi
245192 self ._run_subprocess (["clusterctl" , "init" , "--infrastructure" , "openstack" ], "Error during clusterctl init" )
246193
247194 # Wait for all CAPI pods to be ready
248- wait_for_capi_pods_ready ( )
195+ wait_for_pods ([ "capi-kubeadm-bootstrap-system" , "capi-kubeadm-control-plane-system" , "capi-system" ] )
249196
250197 # Apply infrastructure components
251198 self ._apply_yaml_with_envsubst ("cso-infrastructure-components.yaml" , "Error applying CSO infrastructure components" )
@@ -259,7 +206,7 @@ def create_cluster(self, cluster_name="scs-cluster", version=None, kubeconfig_fi
259206 )
260207 self ._run_subprocess (helm_command , "Error deploying CSP-helper chart" , shell = True )
261208
262- wait_for_cso_pods_ready ( )
209+ wait_for_pods ([ "cso-system" ] )
263210
264211 # Create Cluster Stack definition and workload cluster
265212 self ._apply_yaml_with_envsubst ("clusterstack.yaml" , "Error applying clusterstack.yaml" )
0 commit comments