Skip to content

Instantly share code, notes, and snippets.

@thomastaylor312
Created November 4, 2016 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomastaylor312/bb668d080453f6fa9d00d68dfc7aa85c to your computer and use it in GitHub Desktop.
Save thomastaylor312/bb668d080453f6fa9d00d68dfc7aa85c to your computer and use it in GitHub Desktop.
Function for checking status of containers in pods
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