Skip to content

Commit 596788e

Browse files
committed
update get_pods to look through all namespaces
This expands `get_pods` view to see and search through all namespaces. It also flattens out list[V1PodList] into just list[V1Pod]. This affected two downstream functions: `down` and `_logs`. I updated them accordingly.
1 parent 6b51bb3 commit 596788e

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/warnet/control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def delete_pod(pod_name, namespace):
178178

179179
# Delete remaining pods
180180
pods = get_pods()
181-
for pod in pods.items:
181+
for pod in pods:
182182
futures.append(executor.submit(delete_pod, pod.metadata.name, pod.metadata.namespace))
183183

184184
# Wait for all tasks to complete and print results
@@ -346,7 +346,7 @@ def _logs(pod_name: str, follow: bool):
346346
if pod_name == "":
347347
try:
348348
pods = get_pods()
349-
pod_list = [item.metadata.name for item in pods.items]
349+
pod_list = [item.metadata.name for item in pods]
350350
except Exception as e:
351351
print(f"Could not fetch any pods in namespace {namespace}: {e}")
352352
return

src/warnet/k8s.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from kubernetes import client, config, watch
1010
from kubernetes.client import CoreV1Api
1111
from kubernetes.client.exceptions import ApiException
12-
from kubernetes.client.models import V1Namespace, V1PodList
12+
from kubernetes.client.models import V1Namespace, V1Pod, V1PodList
1313
from kubernetes.dynamic import DynamicClient
1414
from kubernetes.stream import stream
1515

@@ -34,19 +34,25 @@ def get_dynamic_client() -> DynamicClient:
3434
return DynamicClient(client.ApiClient())
3535

3636

37-
def get_pods() -> V1PodList:
37+
def get_pods() -> list[V1Pod]:
3838
sclient = get_static_client()
39-
try:
40-
pod_list: V1PodList = sclient.list_namespaced_pod(get_default_namespace())
41-
except Exception as e:
42-
raise e
43-
return pod_list
44-
45-
46-
def get_mission(mission: str) -> list[V1PodList]:
39+
pods: list[V1Pod] = []
40+
namespaces = get_namespaces()
41+
for ns in namespaces:
42+
namespace = ns.metadata.name
43+
try:
44+
pod_list: V1PodList = sclient.list_namespaced_pod(namespace)
45+
for pod in pod_list.items:
46+
pods.append(pod)
47+
except Exception as e:
48+
raise e
49+
return pods
50+
51+
52+
def get_mission(mission: str) -> list[V1Pod]:
4753
pods = get_pods()
48-
crew = []
49-
for pod in pods.items:
54+
crew: list[V1Pod] = []
55+
for pod in pods:
5056
if "mission" in pod.metadata.labels and pod.metadata.labels["mission"] == mission:
5157
crew.append(pod)
5258
return crew

0 commit comments

Comments
 (0)