Skip to content

Commit d45fb24

Browse files
committed
feat(controller): disable swap if there's a mem limit
1 parent ab53096 commit d45fb24

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

controller/deis/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import unicode_literals
66
import os.path
77
import random
8+
import semantic_version as semver
89
import string
910
import sys
1011
import tempfile
@@ -372,6 +373,17 @@
372373
sys.path.append('/templates')
373374
from confd_settings import * # noqa
374375

376+
# Disable swap when mem limits are set, unless Docker is too old
377+
DISABLE_SWAP = '--memory-swap=-1'
378+
try:
379+
version = 'unknown'
380+
from registry.dockerclient import DockerClient
381+
version = DockerClient().client.version().get('Version')
382+
if not semver.validate(version) or semver.Version(version) < semver.Version('1.5.0'):
383+
DISABLE_SWAP = ''
384+
except:
385+
print("Not disabling --memory-swap for Docker version {}".format(version))
386+
375387
# LDAP Backend Configuration
376388
# Should be always after the confd_settings import.
377389
LDAP_USER_SEARCH = LDAPSearch(

controller/requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ django-auth-ldap==1.2.5
1010
djangorestframework==3.0.5
1111
docker-py==1.5.0
1212
gunicorn==19.3.0
13+
marathon==0.6.15
1314
paramiko==1.15.2
1415
psycopg2==2.6.1
1516
python-etcd==0.3.2
17+
python-ldap==2.4.19
1618
PyYAML==3.11
19+
semantic_version==2.4.2
1720
simpleflock==0.0.2
18-
static==1.1.1
1921
South==1.0.2
20-
python-ldap==2.4.19
21-
marathon==0.6.15
22+
static==1.1.1

controller/scheduler/fleet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def _create_container(self, name, image, command, unit, **kwargs):
127127
# prepare memory limit for the container type
128128
mem = kwargs.get('memory', {}).get(l['c_type'], None)
129129
if mem:
130-
l.update({'memory': '-m {}'.format(mem.lower())})
130+
l.update({'memory': '-m {} {}'.format(mem.lower(), settings.DISABLE_SWAP)})
131131
else:
132132
l.update({'memory': ''})
133133
# prepare memory limit for the container type

docs/docs_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ gunicorn==19.3.0
1616
paramiko==1.15.2
1717
python-etcd==0.3.2
1818
PyYAML==3.11
19+
semantic_version==2.4.2
1920
simpleflock==0.0.2
2021
South==1.0.2
2122

0 commit comments

Comments
 (0)