From 7c0262db3d1609e770f29844c2838f3e2bf9e3d5 Mon Sep 17 00:00:00 2001 From: Nicola Sella Date: Mon, 12 May 2025 16:09:43 +0200 Subject: [PATCH] compat: Add DefaultAddressPools field to GET /info Signed-off-by: Nicola Sella --- pkg/api/handlers/compat/info.go | 116 +++++++++++++++++++------------- test/apiv2/47-subnet-pools.at | 31 +++++++++ 2 files changed, 100 insertions(+), 47 deletions(-) create mode 100644 test/apiv2/47-subnet-pools.at diff --git a/pkg/api/handlers/compat/info.go b/pkg/api/handlers/compat/info.go index 1f6e249b74..b4c82910f4 100644 --- a/pkg/api/handlers/compat/info.go +++ b/pkg/api/handlers/compat/info.go @@ -55,53 +55,54 @@ func GetInfo(w http.ResponseWriter, r *http.Request) { // liveRestoreEnabled := criu.CheckForCriu() && configInfo.RuntimeSupportsCheckpoint() info := &handlers.Info{ Info: dockerSystem.Info{ - Architecture: goRuntime.GOARCH, - BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, - BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, - CPUCfsPeriod: sysInfo.CPUCfsPeriod, - CPUCfsQuota: sysInfo.CPUCfsQuota, - CPUSet: sysInfo.Cpuset, - CPUShares: sysInfo.CPUShares, - CgroupDriver: configInfo.Engine.CgroupManager, - ContainerdCommit: dockerSystem.Commit{}, - Containers: infoData.Store.ContainerStore.Number, - ContainersPaused: stateInfo[define.ContainerStatePaused], - ContainersRunning: stateInfo[define.ContainerStateRunning], - ContainersStopped: stateInfo[define.ContainerStateStopped] + stateInfo[define.ContainerStateExited], - Debug: log.IsLevelEnabled(log.DebugLevel), - DefaultRuntime: configInfo.Engine.OCIRuntime, - DockerRootDir: infoData.Store.GraphRoot, - Driver: infoData.Store.GraphDriverName, - DriverStatus: getGraphStatus(infoData.Store.GraphStatus), - ExperimentalBuild: true, - GenericResources: nil, - HTTPProxy: getEnv("http_proxy"), - HTTPSProxy: getEnv("https_proxy"), - ID: uuid.New().String(), - IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, - Images: infoData.Store.ImageStore.Number, - IndexServerAddress: "", - InitBinary: "", - InitCommit: dockerSystem.Commit{}, - Isolation: "", - KernelMemoryTCP: false, - KernelVersion: infoData.Host.Kernel, - Labels: nil, - LiveRestoreEnabled: false, - LoggingDriver: "", - MemTotal: infoData.Host.MemTotal, - MemoryLimit: sysInfo.MemoryLimit, - NCPU: goRuntime.NumCPU(), - NEventsListener: 0, - NFd: getFdCount(), - NGoroutines: goRuntime.NumGoroutine(), - Name: infoData.Host.Hostname, - NoProxy: getEnv("no_proxy"), - OSType: goRuntime.GOOS, - OSVersion: infoData.Host.Distribution.Version, - OomKillDisable: sysInfo.OomKillDisable, - OperatingSystem: infoData.Host.Distribution.Distribution, - PidsLimit: sysInfo.PidsLimit, + Architecture: goRuntime.GOARCH, + BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, + BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, + CPUCfsPeriod: sysInfo.CPUCfsPeriod, + CPUCfsQuota: sysInfo.CPUCfsQuota, + CPUSet: sysInfo.Cpuset, + CPUShares: sysInfo.CPUShares, + CgroupDriver: configInfo.Engine.CgroupManager, + ContainerdCommit: dockerSystem.Commit{}, + Containers: infoData.Store.ContainerStore.Number, + ContainersPaused: stateInfo[define.ContainerStatePaused], + 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, + DriverStatus: getGraphStatus(infoData.Store.GraphStatus), + ExperimentalBuild: true, + GenericResources: nil, + HTTPProxy: getEnv("http_proxy"), + HTTPSProxy: getEnv("https_proxy"), + ID: uuid.New().String(), + IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, + Images: infoData.Store.ImageStore.Number, + IndexServerAddress: "", + InitBinary: "", + InitCommit: dockerSystem.Commit{}, + Isolation: "", + KernelMemoryTCP: false, + KernelVersion: infoData.Host.Kernel, + Labels: nil, + LiveRestoreEnabled: false, + LoggingDriver: "", + MemTotal: infoData.Host.MemTotal, + MemoryLimit: sysInfo.MemoryLimit, + NCPU: goRuntime.NumCPU(), + NEventsListener: 0, + NFd: getFdCount(), + NGoroutines: goRuntime.NumGoroutine(), + Name: infoData.Host.Hostname, + NoProxy: getEnv("no_proxy"), + OSType: goRuntime.GOOS, + OSVersion: infoData.Host.Distribution.Version, + OomKillDisable: sysInfo.OomKillDisable, + OperatingSystem: infoData.Host.Distribution.Distribution, + PidsLimit: sysInfo.PidsLimit, Plugins: dockerSystem.PluginsInfo{ Volume: infoData.Plugins.Volume, Network: infoData.Plugins.Network, @@ -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 +} diff --git a/test/apiv2/47-subnet-pools.at b/test/apiv2/47-subnet-pools.at new file mode 100644 index 0000000000..eb5ce0337f --- /dev/null +++ b/test/apiv2/47-subnet-pools.at @@ -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 <