Skip to content

Commit df22a51

Browse files
committed
api/types: move container-networksettings types to api/types/container
This moves the NetworkSettings, NetworkSettingsBase, DefaultNetworkSettings, and SummaryNetworkSettings types to the api/types/container package, and deprecates the old location. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a045f9e commit df22a51

5 files changed

Lines changed: 122 additions & 94 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package container
2+
3+
import (
4+
"github.com/docker/docker/api/types/network"
5+
"github.com/docker/go-connections/nat"
6+
)
7+
8+
// NetworkSettings exposes the network settings in the api
9+
type NetworkSettings struct {
10+
NetworkSettingsBase
11+
DefaultNetworkSettings
12+
Networks map[string]*network.EndpointSettings
13+
}
14+
15+
// NetworkSettingsBase holds networking state for a container when inspecting it.
16+
type NetworkSettingsBase struct {
17+
Bridge string // Bridge contains the name of the default bridge interface iff it was set through the daemon --bridge flag.
18+
SandboxID string // SandboxID uniquely represents a container's network stack
19+
SandboxKey string // SandboxKey identifies the sandbox
20+
Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
21+
22+
// HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
23+
//
24+
// Deprecated: This field is never set and will be removed in a future release.
25+
HairpinMode bool
26+
// LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
27+
//
28+
// Deprecated: This field is never set and will be removed in a future release.
29+
LinkLocalIPv6Address string
30+
// LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
31+
//
32+
// Deprecated: This field is never set and will be removed in a future release.
33+
LinkLocalIPv6PrefixLen int
34+
SecondaryIPAddresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
35+
SecondaryIPv6Addresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
36+
}
37+
38+
// DefaultNetworkSettings holds network information
39+
// during the 2 release deprecation period.
40+
// It will be removed in Docker 1.11.
41+
type DefaultNetworkSettings struct {
42+
EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
43+
Gateway string // Gateway holds the gateway address for the network
44+
GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
45+
GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
46+
IPAddress string // IPAddress holds the IPv4 address for the network
47+
IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
48+
IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
49+
MacAddress string // MacAddress holds the MAC address for the network
50+
}
51+
52+
// NetworkSettingsSummary provides a summary of container's networks
53+
// in /containers/json
54+
type NetworkSettingsSummary struct {
55+
Networks map[string]*network.EndpointSettings
56+
}

api/types/types.go

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
"github.com/docker/docker/api/types/filters"
88
"github.com/docker/docker/api/types/image"
99
"github.com/docker/docker/api/types/mount"
10-
"github.com/docker/docker/api/types/network"
1110
"github.com/docker/docker/api/types/swarm"
1211
"github.com/docker/docker/api/types/volume"
13-
"github.com/docker/go-connections/nat"
1412
)
1513

1614
const (
@@ -156,7 +154,7 @@ type Container struct {
156154
NetworkMode string `json:",omitempty"`
157155
Annotations map[string]string `json:",omitempty"`
158156
}
159-
NetworkSettings *SummaryNetworkSettings
157+
NetworkSettings *container.NetworkSettingsSummary
160158
Mounts []MountPoint
161159
}
162160

@@ -278,57 +276,7 @@ type ContainerJSON struct {
278276
*ContainerJSONBase
279277
Mounts []MountPoint
280278
Config *container.Config
281-
NetworkSettings *NetworkSettings
282-
}
283-
284-
// NetworkSettings exposes the network settings in the api
285-
type NetworkSettings struct {
286-
NetworkSettingsBase
287-
DefaultNetworkSettings
288-
Networks map[string]*network.EndpointSettings
289-
}
290-
291-
// SummaryNetworkSettings provides a summary of container's networks
292-
// in /containers/json
293-
type SummaryNetworkSettings struct {
294-
Networks map[string]*network.EndpointSettings
295-
}
296-
297-
// NetworkSettingsBase holds networking state for a container when inspecting it.
298-
type NetworkSettingsBase struct {
299-
Bridge string // Bridge contains the name of the default bridge interface iff it was set through the daemon --bridge flag.
300-
SandboxID string // SandboxID uniquely represents a container's network stack
301-
SandboxKey string // SandboxKey identifies the sandbox
302-
Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
303-
304-
// HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
305-
//
306-
// Deprecated: This field is never set and will be removed in a future release.
307-
HairpinMode bool
308-
// LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
309-
//
310-
// Deprecated: This field is never set and will be removed in a future release.
311-
LinkLocalIPv6Address string
312-
// LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
313-
//
314-
// Deprecated: This field is never set and will be removed in a future release.
315-
LinkLocalIPv6PrefixLen int
316-
SecondaryIPAddresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
317-
SecondaryIPv6Addresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
318-
}
319-
320-
// DefaultNetworkSettings holds network information
321-
// during the 2 release deprecation period.
322-
// It will be removed in Docker 1.11.
323-
type DefaultNetworkSettings struct {
324-
EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
325-
Gateway string // Gateway holds the gateway address for the network
326-
GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
327-
GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
328-
IPAddress string // IPAddress holds the IPv4 address for the network
329-
IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
330-
IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
331-
MacAddress string // MacAddress holds the MAC address for the network
279+
NetworkSettings *container.NetworkSettings
332280
}
333281

