From 840a12ac90fd41bc0fc170868566b4c422dd404c Mon Sep 17 00:00:00 2001 From: Wang Yumu <37442693@qq.com> Date: Tue, 7 Jul 2020 11:17:51 +0800 Subject: [PATCH] Add DefaultAddressPools to docker info #40388 Signed-off-by: Wang Yumu <37442693@qq.com> --- api/swagger.yaml | 19 +++++++++++++++++++ api/types/types.go | 25 ++++++++++++++++--------- daemon/info.go | 10 ++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 97e80bd6db..835ac51211 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4676,6 +4676,25 @@ definitions: such as number of nodes, and expiration are included. type: "string" example: "Community Engine" + DefaultAddressPools: + description: | + List of custom default address pools for local networks, which can be + specified in the daemon.json file or dockerd option. + + Example: a Base "10.10.0.0/16" with Size 24 will define the set of 256 + 10.10.[0-255].0/24 address pools. + type: "array" + items: + type: "object" + properties: + Base: + description: "The network address in CIDR format" + type: "string" + example: "10.10.0.0/16" + Size: + description: "The network pool size" + type: "integer" + example: "24" Warnings: description: | List of warnings / informational messages about missing features, or diff --git a/api/types/types.go b/api/types/types.go index dd5f2aff8a..1500f1b7f4 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -203,15 +203,16 @@ type Info struct { // LiveRestoreEnabled determines whether containers should be kept // running when the daemon is shutdown or upon daemon start if // running containers are detected - LiveRestoreEnabled bool - Isolation container.Isolation - InitBinary string - ContainerdCommit Commit - RuncCommit Commit - InitCommit Commit - SecurityOptions []string - ProductLicense string `json:",omitempty"` - Warnings []string + LiveRestoreEnabled bool + Isolation container.Isolation + InitBinary string + ContainerdCommit Commit + RuncCommit Commit + InitCommit Commit + SecurityOptions []string + ProductLicense string `json:",omitempty"` + DefaultAddressPools []NetworkAddressPool + Warnings []string } // KeyValue holds a key/value pair @@ -219,6 +220,12 @@ type KeyValue struct { Key, Value string } +// NetworkAddressPool is a temp struct used by Info struct +type NetworkAddressPool struct { + Base string + Size int +} + // SecurityOpt contains the name and options of a security option type SecurityOpt struct { Name string diff --git a/daemon/info.go b/daemon/info.go index cbae94ec47..b47cb7283d 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -78,6 +78,7 @@ func (daemon *Daemon) SystemInfo() *types.Info { daemon.fillPluginsInfo(v) daemon.fillSecurityOptions(v, sysInfo) daemon.fillLicense(v) + daemon.fillDefaultAddressPools(v) if v.DefaultRuntime == config.LinuxV1RuntimeName { v.Warnings = append(v.Warnings, fmt.Sprintf("Configured default runtime %q is deprecated and will be removed in the next release.", config.LinuxV1RuntimeName)) @@ -229,6 +230,15 @@ func (daemon *Daemon) fillAPIInfo(v *types.Info) { } } +func (daemon *Daemon) fillDefaultAddressPools(v *types.Info) { + for _, pool := range daemon.configStore.DefaultAddressPools.Value() { + v.DefaultAddressPools = append(v.DefaultAddressPools, types.NetworkAddressPool{ + Base: pool.Base, + Size: pool.Size, + }) + } +} + func hostName() string { hostname := "" if hn, err := os.Hostname(); err != nil {