mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 11:58:43 +00:00
Allow healthcheck override without test option (#847)
* Add healthcheck test_cli_compatible option * Update plugins/module_utils/util.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/docker_container.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
2eb2c9febf
commit
5016a96eba
@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- docker_container - adds ``healthcheck.test_cli_compatible`` to allow omit test option on containers without remove existing image test (https://github.com/ansible-collections/community.docker/pull/847).
|
||||||
@ -935,6 +935,7 @@ OPTION_HEALTHCHECK = (
|
|||||||
OptionGroup(preprocess=_preprocess_healthcheck)
|
OptionGroup(preprocess=_preprocess_healthcheck)
|
||||||
.add_option('healthcheck', type='dict', ansible_suboptions=dict(
|
.add_option('healthcheck', type='dict', ansible_suboptions=dict(
|
||||||
test=dict(type='raw'),
|
test=dict(type='raw'),
|
||||||
|
test_cli_compatible=dict(type='bool', default=False),
|
||||||
interval=dict(type='str'),
|
interval=dict(type='str'),
|
||||||
timeout=dict(type='str'),
|
timeout=dict(type='str'),
|
||||||
start_period=dict(type='str'),
|
start_period=dict(type='str'),
|
||||||
|
|||||||
@ -746,7 +746,7 @@ def _preprocess_etc_hosts(module, client, api_version, value):
|
|||||||
def _preprocess_healthcheck(module, client, api_version, value):
|
def _preprocess_healthcheck(module, client, api_version, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
if not value or not value.get('test'):
|
if not value or not (value.get('test') or (value.get('test_cli_compatible') and value.get('test') is None)):
|
||||||
value = {'test': ['NONE']}
|
value = {'test': ['NONE']}
|
||||||
elif 'test' in value:
|
elif 'test' in value:
|
||||||
value['test'] = normalize_healthcheck_test(value['test'])
|
value['test'] = normalize_healthcheck_test(value['test'])
|
||||||
|
|||||||
@ -353,7 +353,7 @@ def normalize_healthcheck(healthcheck, normalize_test=False):
|
|||||||
result = dict()
|
result = dict()
|
||||||
|
|
||||||
# All supported healthcheck parameters
|
# All supported healthcheck parameters
|
||||||
options = ('test', 'interval', 'timeout', 'start_period', 'start_interval', 'retries')
|
options = ('test', 'test_cli_compatible', 'interval', 'timeout', 'start_period', 'start_interval', 'retries')
|
||||||
|
|
||||||
duration_options = ('interval', 'timeout', 'start_period', 'start_interval')
|
duration_options = ('interval', 'timeout', 'start_period', 'start_interval')
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ def normalize_healthcheck(healthcheck, normalize_test=False):
|
|||||||
continue
|
continue
|
||||||
if key in duration_options:
|
if key in duration_options:
|
||||||
value = convert_duration_to_nanosecond(value)
|
value = convert_duration_to_nanosecond(value)
|
||||||
if not value:
|
if not value and not (healthcheck.get('test_cli_compatible') and key == 'test'):
|
||||||
continue
|
continue
|
||||||
if key == 'retries':
|
if key == 'retries':
|
||||||
try:
|
try:
|
||||||
@ -376,7 +376,7 @@ def normalize_healthcheck(healthcheck, normalize_test=False):
|
|||||||
'Cannot parse number of retries for healthcheck. '
|
'Cannot parse number of retries for healthcheck. '
|
||||||
'Expected an integer, got "{0}".'.format(value)
|
'Expected an integer, got "{0}".'.format(value)
|
||||||
)
|
)
|
||||||
if key == 'test' and normalize_test:
|
if key == 'test' and value and normalize_test:
|
||||||
value = normalize_healthcheck_test(value)
|
value = normalize_healthcheck_test(value)
|
||||||
result[key] = value
|
result[key] = value
|
||||||
|
|
||||||
|
|||||||
@ -379,6 +379,16 @@ options:
|
|||||||
- Command to run to check health.
|
- Command to run to check health.
|
||||||
- Must be either a string or a list. If it is a list, the first item must be one of V(NONE), V(CMD) or V(CMD-SHELL).
|
- Must be either a string or a list. If it is a list, the first item must be one of V(NONE), V(CMD) or V(CMD-SHELL).
|
||||||
type: raw
|
type: raw
|
||||||
|
test_cli_compatible:
|
||||||
|
description:
|
||||||
|
- If set to V(true), omitting O(healthcheck.test) while providing O(healthcheck) does not disable healthchecks,
|
||||||
|
but simply overwrites the image's values by the ones specified in O(healthcheck). This is
|
||||||
|
the behavior used by the Docker CLI.
|
||||||
|
- If set to V(false), omitting O(healthcheck.test) will disable the container's health check.
|
||||||
|
This is the classical behavior of the module and currently the default behavior.
|
||||||
|
default: false
|
||||||
|
type: bool
|
||||||
|
version_added: 3.10.0
|
||||||
interval:
|
interval:
|
||||||
description:
|
description:
|
||||||
- Time between running the check.
|
- Time between running the check.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user