compat: Add DefaultAddressPools field to GET /info

Signed-off-by: Nicola Sella <nsella@redhat.com>
This commit is contained in:
Nicola Sella 2025-05-12 16:09:43 +02:00
parent ee283c7514
commit 7c0262db3d
No known key found for this signature in database
GPG Key ID: 3513D09FD6569F2B
2 changed files with 100 additions and 47 deletions

View File

@ -69,6 +69,7 @@ func GetInfo(w http.ResponseWriter, r *http.Request) {
ContainersRunning: stateInfo[define.ContainerStateRunning],
ContainersStopped: stateInfo[define.ContainerStateStopped] + stateInfo[define.ContainerStateExited],
Debug: log.IsLevelEnabled(log.DebugLevel),
DefaultAddressPools: getDefaultAddressPools(configInfo),
DefaultRuntime: configInfo.Engine.OCIRuntime,
DockerRootDir: infoData.Store.GraphRoot,
Driver: infoData.Store.GraphDriverName,
@ -237,3 +238,24 @@ func getEnv(value string) string {
}
return ""
}
func getDefaultAddressPools(configInfo *config.Config) []dockerSystem.NetworkAddressPool {
// Convert DefaultSubnetPools to DefaultAddressPools
if len(configInfo.Network.DefaultSubnetPools) == 0 {
return nil
}
pools := make([]dockerSystem.NetworkAddressPool, 0, len(configInfo.Network.DefaultSubnetPools))
for _, pool := range configInfo.Network.DefaultSubnetPools {
if pool.Base == nil {
continue
}
pools = append(pools, dockerSystem.NetworkAddressPool{
Base: pool.Base.String(),
Size: pool.Size,
})
}
return pools
}

View File

@ -0,0 +1,31 @@
# -*- sh -*-
#
# subnet pools conversion tests
#
# Create a temporary containers.conf with custom DefaultSubnetPools
testdir=$(mktemp -d)
cat > $testdir/containers.default_subnet_pools.conf <<EOF
[network]
default_subnet_pools = [
{ "base" = "10.89.0.0/16", "size" = 24 },
{ "base" = "10.90.0.0/15", "size" = 26 }
]
EOF
# Restart podman with custom config
stop_service
CONTAINERS_CONF=$testdir/containers.default_subnet_pools.conf start_service
# Test the Docker-compatible API endpoints
t GET info 200 \
'.DefaultAddressPools | length=2' \
'.DefaultAddressPools[0].Base=10.89.0.0/16' \
'.DefaultAddressPools[0].Size=24' \
'.DefaultAddressPools[1].Base=10.90.0.0/15' \
'.DefaultAddressPools[1].Size=26'
# Restart with the default containers.conf for next tests.
rm -rf $testdir
stop_service
start_service