mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #39562 from terminalmage/issue30802
Add ulimits to dockerng state/exec module
This commit is contained in:
commit
fbe2194a93
2 changed files with 75 additions and 3 deletions
|
@ -554,6 +554,12 @@ VALID_CREATE_OPTS = {
|
|||
'min_docker': (1, 5, 0),
|
||||
'default': '',
|
||||
},
|
||||
'ulimits': {
|
||||
'path': 'HostConfig:Ulimits',
|
||||
'min_docker': (1, 6, 0),
|
||||
'min_docker_py': (1, 2, 0),
|
||||
'default': [],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -787,10 +793,10 @@ def _get_client(timeout=None):
|
|||
client_kwargs['version'] = 'auto'
|
||||
|
||||
try:
|
||||
__context__['docker.client'] = docker.Client(**client_kwargs)
|
||||
except AttributeError:
|
||||
# docker-py 2.0 renamed this client attribute
|
||||
__context__['docker.client'] = docker.APIClient(**client_kwargs)
|
||||
except AttributeError:
|
||||
__context__['docker.client'] = docker.Client(**client_kwargs)
|
||||
|
||||
# Set a new timeout if one was passed
|
||||
if timeout is not None and __context__['docker.client'].timeout != timeout:
|
||||
|
@ -1792,6 +1798,44 @@ def _validate_input(kwargs,
|
|||
else:
|
||||
kwargs['labels'] = salt.utils.repack_dictlist(kwargs['labels'])
|
||||
|
||||
def _valid_ulimits(): # pylint: disable=unused-variable
|
||||
'''
|
||||
Must be a string or list of strings with bind mount information
|
||||
'''
|
||||
if kwargs.get('ulimits') is None:
|
||||
# No need to validate
|
||||
return
|
||||
err = (
|
||||
'Invalid ulimits configuration. See the documentation for proper '
|
||||
'usage.'
|
||||
)
|
||||
try:
|
||||
_valid_dictlist('ulimits')
|
||||
# If this was successful then assume the correct API value was
|
||||
# passed on on the CLI and do not proceed with validation.
|
||||
return
|
||||
except SaltInvocationError:
|
||||
pass
|
||||
try:
|
||||
_valid_stringlist('ulimits')
|
||||
except SaltInvocationError:
|
||||
raise SaltInvocationError(err)
|
||||
|
||||
new_ulimits = []
|
||||
for ulimit in kwargs['ulimits']:
|
||||
ulimit_name, comps = ulimit.strip().split('=', 1)
|
||||
try:
|
||||
comps = [int(x) for x in comps.split(':', 1)]
|
||||
except ValueError:
|
||||
raise SaltInvocationError(err)
|
||||
if len(comps) == 1:
|
||||
comps *= 2
|
||||
soft_limit, hard_limit = comps
|
||||
new_ulimits.append({'Name': ulimit_name,
|
||||
'Soft': soft_limit,
|
||||
'Hard': hard_limit})
|
||||
kwargs['ulimits'] = new_ulimits
|
||||
|
||||
# And now, the actual logic to perform the validation
|
||||
if 'docker.docker_version' not in __context__:
|
||||
# Have to call this func using the __salt__ dunder (instead of just
|
||||
|
|
|
@ -50,7 +50,8 @@ from salt.modules.dockerng import (
|
|||
STOP_TIMEOUT,
|
||||
VALID_CREATE_OPTS,
|
||||
_validate_input,
|
||||
_get_repo_tag
|
||||
_get_repo_tag,
|
||||
_get_docker_py_versioninfo,
|
||||
)
|
||||
# pylint: enable=no-name-in-module,import-error
|
||||
import salt.utils
|
||||
|
@ -240,6 +241,7 @@ def _compare(actual, create_kwargs, defaults_from_image):
|
|||
ret.update({item: {'old': actual_ports,
|
||||
'new': desired_ports}})
|
||||
continue
|
||||
|
||||
elif item == 'volumes':
|
||||
if actual_data is None:
|
||||
actual_data = []
|
||||
|
@ -411,6 +413,7 @@ def _compare(actual, create_kwargs, defaults_from_image):
|
|||
# sometimes `[]`. We have to deal with it.
|
||||
if bool(actual_data) != bool(data):
|
||||
ret.update({item: {'old': actual_data, 'new': data}})
|
||||
|
||||
elif item == 'labels':
|
||||
if actual_data is None:
|
||||
actual_data = {}
|
||||
|
@ -426,6 +429,7 @@ def _compare(actual, create_kwargs, defaults_from_image):
|
|||
if actual_data != data:
|
||||
ret.update({item: {'old': actual_data, 'new': data}})
|
||||
continue
|
||||
|
||||
elif item == 'security_opt':
|
||||
if actual_data is None:
|
||||
actual_data = []
|
||||
|
@ -441,6 +445,7 @@ def _compare(actual, create_kwargs, defaults_from_image):
|
|||
ret.update({item: {'old': actual_data,
|
||||
'new': desired_data}})
|
||||
continue
|
||||
|
||||
elif item in ('cmd', 'command', 'entrypoint'):
|
||||
if (actual_data is None and item not in create_kwargs and
|
||||
_image_get(config['image_path'])):
|
||||
|
@ -1481,6 +1486,29 @@ def running(name,
|
|||
|
||||
This option requires Docker 1.5.0 or newer.
|
||||
|
||||
ulimits
|
||||
List of ulimits. These limits should be passed in
|
||||
the format ``<ulimit_name>:<soft_limit>:<hard_limit>``, with the hard
|
||||
limit being optional.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
foo:
|
||||
dockerng.running:
|
||||
- image: bar/baz:latest
|
||||
- ulimits: nofile=1024:1024,nproc=60
|
||||
|
||||
Ulimits can be passed as a YAML list instead of a comma-separated list:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
foo:
|
||||
dockerng.running:
|
||||
- image: bar/baz:latest
|
||||
- ulimits:
|
||||
- nofile=1024:1024
|
||||
- nproc=60
|
||||
|
||||
labels
|
||||
Add Metadata to the container. Can be a list of strings/dictionaries
|
||||
or a dictionary of strings (keys and values).
|
||||
|
|
Loading…
Add table
Reference in a new issue