Merge pull request #49520 from robmry/inspect_gw6_not_cidr

Fix network inspect IPv6 gateway address format
This commit is contained in:
Sebastiaan van Stijn
2025-02-24 11:53:37 +01:00
committed by GitHub
3 changed files with 24 additions and 2 deletions

View File

@@ -751,9 +751,13 @@ func buildIPAMResources(nw *libnetwork.Network) networktypes.IPAM {
if info.IPAMData.Pool == nil {
continue
}
var gw string
if info.IPAMData.Gateway != nil {
gw = info.IPAMData.Gateway.IP.String()
}
ipamConfig = append(ipamConfig, networktypes.IPAMConfig{
Subnet: info.IPAMData.Pool.String(),
Gateway: info.IPAMData.Gateway.String(),
Gateway: gw,
})
}
}

View File

@@ -57,7 +57,7 @@ func TestDaemonDefaultBridgeIPAM_Docker0(t *testing.T) {
},
expIPAMConfig: []network.IPAMConfig{
{Subnet: "192.168.176.0/24", Gateway: "192.168.176.1"},
{Subnet: "fdd1:8161:2d2c::/64", Gateway: "fdd1:8161:2d2c::1/64"},
{Subnet: "fdd1:8161:2d2c::/64", Gateway: "fdd1:8161:2d2c::1"},
},
},
{

View File

@@ -1542,3 +1542,21 @@ func TestAdvertiseAddresses(t *testing.T) {
})
}
}
// TestNetworkInspectGateway checks that gateways reported in inspect output are parseable as addresses.
func TestNetworkInspectGateway(t *testing.T) {
ctx := setupTest(t)
c := testEnv.APIClient()
const netName = "test-inspgw"
nid, err := network.Create(ctx, c, netName, network.WithIPv6())
assert.NilError(t, err)
defer network.RemoveNoError(ctx, t, c, netName)
insp, err := c.NetworkInspect(ctx, nid, networktypes.InspectOptions{})
assert.NilError(t, err)
for _, ipamCfg := range insp.IPAM.Config {
_, err := netip.ParseAddr(ipamCfg.Gateway)
assert.Check(t, err)
}
}