Skip to content

Commit e32b57b

Browse files
Merge pull request #26115 from inknos/compat-get-info-defaultaddresspool
compat: Add DefaultAddressPools field to GET /info
2 parents 8f8a90a + 7c0262d commit e32b57b

File tree

2 files changed

+100
-47
lines changed

2 files changed

+100
-47
lines changed

pkg/api/handlers/compat/info.go

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,53 +55,54 @@ func GetInfo(w http.ResponseWriter, r *http.Request) {
5555
// liveRestoreEnabled := criu.CheckForCriu() && configInfo.RuntimeSupportsCheckpoint()
5656
info := &handlers.Info{
5757
Info: dockerSystem.Info{
58-
Architecture: goRuntime.GOARCH,
59-
BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
60-
BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
61-
CPUCfsPeriod: sysInfo.CPUCfsPeriod,
62-
CPUCfsQuota: sysInfo.CPUCfsQuota,
63-
CPUSet: sysInfo.Cpuset,
64-
CPUShares: sysInfo.CPUShares,
65-
CgroupDriver: configInfo.Engine.CgroupManager,
66-
ContainerdCommit: dockerSystem.Commit{},
67-
Containers: infoData.Store.ContainerStore.Number,
68-
ContainersPaused: stateInfo[define.ContainerStatePaused],
69-
ContainersRunning: stateInfo[define.ContainerStateRunning],
70-
ContainersStopped: stateInfo[define.ContainerStateStopped] + stateInfo[define.ContainerStateExited],
71-
Debug: log.IsLevelEnabled(log.DebugLevel),
72-
DefaultRuntime: configInfo.Engine.OCIRuntime,
73-
DockerRootDir: infoData.Store.GraphRoot,
74-
Driver: infoData.Store.GraphDriverName,
75-
DriverStatus: getGraphStatus(infoData.Store.GraphStatus),
76-
ExperimentalBuild: true,
77-
GenericResources: nil,
78-
HTTPProxy: getEnv("http_proxy"),
79-
HTTPSProxy: getEnv("https_proxy"),
80-
ID: uuid.New().String(),
81-
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
82-
Images: infoData.Store.ImageStore.Number,
83-
IndexServerAddress: "",
84-
InitBinary: "",
85-
InitCommit: dockerSystem.Commit{},
86-
Isolation: "",
87-
KernelMemoryTCP: false,
88-
KernelVersion: infoData.Host.Kernel,
89-
Labels: nil,
90-
LiveRestoreEnabled: false,
91-
LoggingDriver: "",
92-
MemTotal: infoData.Host.MemTotal,
93-
MemoryLimit: sysInfo.MemoryLimit,
94-
NCPU: goRuntime.NumCPU(),
95-
NEventsListener: 0,
96-
NFd: getFdCount(),
97-
NGoroutines: goRuntime.NumGoroutine(),
98-
Name: infoData.Host.Hostname,
99-
NoProxy: getEnv("no_proxy"),
100-
OSType: goRuntime.GOOS,
101-
OSVersion: infoData.Host.Distribution.Version,
102-
OomKillDisable: sysInfo.OomKillDisable,
103-
OperatingSystem: infoData.Host.Distribution.Distribution,
104-
PidsLimit: sysInfo.PidsLimit,
58+
Architecture: goRuntime.GOARCH,
59+
BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
60+
BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
61+
CPUCfsPeriod: sysInfo.CPUCfsPeriod,
62+
CPUCfsQuota: sysInfo.CPUCfsQuota,
63+
CPUSet: sysInfo.Cpuset,
64+
CPUShares: sysInfo.CPUShares,
65+
CgroupDriver: configInfo.Engine.CgroupManager,
66+
ContainerdCommit: dockerSystem.Commit{},
67+
Containers: infoData.Store.ContainerStore.Number,
68+
ContainersPaused: stateInfo[define.ContainerStatePaused],
69+
ContainersRunning: stateInfo[define.ContainerStateRunning],
70+
ContainersStopped: stateInfo[define.ContainerStateStopped] + stateInfo[define.ContainerStateExited],
71+
Debug: log.IsLevelEnabled(log.DebugLevel),
72+
DefaultAddressPools: getDefaultAddressPools(configInfo),
73+
DefaultRuntime: configInfo.Engine.OCIRuntime,
74+
DockerRootDir: infoData.Store.GraphRoot,
75+
Driver: infoData.Store.GraphDriverName,
76+
DriverStatus: getGraphStatus(infoData.Store.GraphStatus),
77+
ExperimentalBuild: true,
78+
GenericResources: nil,
79+
HTTPProxy: getEnv("http_proxy"),
80+
HTTPSProxy: getEnv("https_proxy"),
81+
ID: uuid.New().String(),
82+
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
83+
Images: infoData.Store.ImageStore.Number,
84+
IndexServerAddress: "",
85+
InitBinary: "",
86+
InitCommit: dockerSystem.Commit{},
87+
Isolation: "",
88+
KernelMemoryTCP: false,
89+
KernelVersion: infoData.Host.Kernel,
90+
Labels: nil,
91+
LiveRestoreEnabled: false,
92+
LoggingDriver: "",
93+
MemTotal: infoData.Host.MemTotal,
94+
MemoryLimit: sysInfo.MemoryLimit,
95+
NCPU: goRuntime.NumCPU(),
96+
NEventsListener: 0,
97+
NFd: getFdCount(),
98+
NGoroutines: goRuntime.NumGoroutine(),
99+
Name: infoData.Host.Hostname,
100+
NoProxy: getEnv("no_proxy"),
101+
OSType: goRuntime.GOOS,
102+
OSVersion: infoData.Host.Distribution.Version,
103+
OomKillDisable: sysInfo.OomKillDisable,
104+
OperatingSystem: infoData.Host.Distribution.Distribution,
105+
PidsLimit: sysInfo.PidsLimit,
105106
Plugins: dockerSystem.PluginsInfo{
106107
Volume: infoData.Plugins.Volume,
107108
Network: infoData.Plugins.Network,
@@ -237,3 +238,24 @@ func getEnv(value string) string {
237238
}
238239
return ""
239240
}
241+
242+
func getDefaultAddressPools(configInfo *config.Config) []dockerSystem.NetworkAddressPool {
243+
// Convert DefaultSubnetPools to DefaultAddressPools
244+
if len(configInfo.Network.DefaultSubnetPools) == 0 {
245+
return nil
246+
}
247+
248+
pools := make([]dockerSystem.NetworkAddressPool, 0, len(configInfo.Network.DefaultSubnetPools))
249+
for _, pool := range configInfo.Network.DefaultSubnetPools {
250+
if pool.Base == nil {
251+
continue
252+
}
253+
254+
pools = append(pools, dockerSystem.NetworkAddressPool{
255+
Base: pool.Base.String(),
256+
Size: pool.Size,
257+
})
258+
}
259+
260+
return pools
261+
}

test/apiv2/47-subnet-pools.at

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- sh -*-
2+
#
3+
# subnet pools conversion tests
4+
#
5+
6+
# Create a temporary containers.conf with custom DefaultSubnetPools
7+
testdir=$(mktemp -d)
8+
cat > $testdir/containers.default_subnet_pools.conf <<EOF
9+
[network]
10+
default_subnet_pools = [
11+
{ "base" = "10.89.0.0/16", "size" = 24 },
12+
{ "base" = "10.90.0.0/15", "size" = 26 }
13+
]
14+
EOF
15+
16+
# Restart podman with custom config
17+
stop_service
18+
CONTAINERS_CONF=$testdir/containers.default_subnet_pools.conf start_service
19+
20+
# Test the Docker-compatible API endpoints
21+
t GET info 200 \
22+
'.DefaultAddressPools | length=2' \
23+
'.DefaultAddressPools[0].Base=10.89.0.0/16' \
24+
'.DefaultAddressPools[0].Size=24' \
25+
'.DefaultAddressPools[1].Base=10.90.0.0/15' \
26+
'.DefaultAddressPools[1].Size=26'
27+
28+
# Restart with the default containers.conf for next tests.
29+
rm -rf $testdir
30+
stop_service
31+
start_service

0 commit comments

Comments
 (0)