Skip to content

Commit 01df2e1

Browse files
authored
Merge pull request #918 from helgi/ticket_915
fix(scheduler): lower case CPU limits and upper case first char in Memory limits for Kubernetes
2 parents 89a0ff8 + ffef759 commit 01df2e1

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,13 @@ def _set_container(self, namespace, container_name, data, **kwargs): # noqa
619619
if mem[-2:-1].isalpha() and mem[-1].isalpha():
620620
mem = mem[:-1]
621621

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

625626
if cpu:
626-
data["resources"]["limits"]["cpu"] = cpu
627+
# CPU needs to be defined as lower case
628+
data["resources"]["limits"]["cpu"] = cpu.lower()
627629

628630
# add in healthchecks
629631
healthchecks = kwargs.get('healthcheck', None)

rootfs/scheduler/tests/test_scheduler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,16 @@ def test_set_container_applies_healthcheck_with_routable(self):
5353
data,
5454
healthcheck=healthcheck)
5555
self.assertEqual(data.get('livenessProbe'), None)
56+
57+
def test_set_container_limits(self):
58+
"""
59+
Test that when _set_container has limits that is sets them properly
60+
"""
61+
data = {}
62+
self.scheduler_client._set_container(
63+
'foo', 'bar', data, app_type='fake', cpu={'fake': '500M'}, memory={'fake': '1024m'}
64+
)
65+
# make sure CPU gets lower cased
66+
self.assertEqual(data['resources']['limits']['cpu'], '500m', 'CPU should be lower cased')
67+
# make sure first char of Memory is upper cased
68+
self.assertEqual(data['resources']['limits']['memory'], '1024Mi', 'Memory should be upper cased') # noqa

0 commit comments

Comments
 (0)