Skip to content

Commit a0569ed

Browse files
committed
k8s & control: query all namespaces
This expands `get_pods` view to query 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 38e5391 commit a0569ed

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
@@ -138,7 +138,7 @@ def delete_pod(pod_name, namespace):
138138

139139
# Delete remaining pods
140140
pods = get_pods()
141-
for pod in pods.items:
141+
for pod in pods:
142142
futures.append(executor.submit(delete_pod, pod.metadata.name, pod.metadata.namespace))
143143

144144
# Wait for all tasks to complete and print results
@@ -306,7 +306,7 @@ def _logs(pod_name: str, follow: bool):
306306
if pod_name == "":
307307
try:
308308
pods = get_pods()
309-
pod_list = [item.metadata.name for item in pods.items]
309+
pod_list = [item.metadata.name for item in pods]
310310
except Exception as e:
311311
print(f"Could not fetch any pods in namespace {namespace}: {e}")
312312
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)