334282
// MountPoint represents a mount point configuration inside the container.

api/types/types_deprecated.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,26 @@ type ContainerNode struct {
208208
Memory int64
209209
Labels map[string]string
210210
}
211+
212+
// NetworkSettings exposes the network settings in the api.
213+
//
214+
// Deprecated: use [container.NetworkSettings].
215+
type NetworkSettings = container.NetworkSettings
216+
217+
// NetworkSettingsBase holds networking state for a container when inspecting it.
218+
//
219+
// Deprecated: use [container.NetworkSettingsBase].
220+
type NetworkSettingsBase = container.NetworkSettingsBase
221+
222+
// DefaultNetworkSettings holds network information
223+
// during the 2 release deprecation period.
224+
// It will be removed in Docker 1.11.
225+
//
226+
// Deprecated: use [container.DefaultNetworkSettings].
227+
type DefaultNetworkSettings = container.DefaultNetworkSettings
228+
229+
// SummaryNetworkSettings provides a summary of container's networks
230+
// in /containers/json.
231+
//
232+
// Deprecated: use [container.NetworkSettingsSummary].
233+
type SummaryNetworkSettings = container.NetworkSettingsSummary

container/view.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/containerd/log"
1616
"github.com/docker/docker/api/types"
17+
"github.com/docker/docker/api/types/container"
1718
"github.com/docker/docker/api/types/network"
1819
"github.com/docker/docker/errdefs"
1920
"github.com/docker/go-connections/nat"
@@ -299,76 +300,76 @@ func (v *View) GetAllNames() map[string][]string {
299300

300301
// transform maps a (deep) copied Container object to what queries need.
301302
// A lock on the Container is not held because these are immutable deep copies.
302-
func (v *View) transform(container *Container) *Snapshot {
303+
func (v *View) transform(ctr *Container) *Snapshot {
303304
health := types.NoHealthcheck
304-
if container.Health != nil {
305-
health = container.Health.Status()
305+
if ctr.Health != nil {
306+
health = ctr.Health.Status()
306307
}
307308
snapshot := &Snapshot{
308309
Container: types.Container{
309-
ID: container.ID,
310-
Names: v.getNames(container.ID),
311-
ImageID: container.ImageID.String(),
310+
ID: ctr.ID,
311+
Names: v.getNames(ctr.ID),
312+
ImageID: ctr.ImageID.String(),
312313
Ports: []types.Port{},
313-
Mounts: container.GetMountPoints(),
314-
State: container.State.StateString(),
315-
Status: container.State.String(),
316-
Created: container.Created.Unix(),
314+
Mounts: ctr.GetMountPoints(),
315+
State: ctr.State.StateString(),
316+
Status: ctr.State.String(),
317+
Created: ctr.Created.Unix(),
317318
},
318-
CreatedAt: container.Created,
319-
StartedAt: container.StartedAt,
320-
Name: container.Name,
321-
Pid: container.Pid,
322-
Managed: container.Managed,
319+
CreatedAt: ctr.Created,
320+
StartedAt: ctr.StartedAt,
321+
Name: ctr.Name,
322+
Pid: ctr.Pid,
323+
Managed: ctr.Managed,
323324
ExposedPorts: make(nat.PortSet),
324325
PortBindings: make(nat.PortSet),
325326
Health: health,
326-
Running: container.Running,
327-
Paused: container.Paused,
328-
ExitCode: container.ExitCode(),
327+
Running: ctr.Running,
328+
Paused: ctr.Paused,
329+
ExitCode: ctr.ExitCode(),
329330
}
330331

331332
if snapshot.Names == nil {
332333
// Dead containers will often have no name, so make sure the response isn't null
333334
snapshot.Names = []string{}
334335
}
335336

336-
if container.HostConfig != nil {
337-
snapshot.Container.HostConfig.NetworkMode = string(container.HostConfig.NetworkMode)
338-
snapshot.Container.HostConfig.Annotations = maps.Clone(container.HostConfig.Annotations)
339-
snapshot.HostConfig.Isolation = string(container.HostConfig.Isolation)
340-
for binding := range container.HostConfig.PortBindings {
337+
if ctr.HostConfig != nil {
338+
snapshot.Container.HostConfig.NetworkMode = string(ctr.HostConfig.NetworkMode)
339+
snapshot.Container.HostConfig.Annotations = maps.Clone(ctr.HostConfig.Annotations)
340+
snapshot.HostConfig.Isolation = string(ctr.HostConfig.Isolation)
341+
for binding := range ctr.HostConfig.PortBindings {
341342
snapshot.PortBindings[binding] = struct{}{}
342343
}
343344
}
344345

345-
if container.Config != nil {
346-
snapshot.Image = container.Config.Image
347-
snapshot.Labels = container.Config.Labels
348-
for exposed := range container.Config.ExposedPorts {
346+
if ctr.Config != nil {
347+
snapshot.Image = ctr.Config.Image
348+
snapshot.Labels = ctr.Config.Labels
349+
for exposed := range ctr.Config.ExposedPorts {
349350
snapshot.ExposedPorts[exposed] = struct{}{}
350351
}
351352
}
352353

353-
if len(container.Args) > 0 {
354+
if len(ctr.Args) > 0 {
354355
var args []string
355-
for _, arg := range container.Args {
356+
for _, arg := range ctr.Args {
356357
if strings.Contains(arg, " ") {
357358
args = append(args, fmt.Sprintf("'%s'", arg))
358359
} else {
359360
args = append(args, arg)
360361
}
361362
}
362363
argsAsString := strings.Join(args, " ")
363-
snapshot.Command = fmt.Sprintf("%s %s", container.Path, argsAsString)
364+
snapshot.Command = fmt.Sprintf("%s %s", ctr.Path, argsAsString)
364365
} else {
365-
snapshot.Command = container.Path
366+
snapshot.Command = ctr.Path
366367
}
367368

368369
snapshot.Ports = []types.Port{}
369370
networks := make(map[string]*network.EndpointSettings)
370-
if container.NetworkSettings != nil {
371-
for name, netw := range container.NetworkSettings.Networks {
371+
if ctr.NetworkSettings != nil {
372+
for name, netw := range ctr.NetworkSettings.Networks {
372373
if netw == nil || netw.EndpointSettings == nil {
373374
continue
374375
}
@@ -390,7 +391,7 @@ func (v *View) transform(container *Container) *Snapshot {
390391
}
391392
}
392393
}
393-
for port, bindings := range container.NetworkSettings.Ports {
394+
for port, bindings := range ctr.NetworkSettings.Ports {
394395
p, err := nat.ParsePort(port.Port())
395396
if err != nil {
396397
log.G(context.TODO()).WithError(err).Warn("invalid port map")
@@ -418,7 +419,7 @@ func (v *View) transform(container *Container) *Snapshot {
418419
}
419420
}
420421
}
421-
snapshot.NetworkSettings = &types.SummaryNetworkSettings{Networks: networks}
422+
snapshot.NetworkSettings = &container.NetworkSettingsSummary{Networks: networks}
422423

423424
return snapshot
424425
}

daemon/inspect.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string,
7272
}
7373

7474
mountPoints := ctr.GetMountPoints()
75-
networkSettings := &types.NetworkSettings{
76-
NetworkSettingsBase: types.NetworkSettingsBase{
75+
networkSettings := &containertypes.NetworkSettings{
76+
NetworkSettingsBase: containertypes.NetworkSettingsBase{
7777
Bridge: ctr.NetworkSettings.Bridge,
7878
SandboxID: ctr.NetworkSettings.SandboxID,
7979
SandboxKey: ctr.NetworkSettings.SandboxKey,
@@ -247,13 +247,13 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, err
247247

248248
// getDefaultNetworkSettings creates the deprecated structure that holds the information
249249
// about the bridge network for a container.
250-
func getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
250+
func getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) containertypes.DefaultNetworkSettings {
251251
nw, ok := networks[networktypes.NetworkBridge]
252252
if !ok || nw.EndpointSettings == nil {
253-
return types.DefaultNetworkSettings{}
253+
return containertypes.DefaultNetworkSettings{}
254254
}
255255

256-
return types.DefaultNetworkSettings{
256+
return containertypes.DefaultNetworkSettings{
257257
EndpointID: nw.EndpointSettings.EndpointID,
258258
Gateway: nw.EndpointSettings.Gateway,
259259
GlobalIPv6Address: nw.EndpointSettings.GlobalIPv6Address,

0 commit comments

Comments
 (0)