Skip to content

Commit ddb910d

Browse files
committed
Always include Ports within inspect response
Related to containerd#3310 New behavior will always initialize a NetworkSettings entity within the inspect response. If the target container does not exist, the NetworkSettings will be full of "zero-value" members. If the target container is active, but ports were not published, then the Ports key of NetworkSettings will have an empty structure value. If the target container is active and ports were published, then the Ports key of NetworkSettings will have populated values. Signed-off-by: Sam Chew <[email protected]>
1 parent 74f2755 commit ddb910d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/inspecttypes/dockercompat/dockercompat.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type ContainerState struct {
186186
}
187187

188188
type NetworkSettings struct {
189-
Ports *nat.PortMap `json:",omitempty"`
189+
Ports *nat.PortMap
190190
DefaultNetworkSettings
191191
Networks map[string]*NetworkEndpointSettings
192192
}
@@ -398,12 +398,15 @@ func statusFromNative(x containerd.Status, labels map[string]string) string {
398398
}
399399

400400
func networkSettingsFromNative(n *native.NetNS, sp *specs.Spec) (*NetworkSettings, error) {
401-
if n == nil {
402-
return nil, nil
403-
}
404401
res := &NetworkSettings{
405402
Networks: make(map[string]*NetworkEndpointSettings),
406403
}
404+
resPortMap := make(nat.PortMap)
405+
res.Ports = &resPortMap
406+
if n == nil {
407+
return res, nil
408+
}
409+
407410
var primary *NetworkEndpointSettings
408411
for _, x := range n.Interfaces {
409412
if x.Interface.Flags&net.FlagLoopback != 0 {
@@ -447,8 +450,11 @@ func networkSettingsFromNative(n *native.NetNS, sp *specs.Spec) (*NetworkSetting
447450
if err != nil {
448451
return nil, err
449452
}
450-
res.Ports = nports
453+
for portLabel, portBindings := range *nports {
454+
resPortMap[portLabel] = portBindings
455+
}
451456
}
457+
452458
if x.Index == n.PrimaryInterface {
453459
primary = nes
454460
}

0 commit comments

Comments
 (0)