File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1+ import datetime
12import logging
23import os
34
45import kubernetes
56from fastapi import APIRouter , status
7+ from kubernetes .client .models import V1Pod
68
79from .config import get_settings
810
@@ -45,13 +47,21 @@ async def get_info():
4547 v1 = kubernetes .client .CoreV1Api ()
4648 try :
4749 pod = v1 .read_namespaced_pod (name = pod_name , namespace = namespace )
48- # Get image name from the first container
49- if pod .spec .containers :
50+ # Ensure pod is a V1Pod instance and has spec and containers
51+ if (
52+ isinstance (pod , V1Pod )
53+ and pod .spec is not None
54+ and getattr (pod .spec , "containers" , None ) is not None
55+ and isinstance (pod .spec .containers , list )
56+ and len (pod .spec .containers ) > 0
57+ ):
5058 image_name = pod .spec .containers [0 ].image
5159 info ["Pod image" ] = image_name
5260 else :
53- logging .error ("No pod. spec. containers found " )
61+ logging .error ("Pod object is not a V1Pod instance or missing spec/ containers" )
5462 except Exception as e :
5563 logging .error ("Can't retrieve pod image name. Error %s" , str (e ))
5664
65+ info ["Now" ] = datetime .datetime .now ().astimezone ().isoformat ()
66+
5767 return info
You can’t perform that action at this time.
0 commit comments