Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kube_aws_autoscaler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ def calculate_usage_by_asg_zone(pods: list, nodes: dict) -> dict:
if phase == 'Succeeded':
# ignore completed jobs
continue
node = nodes.get(pod.obj['spec'].get('nodeName'))
node_name = pod.obj['spec'].get('nodeName')
node = nodes.get(node_name)
if node:
asg_name = node['asg_name']
zone = node['zone']
else:
if node_name and phase in ('Running', 'Unknown'):
# ignore killed "ghost" pods
# (pod is still returned by API, but node was terminated)
continue
# pod is unassigned/pending
asg_name = 'unknown'
# TODO: we actually might know the AZ by looking at volumes..
Expand Down
14 changes: 14 additions & 0 deletions tests/test_autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ def test_calculate_usage_by_asg_zone():
nodes = {'foo': {'asg_name': 'asg1', 'zone': 'z1'}}
assert calculate_usage_by_asg_zone([pod], nodes) == {('asg1', 'z1'): {'cpu': 1/1000, 'memory': 52428800, 'pods': 1}}

# pod is assigned to a node, but pending
pod = MagicMock()
pod.name = 'mypod'
pod.obj = {'status': {'phase': 'Pending'}, 'spec': {'nodeName': 'foo', 'containers': [{'name': 'mycont', 'resources': {'requests': {'cpu': '1m'}}}]}}
nodes = {}
assert calculate_usage_by_asg_zone([pod], nodes) == {('unknown', 'unknown'): {'cpu': 1/1000, 'memory': 52428800, 'pods': 1}}

# pod is a "ghost" --- returned by API but node no longer exists
pod = MagicMock()
pod.name = 'mypod'
pod.obj = {'status': {'phase': 'Running'}, 'spec': {'nodeName': 'foo', 'containers': [{'name': 'mycont', 'resources': {'requests': {'cpu': '1m'}}}]}}
nodes = {}
assert calculate_usage_by_asg_zone([pod], nodes) == {}


def test_calculate_required_auto_scaling_group_sizes():
assert calculate_required_auto_scaling_group_sizes({}, {}, {}, {}) == {}
Expand Down