Filter out "Evicted" pods (#158)

* Update kubernetes.py

* add failed pod phase

- Add mock data for failed pods
- Failed pods do not get a 'ready' or 'state' key in api. ( see issue #157 )
This commit is contained in:
Drew Rapenchuk
2018-03-26 12:36:08 -04:00
committed by Henning Jacobs
parent b724994070
commit 74bf801bc3
2 changed files with 7 additions and 4 deletions

View File

@@ -89,8 +89,8 @@ def query_kubernetes_cluster(cluster):
termination_time = parse_time(termination_time)
if termination_time > last_termination_time:
last_termination_time = termination_time
if last_termination_time and last_termination_time < now - 3600:
# the job/pod finished more than an hour ago
if (last_termination_time and last_termination_time < now - 3600) or (obj['reason'] in 'Evicted'):
# the job/pod finished more than an hour ago or if it is evicted by cgroup limits
# => filter out
continue
pods_by_namespace_name[(obj['namespace'], obj['name'])] = obj

View File

@@ -23,7 +23,7 @@ def generate_mock_pod(index: int, i: int, j: int):
'env': ['prod', 'dev'],
'owner': ['x-wing', 'iris']
}
pod_phases = ['Pending', 'Running', 'Running']
pod_phases = ['Pending', 'Running', 'Running', 'Failed']
pod_labels = {}
for li, k in enumerate(labels):
@@ -44,7 +44,10 @@ def generate_mock_pod(index: int, i: int, j: int):
if j % 13 == 0:
container.update(**{'ready': False, 'state': {'waiting': {'reason': 'CrashLoopBackOff'}}})
elif j % 7 == 0:
container.update(**{'ready': True, 'state': {'running': {}}, 'restartCount': 3})
container.update(**{'ready': False, 'state': {'running': {}}, 'restartCount': 3})
elif phase == 'Failed':
del container['state']
del container['ready']
containers.append(container)
pod = {
'name': '{}-{}-{}'.format(names[hash_int((i + 1) * (j + 1)) % len(names)], i, j),