Skip to content

Commit 765a79d

Browse files
committed
Test of auto deploy take 2
1 parent 94de157 commit 765a79d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pyapp/app/info_api.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import datetime
12
import logging
23
import os
34

45
import kubernetes
56
from fastapi import APIRouter, status
7+
from kubernetes.client.models import V1Pod
68

79
from .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

0 commit comments

Comments
 (0)