-
Notifications
You must be signed in to change notification settings - Fork 153
fix: handle None return from get_container_runtime() #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
+70
to
+76
|
||
| 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.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry loop can exceed
max_waitwhenpoll_intervalis larger than the remaining time (e.g., max_wait=1, poll_interval=10 will still sleep 10s). Consider using a monotonic deadline and sleepingmin(poll_interval, remaining)(or validating/clampingpoll_interval) somax_waitis an actual upper bound.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be an extreme case but a good practice