Merge pull request #4563 from shin-/3723-mem-reservation

Add mem_reservation option to service config in 2.0 and 2.1 formats
This commit is contained in:
Joffrey F 2017-03-07 15:23:22 -08:00 committed by GitHub
commit dd4e49ef98
6 changed files with 28 additions and 4 deletions

View File

@ -76,7 +76,8 @@ DOCKER_CONFIG_KEYS = [
'labels',
'links',
'mac_address',
'mem_limit',
'mem_limit'
'mem_reservation',
'memswap_limit',
'mem_swappiness',
'net',

View File

@ -145,8 +145,9 @@
"mac_address": {"type": "string"},
"mem_limit": {"type": ["number", "string"]},
"memswap_limit": {"type": ["number", "string"]},
"mem_reservation": {"type": ["string", "integer"]},
"mem_swappiness": {"type": "integer"},
"memswap_limit": {"type": ["number", "string"]},
"network_mode": {"type": "string"},
"networks": {

View File

@ -168,8 +168,9 @@
"mac_address": {"type": "string"},
"mem_limit": {"type": ["number", "string"]},
"memswap_limit": {"type": ["number", "string"]},
"mem_reservation": {"type": ["string", "integer"]},
"mem_swappiness": {"type": "integer"},
"memswap_limit": {"type": ["number", "string"]},
"network_mode": {"type": "string"},
"networks": {

View File

@ -64,9 +64,10 @@ DOCKER_START_KEYS = [
'log_driver',
'log_opt',
'mem_limit',
'mem_reservation',
'memswap_limit',
'oom_score_adj',
'mem_swappiness',
'oom_score_adj',
'pid',
'pids_limit',
'privileged',
@ -766,6 +767,7 @@ class Service(object):
cap_add=options.get('cap_add'),
cap_drop=options.get('cap_drop'),
mem_limit=options.get('mem_limit'),
mem_reservation=options.get('mem_reservation'),
memswap_limit=options.get('memswap_limit'),
ulimits=build_ulimits(options.get('ulimits')),
log_config=log_config,

View File

@ -880,6 +880,11 @@ class ServiceTest(DockerClientTestCase):
container = create_and_start_container(service)
self.assertEqual(container.get('HostConfig.MemorySwappiness'), 11)
def test_mem_reservation(self):
service = self.create_service('web', mem_reservation='20m')
container = create_and_start_container(service)
assert container.get('HostConfig.MemoryReservation') == 20 * 1024 * 1024
def test_restart_always_value(self):
service = self.create_service('web', restart={'Name': 'always'})
container = create_and_start_container(service)

View File

@ -170,6 +170,20 @@ class ServiceTest(unittest.TestCase):
2000000000
)
def test_mem_reservation(self):
self.mock_client.create_host_config.return_value = {}
service = Service(
name='foo',
image='foo',
hostname='name',
client=self.mock_client,
mem_reservation='512m'
)
service._get_container_create_options({'some': 'overrides'}, 1)
assert self.mock_client.create_host_config.called is True
assert self.mock_client.create_host_config.call_args[1]['mem_reservation'] == '512m'
def test_cgroup_parent(self):
self.mock_client.create_host_config.return_value = {}