mirror of
https://github.com/Rainyy21/k3s-health-dashboard.git
synced 2026-10-11 01:40:19 -04:00
fix syntax error and it pass the test case
This commit is contained in:
+4
-27
@@ -1,31 +1,8 @@
|
||||
from fastapi import APIRouter, Query
|
||||
from k8s_client import get_core_client
|
||||
from app.k8s_client import fetch_pods
|
||||
|
||||
router = APIRouter(prefix="/pods", tags=["pods"])
|
||||
router = APIRouter(prefix="/pods", tags=["pods"])
|
||||
|
||||
@router.get("/")
|
||||
def list_pods(namespace: str = Query("default")):
|
||||
v1 = get_core_client()
|
||||
pods = v1.list_namespaced_pod(namespace=namespace).items
|
||||
return [
|
||||
{
|
||||
"name": p.metadata.name,
|
||||
"namespace": p.metadata.namespace,
|
||||
"phase": p.status.phase, # Pending/Running/Succeeded/Failed
|
||||
"ready": _is_ready(p),
|
||||
"restarts": _restarts(p),
|
||||
"node": p.spec.node_name,
|
||||
}
|
||||
for p in pods
|
||||
]
|
||||
|
||||
|
||||
def _is_ready(pod) -> bool :
|
||||
if not pod.status.conditions:
|
||||
return False
|
||||
for any(c.type == "Ready" and c.status == "True" for c in pod.status.conditions)
|
||||
|
||||
def _restarts(pod) -> int:
|
||||
if not pod.status.container_statuses:
|
||||
return 0
|
||||
return sum(c.restart_count for c in pod.status.container_statuses)
|
||||
def list_pods(namespace: str = Query("all")):
|
||||
return fetch_pods(namespace=namespace)
|
||||
|
||||
Reference in New Issue
Block a user