Skip to content

Commit 97c944b

Browse files
committed
chore(controller): list pod when pending
1 parent 4a31ba1 commit 97c944b

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

rootfs/api/models/app.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,21 @@ def get_command_and_args(pod, container_name):
431431
result = []
432432
try:
433433
pod = self.scheduler().pod.get(self.id, pod_name).json()
434-
for status in pod["status"]["containerStatuses"]:
434+
if pod["status"]['phase'] == 'Pending':
435+
statuses = pod["spec"]["containers"]
436+
else:
437+
statuses = pod["status"]["containerStatuses"]
438+
for status in statuses:
435439
command, args = get_command_and_args(pod, status["name"])
436440
result.append({
437441
"container": status["name"],
438442
"image": status["image"],
439443
"command": command,
440444
"args": args,
441-
"state": status["state"],
442-
"lastState": status["lastState"],
443-
"ready": status["ready"],
444-
"restartCount": status["restartCount"],
445+
"state": status.get("state", {}),
446+
"lastState": status.get("lastState", {}),
447+
"ready": status.get("ready", False),
448+
"restartCount": status.get("restartCount", 0),
445449
"status": pod["status"].get("phase", ""),
446450
"reason": pod["status"].get("reason", ""),
447451
"message": pod["status"].get("message", "")
@@ -470,15 +474,22 @@ def list_pods(self, *args, **kwargs):
470474
else:
471475
started = str(
472476
datetime.now(timezone.utc).strftime(settings.DRYCC_DATETIME_FORMAT))
477+
state = str(self.scheduler().pod.state(p))
478+
if p['status']['phase'] != 'Pending':
479+
ready = len([1 for s in p["status"]["containerStatuses"] if s['ready']])
480+
restarts = sum([s['restartCount'] for s in p["status"]["containerStatuses"]])
481+
else:
482+
restarts = 0
483+
ready = 0
473484
item = {
474-
'name': p['metadata']['name'], 'state': str(self.scheduler().pod.state(p)),
485+
'name': p['metadata']['name'],
486+
'state': state,
475487
'release': labels['version'], 'type': labels['type'], 'started': started,
476488
'ready': "%s/%s" % (
477-
len([1 for s in p["status"]["containerStatuses"] if s['ready']]),
478-
len(p["status"]["containerStatuses"]),
489+
ready,
490+
len(p["spec"]["containers"]),
479491
),
480-
'restarts': sum(
481-
[s['restartCount'] for s in p["status"]["containerStatuses"]]),
492+
'restarts': restarts
482493
}
483494
data.append(item)
484495
# sorting so latest start date is first

0 commit comments

Comments
 (0)