docker_container.running sort list of links

When the docker_container.running module is comparing the defined state
and the current state of a container, the list of linked containers in
the current state is is a non-deterministic order. This results in a
container recreation even though the links are the same (just in a
different order).

This patches the comparison function to lexically sort both the existing
and desired list of links, making the comparison deterministic and not
recreating a container when the links have not changed.

Fixes #44258.
This commit is contained in:
Ollie Armstrong 2017-10-24 17:32:02 +01:00 committed by rallytime
parent bd5b9dd0aa
commit ae34a15503
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19

View file

@ -910,8 +910,8 @@ def compare_container(first, second, ignore=None):
ret.setdefault(conf_dict, {})[item] = {'old': image1, 'new': image2}
else:
if item == 'Links':
val1 = _scrub_links(val1, first)
val2 = _scrub_links(val2, second)
val1 = sorted(_scrub_links(val1, first))
val2 = sorted(_scrub_links(val2, second))
if val1 != val2:
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
# Check for optionally-present items that were in the second container
@ -933,8 +933,8 @@ def compare_container(first, second, ignore=None):
ret.setdefault(conf_dict, {})[item] = {'old': image1, 'new': image2}
else:
if item == 'Links':
val1 = _scrub_links(val1, first)
val2 = _scrub_links(val2, second)
val1 = sorted(_scrub_links(val1, first))
val2 = sorted(_scrub_links(val2, second))
if val1 != val2:
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
return ret