Skip to content

Ignore empty IPAMConfig addresses from Docker 29 when comparing container networks - #35

Open
mitar wants to merge 1 commit into
salt-extensions:mainfrom
mitar:docker-container-networks-ipamconfig
Open

mitar wants to merge 1 commit into
salt-extensions:mainfrom
mitar:docker-container-networks-ipamconfig

Conversation

@mitar

@mitar mitar commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Docker 29 reports addresses which were not set explicitly as empty strings in a container's per-network IPAMConfig. With Docker 29.1.3:

Connection IPAMConfig
user network, automatic IP {"IPv4Address": "", "IPv6Address": ""}
user network, static IPv4 {"IPv4Address": "10.247.198.10", "IPv6Address": ""}
default bridge null

docker.compare_container_networks, which docker_container.running uses to find network changes, passed these values through. This had two effects:

  1. The reported network changes contained the empty strings.
  2. It decides whether an IP configuration is static with bool(IPAMConfig). A dict of empty strings is truthy, so an automatic IP counted as a static one, and the changes for switching between static and automatic IP configuration, or for connecting a network with an automatic IP, were reported as IPAMConfig values made of empty strings instead of IPConfiguration and the assigned IP.

This PR drops the empty values when reading the networks, so that an IPAMConfig without explicitly set addresses counts as no static configuration. It builds new dicts for this instead of changing the inspect data which the caller passed in. The loop over the second container's networks now iterates with .items(), because pylint asked for it once the networks are a plain dict.

The same kind of Docker 29 change, an empty IPRange in network IPAM pools, is already handled by docker.compare_networks.

What issues does this PR fix or reference?

Fixes: no issue was opened for this.

Previous Behavior

With Docker 29, the 5 cases of the functional test test_running_networks fail on main, for example:

{'container': {'Networks': {'salt-network-04bke0': {'IPAMConfig': {'new': {'IPv4Address': '10.247.197.116', 'IPv6Address': ''}, 'old': {'IPv4Address': '10.247.197.110', 'IPv6Address': ''}}}}}}
!=
{'container': {'Networks': {'salt-network-04bke0': {'IPAMConfig': {'new': {'IPv4Address': '10.247.197.116'}, 'old': {'IPv4Address': '10.247.197.110'}}}}}}

New Behavior

The reported changes contain only explicitly set addresses, and an automatic IP is reported as automatic. All cases of test_running_networks pass with Docker 29.

Merge requirements satisfied?

[NOTICE] Bug fixes or new features require tests.

  • Docs
  • Changelog - changelog/+container-networks-ipamconfig.fixed.md (I can rename it once it has a number)
  • Tests written/updated - a unit test with Docker 29's shapes for automatic, newly connected, changed and static-to-automatic IP configurations (4 of its 5 cases fail without the fix).

Commits signed with GPG?

Yes

Docker 29 reports addresses which were not set explicitly as empty
strings in a container's per-network IPAMConfig, for example
{"IPv4Address": "", "IPv6Address": ""} for an automatic IP.
docker.compare_container_networks passed them through, so the network
changes which docker_container.running reports contained empty strings.
It also decides whether an IP configuration is static with
bool(IPAMConfig), so an automatic IP counted as a static one. Because
of this, the functional test_running_networks fails on main with
Docker 29.

Drop the empty values when reading the networks, so that an IPAMConfig
without explicitly set addresses counts as no static configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant