Skip to content

Commit 054e158

Browse files
committed
Always include Ports within inspect response
Related to #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 054e158

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.github/workflows/test-canary.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
steps:
4949
- name: Set GO env
5050
run: |
51+
# Enable extended globbing features to use advanced pattern matching
52+
shopt -s extglob
53+
5154
# Get latest containerd
5255
args=(curl --proto '=https' --tlsv1.2 -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
5356
[ "${GITHUB_TOKEN:-}" == "" ] && {
@@ -59,7 +62,8 @@ jobs:
5962
# Get latest golang version and split it in components
6063
norm=()
6164
while read -r line; do
62-
norm+=("$line")
65+
line_trimmed="${line//+([[:space:]])/}"
66+
norm+=("$line_trimmed")
6367
done < \
6468
<(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \
6569
<(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ require (
3535
github.com/coreos/go-systemd/v22 v22.5.0
3636
github.com/cyphar/filepath-securejoin v0.3.1
3737
github.com/distribution/reference v0.6.0
38-
github.com/docker/cli v27.1.1+incompatible
39-
github.com/docker/docker v27.1.1+incompatible
38+
github.com/docker/cli v27.1.2+incompatible
39+
github.com/docker/docker v27.1.2+incompatible
4040
github.com/docker/go-connections v0.5.0
4141
github.com/docker/go-units v0.5.0
4242
github.com/fahedouch/go-logrotate v0.2.1

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
8888
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
8989
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
9090
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
91-
github.com/docker/cli v27.1.1+incompatible h1:goaZxOqs4QKxznZjjBWKONQci/MywhtRv2oNn0GkeZE=
92-
github.com/docker/cli v27.1.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
93-
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
94-
github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
91+
github.com/docker/cli v27.1.2+incompatible h1:nYviRv5Y+YAKx3dFrTvS1ErkyVVunKOhoweCTE1BsnI=
92+
github.com/docker/cli v27.1.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
93+
github.com/docker/docker v27.1.2+incompatible h1:AhGzR1xaQIy53qCkxARaFluI00WPGtXn0AJuoQsVYTY=
94+
github.com/docker/docker v27.1.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
9595
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
9696
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
9797
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=

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)