Created
November 4, 2016 21:43
-
-
Save thomastaylor312/bb668d080453f6fa9d00d68dfc7aa85c to your computer and use it in GitHub Desktop.
Function for checking status of containers in pods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_pods(get_pods_json): | |
problemPods = list() | |
for pod in get_pods_json['items']: | |
isBad = False | |
if pod['status']['phase'] != 'Running' and pod['status']['phase'] != 'Completed': | |
isBad = True | |
else: | |
for container_status in pod['status']['containerStatuses']: | |
if not container_status['ready']: | |
isBad = True | |
break | |
if isBad: | |
podDescription = dict() | |
podDescription['name'] = pod['metadata']['name'] | |
podDescription['state'] = pod['status']['phase'] | |
podDescription['namespace'] = pod['metadata']['namespace'] | |
podDescription['containers'] = list() | |
countRunningContainers = 0 | |
# If the pod hasn't been scheduled yet, it won't have the statuses | |
if 'containerStatuses' in pod['status']: | |
for container_status in pod['status']['containerStatuses']: | |
# Increment the ready count | |
if container_status['ready']: | |
countRunningContainers += 1 | |
podDescription['containers'].append({ | |
'name': container_status['name'], | |
'isRunning': container_status['ready'] | |
}) | |
podDescription['containers_running'] = '{0}/{1}'.format(countRunningContainers, len(podDescription['containers'])) | |
problemPods.append(podDescription) | |
return problemPods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment