diff --git a/aiopslab-applications b/aiopslab-applications index 48e03edb..8038be6b 160000 --- a/aiopslab-applications +++ b/aiopslab-applications @@ -1 +1 @@ -Subproject commit 48e03edb4732468331b6963bc4644e8bae08fac1 +Subproject commit 8038be6b4989c647126f27715acc591c47133c2d diff --git a/aiopslab/generators/fault/inject_symp.py b/aiopslab/generators/fault/inject_symp.py index bc506bfc..b1eb23cf 100644 --- a/aiopslab/generators/fault/inject_symp.py +++ b/aiopslab/generators/fault/inject_symp.py @@ -28,6 +28,12 @@ def __init__(self, namespace: str): container_runtime = self.kubectl.get_container_runtime() + if container_runtime is None: + raise ValueError( + "Could not detect container runtime. " + "Ensure the cluster is running and at least one node is Ready." + ) + if "docker" in container_runtime: pass elif "containerd" in container_runtime: diff --git a/aiopslab/service/kubectl.py b/aiopslab/service/kubectl.py index fad11483..b41e2b65 100644 --- a/aiopslab/service/kubectl.py +++ b/aiopslab/service/kubectl.py @@ -54,15 +54,27 @@ def get_cluster_ip(self, service_name, namespace): service_info = self.core_v1_api.read_namespaced_service(service_name, namespace) return service_info.spec.cluster_ip # type: ignore - def get_container_runtime(self): + def get_container_runtime(self, max_wait: int = 60, poll_interval: int = 2): """ Retrieve the container runtime used by the cluster. If the cluster uses multiple container runtimes, the first one found will be returned. + + Args: + max_wait: Maximum seconds to wait for a Ready node (default: 60) + poll_interval: Seconds between checks (default: 2) + + Returns: + Container runtime version string, or None if no Ready node found within max_wait. """ - for node in self.core_v1_api.list_node().items: - for status in node.status.conditions: - if status.type == "Ready" and status.status == "True": - return node.status.node_info.container_runtime_version + elapsed = 0 + while elapsed < max_wait: + for node in self.core_v1_api.list_node().items: + for status in node.status.conditions: + if status.type == "Ready" and status.status == "True": + return node.status.node_info.container_runtime_version + time.sleep(poll_interval) + elapsed += poll_interval + return None def get_pod_name(self, namespace, label_selector): """Get the name of the first pod in a namespace that matches a given label selector."""