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

Commit

Permalink
fix(scheduler): lower case CPU limits and upper case first char in Me…
Browse files Browse the repository at this point in the history
…mory limits for Kubernetes

Fixes #915
  • Loading branch information
helgi committed Jul 27, 2016
1 parent 89a0ff8 commit ffef759
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rootfs/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,13 @@ def _set_container(self, namespace, container_name, data, **kwargs): # noqa
if mem[-2:-1].isalpha() and mem[-1].isalpha():
mem = mem[:-1]

mem = mem + "i"
# memory needs to be upper cased (only first char)
mem = mem.upper() + "i"
data["resources"]["limits"]["memory"] = mem

if cpu:
data["resources"]["limits"]["cpu"] = cpu
# CPU needs to be defined as lower case
data["resources"]["limits"]["cpu"] = cpu.lower()

# add in healthchecks
healthchecks = kwargs.get('healthcheck', None)
Expand Down
13 changes: 13 additions & 0 deletions rootfs/scheduler/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@ def test_set_container_applies_healthcheck_with_routable(self):
data,
healthcheck=healthcheck)
self.assertEqual(data.get('livenessProbe'), None)

def test_set_container_limits(self):
"""
Test that when _set_container has limits that is sets them properly
"""
data = {}
self.scheduler_client._set_container(
'foo', 'bar', data, app_type='fake', cpu={'fake': '500M'}, memory={'fake': '1024m'}
)
# make sure CPU gets lower cased
self.assertEqual(data['resources']['limits']['cpu'], '500m', 'CPU should be lower cased')
# make sure first char of Memory is upper cased
self.assertEqual(data['resources']['limits']['memory'], '1024Mi', 'Memory should be upper cased') # noqa

0 comments on commit ffef759

Please sign in to comment.