Merge pull request #9563 from mlegenovic/master

Compat api containers/json Ports field is null
This commit is contained in:
OpenShift Merge Robot 2021-03-02 05:08:22 -08:00 committed by GitHub
commit c7267329bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -307,6 +307,21 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
}
}
portMappings, err := l.PortMappings()
if err != nil {
return nil, err
}
ports := make([]types.Port, len(portMappings))
for idx, portMapping := range portMappings {
ports[idx] = types.Port{
IP: portMapping.HostIP,
PrivatePort: uint16(portMapping.ContainerPort),
PublicPort: uint16(portMapping.HostPort),
Type: portMapping.Protocol,
}
}
return &handlers.Container{Container: types.Container{
ID: l.ID(),
Names: []string{fmt.Sprintf("/%s", l.Name())},
@ -314,7 +329,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
ImageID: imageID,
Command: strings.Join(l.Command(), " "),
Created: l.CreatedTime().Unix(),
Ports: nil,
Ports: ports,
SizeRw: sizeRW,
SizeRootFs: sizeRootFs,
Labels: l.Labels(),

View file

@ -246,3 +246,13 @@ t GET containers/$cid/json 200 \
.Mounts[0].Destination="/test"
t DELETE containers/$cid?v=true 204
# test port mapping
podman run -d --rm --name bar -p 8080:9090 $IMAGE top
t GET containers/json 200 \
.[0].Ports[0].PrivatePort=9090 \
.[0].Ports[0].PublicPort=8080 \
.[0].Ports[0].Type="tcp"
podman stop bar