1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

docker_container: improving idempotency (#44808)

* Only handle cpu_shares, volume_driver, auto_remove as in _host_config().

* Don't compare log_options (resp restart_retries) if log_driver (resp restart_policy) is not specified.

* Warn that log_options (resp restart_retries) is ignored if log_driver (resp restart_policy) is not specified.
This commit is contained in:
Felix Fontein 2018-08-30 03:07:32 +02:00 committed by ansibot
parent a96a51b0c6
commit 1dcf52c8fe

View file

@ -1276,7 +1276,6 @@ class Container(DockerBaseClass):
# Map parameters to container inspect results
config_mapping = dict(
auto_remove=host_config.get('AutoRemove'),
expected_cmd=config.get('Cmd'),
domainname=config.get('Domainname'),
hostname=config.get('Hostname'),
@ -1296,8 +1295,6 @@ class Container(DockerBaseClass):
ipc_mode=host_config.get("IpcMode"),
labels=config.get('Labels'),
expected_links=host_config.get('Links'),
log_driver=log_config.get('Type'),
log_options=log_config.get('Config'),
mac_address=network.get('MacAddress'),
memory_swappiness=host_config.get('MemorySwappiness'),
network_mode=host_config.get('NetworkMode'),
@ -1309,7 +1306,6 @@ class Container(DockerBaseClass):
expected_ports=host_config.get('PortBindings'),
read_only=host_config.get('ReadonlyRootfs'),
restart_policy=restart_policy.get('Name'),
restart_retries=restart_policy.get('MaximumRetryCount'),
# Cannot test shm_size, as shm_size is not included in container inspection results.
# shm_size=host_config.get('ShmSize'),
security_opts=host_config.get("SecurityOpt"),
@ -1322,9 +1318,21 @@ class Container(DockerBaseClass):
expected_volumes=config.get('Volumes'),
expected_binds=host_config.get('Binds'),
volumes_from=host_config.get('VolumesFrom'),
volume_driver=host_config.get('VolumeDriver'),
working_dir=config.get('WorkingDir')
)
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')
if self.parameters.client.HAS_AUTO_REMOVE_OPT:
# auto_remove is only supported in docker>=2
config_mapping['auto_remove'] = host_config.get('AutoRemove')
if HAS_DOCKER_PY_3:
# volume_driver moved to create_host_config in > 3
config_mapping['volume_driver'] = host_config.get('VolumeDriver')
differences = []
for key, value in config_mapping.items():
@ -1422,7 +1430,6 @@ class Container(DockerBaseClass):
cpu_quota=host_config.get('CpuQuota'),
cpuset_cpus=host_config.get('CpusetCpus'),
cpuset_mems=host_config.get('CpusetMems'),
cpu_shares=host_config.get('CpuShares'),
kernel_memory=host_config.get("KernelMemory"),
memory=host_config.get('Memory'),
memory_reservation=host_config.get('MemoryReservation'),
@ -1431,6 +1438,10 @@ class Container(DockerBaseClass):
oom_killer=host_config.get('OomKillDisable'),
)
if HAS_DOCKER_PY_3:
# cpu_shares moved to create_host_config in > 3
config_mapping['cpu_shares'] = host_config.get('CpuShares')
differences = []
for key, value in config_mapping.items():
if getattr(self.parameters, key, None) and getattr(self.parameters, key) != value:
@ -1744,6 +1755,11 @@ class ContainerManager(DockerBaseClass):
super(ContainerManager, self).__init__()
if client.module.params.get('log_options') and not client.module.params.get('log_driver'):
client.module.warn('log_options is ignored when log_driver is not specified')
if client.module.params.get('restart_retries') and not client.module.params.get('restart_policy'):
client.module.warn('restart_retries is ignored when restart_policy is not specified')
self.client = client
self.parameters = TaskParameters(client)
self.check_mode = self.client.check_mode