Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Filter out "Evicted" pods (#158)
Browse files Browse the repository at this point in the history
* 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 )
  • Loading branch information
rapenchukd authored and hjacobs committed Mar 26, 2018
1 parent b724994 commit 74bf801
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kube_ops_view/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions kube_ops_view/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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),
Expand Down

0 comments on commit 74bf801

Please sign in to comment.