Skip to content

Commit a46f1c2

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 627c7d9 commit a46f1c2

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/warnet/control.py

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

145145
# Delete remaining pods
146146
pods = get_pods()
147-
for pod in pods.items:
147+
for pod in pods:
148148
futures.append(executor.submit(delete_pod, pod.metadata.name, pod.metadata.namespace))
149149

150150
# Wait for all tasks to complete and print results
@@ -312,7 +312,7 @@ def _logs(pod_name: str, follow: bool):
312312
if pod_name == "":
313313
try:
314314
pods = get_pods()
315-
pod_list = [item.metadata.name for item in pods.items]
315+
pod_list = [item.metadata.name for item in pods]
316316
except Exception as e:
317317
print(f"Could not fetch any pods in namespace {namespace}: {e}")
318318
return

src/warnet/k8s.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ def get_dynamic_client() -> DynamicClient:
3535
return DynamicClient(client.ApiClient())
3636

3737

38-
def get_pods() -> V1PodList:
38+
def get_pods() -> list[V1Pod]:
3939
sclient = get_static_client()
40-
try:
41-
pod_list: V1PodList = sclient.list_namespaced_pod(get_default_namespace())
42-
except Exception as e:
43-
raise e
44-
return pod_list
40+
pods: list[V1Pod] = []
41+
namespaces = get_namespaces()
42+
for ns in namespaces:
43+
namespace = ns.metadata.name
44+
try:
45+
pod_list: V1PodList = sclient.list_namespaced_pod(namespace)
46+
for pod in pod_list.items:
47+
pods.append(pod)
48+
except Exception as e:
49+
raise e
50+
return pods
4551

4652

4753
def get_pod(name: str, namespace: Optional[str] = None) -> V1Pod:
@@ -51,10 +57,10 @@ def get_pod(name: str, namespace: Optional[str] = None) -> V1Pod:
5157
return sclient.read_namespaced_pod(name=name, namespace=namespace)
5258

5359

54-
def get_mission(mission: str) -> list[V1PodList]:
60+
def get_mission(mission: str) -> list[V1Pod]:
5561
pods = get_pods()
56-
crew = []
57-
for pod in pods.items:
62+
crew: list[V1Pod] = []
63+
for pod in pods:
5864
if "mission" in pod.metadata.labels and pod.metadata.labels["mission"] == mission:
5965
crew.append(pod)
6066
return crew

0 commit comments

Comments
 (0)