Browse code

Add DefaultAddressPools to docker info #40388

Signed-off-by: Wang Yumu <37442693@qq.com>

Wang Yumu authored on 2020/07/07 12:17:51
Showing 3 changed files
... ...
@@ -4676,6 +4676,25 @@ definitions:
4676 4676
           such as number of nodes, and expiration are included.
4677 4677
         type: "string"
4678 4678
         example: "Community Engine"
4679
+      DefaultAddressPools:
4680
+        description: |
4681
+          List of custom default address pools for local networks, which can be
4682
+          specified in the daemon.json file or dockerd option.
4683
+
4684
+          Example: a Base "10.10.0.0/16" with Size 24 will define the set of 256
4685
+          10.10.[0-255].0/24 address pools.
4686
+        type: "array"
4687
+        items:
4688
+          type: "object"
4689
+          properties:
4690
+            Base:
4691
+              description: "The network address in CIDR format"
4692
+              type: "string"
4693
+              example: "10.10.0.0/16"
4694
+            Size:
4695
+              description: "The network pool size"
4696
+              type: "integer"
4697
+              example: "24"
4679 4698
       Warnings:
4680 4699
         description: |
4681 4700
           List of warnings / informational messages about missing features, or
... ...
@@ -203,15 +203,16 @@ type Info struct {
203 203
 	// LiveRestoreEnabled determines whether containers should be kept
204 204
 	// running when the daemon is shutdown or upon daemon start if
205 205
 	// running containers are detected
206
-	LiveRestoreEnabled bool
207
-	Isolation          container.Isolation
208
-	InitBinary         string
209
-	ContainerdCommit   Commit
210
-	RuncCommit         Commit
211
-	InitCommit         Commit
212
-	SecurityOptions    []string
213
-	ProductLicense     string `json:",omitempty"`
214
-	Warnings           []string
206
+	LiveRestoreEnabled  bool
207
+	Isolation           container.Isolation
208
+	InitBinary          string
209
+	ContainerdCommit    Commit
210
+	RuncCommit          Commit
211
+	InitCommit          Commit
212
+	SecurityOptions     []string
213
+	ProductLicense      string `json:",omitempty"`
214
+	DefaultAddressPools []NetworkAddressPool
215
+	Warnings            []string
215 216
 }
216 217
 
217 218
 // KeyValue holds a key/value pair
... ...
@@ -219,6 +220,12 @@ type KeyValue struct {
219 219
 	Key, Value string
220 220
 }
221 221
 
222
+// NetworkAddressPool is a temp struct used by Info struct
223
+type NetworkAddressPool struct {
224
+	Base string
225
+	Size int
226
+}
227
+
222 228
 // SecurityOpt contains the name and options of a security option
223 229
 type SecurityOpt struct {
224 230
 	Name    string
... ...
@@ -78,6 +78,7 @@ func (daemon *Daemon) SystemInfo() *types.Info {
78 78
 	daemon.fillPluginsInfo(v)
79 79
 	daemon.fillSecurityOptions(v, sysInfo)
80 80
 	daemon.fillLicense(v)
81
+	daemon.fillDefaultAddressPools(v)
81 82
 
82 83
 	if v.DefaultRuntime == config.LinuxV1RuntimeName {
83 84
 		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) {
229 229
 	}
230 230
 }
231 231
 
232
+func (daemon *Daemon) fillDefaultAddressPools(v *types.Info) {
233
+	for _, pool := range daemon.configStore.DefaultAddressPools.Value() {
234
+		v.DefaultAddressPools = append(v.DefaultAddressPools, types.NetworkAddressPool{
235
+			Base: pool.Base,
236
+			Size: pool.Size,
237
+		})
238
+	}
239
+}
240
+
232 241
 func hostName() string {
233 242
 	hostname := ""
234 243
 	if hn, err := os.Hostname(); err != nil {