Skip to content

Commit e1eefce

Browse files
committed
Merge branch 'schu-oom-kill-disable-pr'
2 parents 9ed7219 + 64eac0b commit e1eefce

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

docker/utils/utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,16 @@ def parse_bytes(s):
469469
return s
470470

471471

472-
def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
473-
publish_all_ports=False, links=None, privileged=False,
474-
dns=None, dns_search=None, volumes_from=None,
475-
network_mode=None, restart_policy=None, cap_add=None,
476-
cap_drop=None, devices=None, extra_hosts=None,
477-
read_only=None, pid_mode=None, ipc_mode=None,
478-
security_opt=None, ulimits=None, log_config=None,
479-
mem_limit=None, memswap_limit=None, mem_swappiness=None,
480-
cgroup_parent=None, group_add=None, cpu_quota=None,
481-
cpu_period=None, version=None):
472+
def create_host_config(
473+
binds=None, port_bindings=None, lxc_conf=None, publish_all_ports=False,
474+
links=None, privileged=False, dns=None, dns_search=None, volumes_from=None,
475+
network_mode=None, restart_policy=None, cap_add=None, cap_drop=None,
476+
devices=None, extra_hosts=None, read_only=None, pid_mode=None,
477+
ipc_mode=None, security_opt=None, ulimits=None, log_config=None,
478+
mem_limit=None, memswap_limit=None, mem_swappiness=None,
479+
cgroup_parent=None, group_add=None, cpu_quota=None, cpu_period=None,
480+
oom_kill_disable=False, version=None
481+
):
482482

483483
host_config = {}
484484

@@ -525,6 +525,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
525525
if privileged:
526526
host_config['Privileged'] = privileged
527527

528+
if oom_kill_disable:
529+
if version_lt(version, '1.19'):
530+
raise errors.InvalidVersion(
531+
'oom_kill_disable param not supported for API version < 1.19'
532+
)
533+
host_config['OomKillDisable'] = oom_kill_disable
534+
528535
if publish_all_ports:
529536
host_config['PublishAllPorts'] = publish_all_ports
530537

docs/hostconfig.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ for example:
7272
* port_bindings (dict): Port bindings. See [Port bindings](port-bindings.md)
7373
for more information.
7474
* lxc_conf (dict): LXC config
75+
* oom_kill_disable (bool): Whether to disable OOM killer
7576
* publish_all_ports (bool): Whether to publish all ports to the host
7677
* links (dict or list of tuples): either as a dictionary mapping name to alias
7778
or as a list of `(name, alias)` tuples

tests/integration/container_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ def test_get_container_stats_no_stream(self):
10541054
self.client.kill(container)
10551055

10561056
self.assertEqual(type(response), dict)
1057-
for key in ['read', 'network', 'precpu_stats', 'cpu_stats',
1057+
for key in ['read', 'networks', 'precpu_stats', 'cpu_stats',
10581058
'memory_stats', 'blkio_stats']:
10591059
self.assertIn(key, response)
10601060

tests/unit/utils_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from docker.client import Client
1515
from docker.constants import DEFAULT_DOCKER_API_VERSION
16-
from docker.errors import DockerException
16+
from docker.errors import DockerException, InvalidVersion
1717
from docker.utils import (
1818
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
1919
create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
@@ -62,6 +62,13 @@ def test_create_host_config_with_cpu_period(self):
6262
config = create_host_config(version='1.20', cpu_period=1999)
6363
self.assertEqual(config.get('CpuPeriod'), 1999)
6464

65+
def test_create_host_config_with_oom_kill_disable(self):
66+
config = create_host_config(version='1.20', oom_kill_disable=True)
67+
self.assertEqual(config.get('OomKillDisable'), True)
68+
self.assertRaises(
69+
InvalidVersion, lambda: create_host_config(version='1.18.3',
70+
oom_kill_disable=True))
71+
6572

6673
class UlimitTest(base.BaseTestCase):
6774
def test_create_host_config_dict_ulimit(self):

0 commit comments

Comments
 (0)