Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container - #65993 - update restart policy (restart policy & restart retries) wit… #66192

Merged
merged 7 commits into from
Jan 6, 2020
28 changes: 21 additions & 7 deletions lib/ansible/modules/cloud/docker/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,12 +1426,17 @@ def update_parameters(self):
mem_reservation='memory_reservation',
memswap_limit='memory_swap',
kernel_memory='kernel_memory',
restart_policy='restart_policy',
)

result = dict()
for key, value in update_parameters.items():
if getattr(self, value, None) is not None:
if self.client.option_minimal_versions[value]['supported']:
if key == 'restart_policy' and self.client.option_minimal_versions[value]['supported']:
restart_policy = dict(Name=self.restart_policy,
MaximumRetryCount=self.restart_retries)
result[key] = restart_policy
elif self.client.option_minimal_versions[value]['supported']:
result[key] = getattr(self, value)
return result

Expand Down Expand Up @@ -1595,9 +1600,10 @@ def _host_config(self):
if self.client.option_minimal_versions[value]['supported']:
params[key] = getattr(self, value)

if self.restart_policy:
params['restart_policy'] = dict(Name=self.restart_policy,
MaximumRetryCount=self.restart_retries)
if self.client.docker_api_version < LooseVersion('1.22'):
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if self.restart_policy:
params['restart_policy'] = dict(Name=self.restart_policy,
MaximumRetryCount=self.restart_retries)

if 'mounts' in params:
params['mounts'] = self.mounts_opt
Expand Down Expand Up @@ -2089,10 +2095,12 @@ def has_different_configuration(self, image):

host_config = self.container['HostConfig']
log_config = host_config.get('LogConfig', dict())
restart_policy = host_config.get('RestartPolicy', dict())
config = self.container['Config']
network = self.container['NetworkSettings']

if self.parameters.client.docker_api_version < LooseVersion('1.22'):
restart_policy = host_config.get('RestartPolicy', dict())
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

# The previous version of the docker module ignored the detach state by
# assuming if the container was running, it must have been detached.
detach = not (config.get('AttachStderr') and config.get('AttachStdout'))
Expand Down Expand Up @@ -2136,7 +2144,6 @@ def has_different_configuration(self, image):
privileged=host_config.get('Privileged'),
expected_ports=host_config.get('PortBindings'),
read_only=host_config.get('ReadonlyRootfs'),
restart_policy=restart_policy.get('Name'),
runtime=host_config.get('Runtime'),
shm_size=host_config.get('ShmSize'),
security_opts=host_config.get("SecurityOpt"),
Expand Down Expand Up @@ -2167,7 +2174,7 @@ def has_different_configuration(self, image):
cpus=host_config.get('NanoCpus'),
)
# Options which don't make sense without their accompanying option
if self.parameters.restart_policy:
if self.parameters.restart_policy and self.parameters.client.docker_api_version < LooseVersion('1.22'):
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
config_mapping['restart_retries'] = restart_policy.get('MaximumRetryCount')
if self.parameters.log_driver:
config_mapping['log_driver'] = log_config.get('Type')
Expand Down Expand Up @@ -2201,6 +2208,7 @@ def has_different_configuration(self, image):
memory=host_config.get('Memory'),
memory_reservation=host_config.get('MemoryReservation'),
memory_swap=host_config.get('MemorySwap'),
restart_policy=restart_policy.get('Name')
))

differences = DifferenceTracker()
Expand Down Expand Up @@ -2265,8 +2273,14 @@ def has_different_resource_limits(self):
memory=host_config.get('Memory'),
memory_reservation=host_config.get('MemoryReservation'),
memory_swap=host_config.get('MemorySwap'),
restart_policy=host_config.get('RestartPolicy')
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
)

# Options which don't make sense without their accompanying option
if self.parameters.restart_policy:
restart_policy = host_config.get('RestartPolicy', dict())
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
config_mapping['restart_retries'] = restart_policy.get('MaximumRetryCount')
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

differences = DifferenceTracker()
for key, value in config_mapping.items():
if getattr(self.parameters, key, None):
Expand Down