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
Merged
@@ -0,0 +1,2 @@
minor_changes:
- docker_container.py - update a containers restart_policy without restarting the container (https://github.com/ansible/ansible/issues/65993)
25 changes: 20 additions & 5 deletions lib/ansible/modules/cloud/docker/docker_container.py
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 @@ -2089,7 +2094,6 @@ 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']

Expand Down Expand Up @@ -2136,7 +2140,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,8 +2170,6 @@ 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:
config_mapping['restart_retries'] = restart_policy.get('MaximumRetryCount')
if self.parameters.log_driver:
config_mapping['log_driver'] = log_config.get('Type')
config_mapping['log_options'] = log_config.get('Config')
Expand All @@ -2190,6 +2191,12 @@ def has_different_configuration(self, image):
# we need to handle all limits which are usually handled by
# update_container() as configuration changes which require a container
# restart.
restart_policy = host_config.get('RestartPolicy', dict())

# Options which don't make sense without their accompanying option
if self.parameters.restart_policy:
config_mapping['restart_retries'] = restart_policy.get('MaximumRetryCount')

config_mapping.update(dict(
blkio_weight=host_config.get('BlkioWeight'),
cpu_period=host_config.get('CpuPeriod'),
Expand All @@ -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 @@ -2254,6 +2262,8 @@ def has_different_resource_limits(self):

host_config = self.container['HostConfig']

restart_policy = host_config.get('RestartPolicy') or dict()

config_mapping = dict(
blkio_weight=host_config.get('BlkioWeight'),
cpu_period=host_config.get('CpuPeriod'),
Expand All @@ -2265,8 +2275,13 @@ 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=restart_policy.get('Name')
)

# Options which don't make sense without their accompanying option
if self.parameters.restart_policy:
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