api: Deprecate response fields from GET /containers/{id}/json

The Docker API 1.44 deprecates the fields HairpinMode, LinkLocalIPv6Address,
LinkLocalIPv6PrefixLen, SecondaryIPAddresses, SecondaryIPv6Addresses available in
NetworkSettings when calling GET /containers/{id}/json and will be removed in a future release.
You should instead look for the default network in NetworkSettings.Networks.

The fields are removed in 1.52. Version gate SecondaryIPAddresses, SecondaryIPv6Addresses
in the handler and update test. HairpinMode, LinkLocalIPv6Address, LinkLocalIPv6PrefixLen
are not returned by the compat endpoint as the response is serialized
to the moby/moby/api structure missing these fields.

Fixes: https://redhat.atlassian.net/browse/RUN-3323

Signed-off-by: Marek Simek <msimek@redhat.com>
This commit is contained in:
Marek Simek 2026-05-25 12:25:28 +02:00
parent f4925bae8c
commit 612c7b71b4
No known key found for this signature in database
GPG key ID: 87ACBB2D068C0A77
2 changed files with 17 additions and 2 deletions

View file

@ -212,6 +212,12 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
if _, err := utils.SupportedVersion(r, ">=1.52.0"); err == nil || errors.Is(err, apiutil.ErrVersionNotGiven) {
if api.NetworkSettings != nil {
api.NetworkSettings.SecondaryIPAddresses = nil
api.NetworkSettings.SecondaryIPv6Addresses = nil
}
}
utils.WriteResponse(w, http.StatusOK, api)
}

View file

@ -535,13 +535,22 @@ class ContainerCompatibleAPITestCase(APITestCase):
r = requests.post(self.uri(self.resolve_container("/containers/{}/start")))
self.assertIn(r.status_code, (204, 304), r.text)
r = requests.get(self.compat_uri(self.resolve_container("/containers/{}/json")))
container_uri = self.resolve_container("/containers/{}/json")
# SecondaryIPAddresses present for API < v1.52
r = requests.get(self.podman_url + "/v1.44/" + container_uri)
self.assertEqual(r.status_code, 200, r.text)
self.assertId(r.content)
out = r.json()
self.assertEqual("10.0.2.0", out["NetworkSettings"]["SecondaryIPAddresses"][0]["Addr"])
self.assertEqual(24, out["NetworkSettings"]["SecondaryIPAddresses"][0]["PrefixLen"])
# SecondaryIPAddresses removed for API >= v1.52
r = requests.get(self.podman_url + "/v1.52/" + container_uri)
self.assertEqual(r.status_code, 200, r.text)
self.assertId(r.content)
out = r.json()
self.assertIsNone(out["NetworkSettings"].get("SecondaryIPAddresses"))
finally:
delete_named_network_ns(network_ns_name)