Merge pull request #5223 from vrothberg/ps-image-id

podman-ps: support image IDs
This commit is contained in:
OpenShift Merge Robot
2020-02-18 16:11:28 +01:00
committed by GitHub
3 changed files with 11 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import (
const ( const (
cidTruncLength = 12 cidTruncLength = 12
podTruncLength = 12 podTruncLength = 12
iidTruncLength = 12
cmdTruncLength = 17 cmdTruncLength = 17
) )
@ -66,6 +67,7 @@ type BatchContainerStruct struct {
type PsContainerOutput struct { type PsContainerOutput struct {
ID string ID string
Image string Image string
ImageID string
Command string Command string
Created string Created string
Ports string Ports string
@ -203,7 +205,7 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
status = "Error" status = "Error"
} }
_, imageName := ctr.Image() imageID, imageName := ctr.Image()
cid := ctr.ID() cid := ctr.ID()
podID := ctr.PodID() podID := ctr.PodID()
if !opts.NoTrunc { if !opts.NoTrunc {
@ -214,6 +216,9 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
if len(command) > cmdTruncLength { if len(command) > cmdTruncLength {
command = command[0:cmdTruncLength] + "..." command = command[0:cmdTruncLength] + "..."
} }
if len(imageID) > iidTruncLength {
imageID = imageID[0:iidTruncLength]
}
} }
ports, err := ctr.PortMappings() ports, err := ctr.PortMappings()
@ -223,6 +228,7 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
pso.ID = cid pso.ID = cid
pso.Image = imageName pso.Image = imageName
pso.ImageID = imageID
pso.Command = command pso.Command = command
pso.Created = created pso.Created = created
pso.Ports = portsToString(ports) pso.Ports = portsToString(ports)

View File

@ -55,7 +55,8 @@ Valid placeholders for the Go template are listed below:
| **Placeholder** | **Description** | | **Placeholder** | **Description** |
| --------------- | ------------------------------------------------ | | --------------- | ------------------------------------------------ |
| .ID | Container ID | | .ID | Container ID |
| .Image | Image ID/Name | | .Image | Image Name/ID |
| .ImageID | Image ID |
| .Command | Quoted command used | | .Command | Quoted command used |
| .CreatedAt | Creation time for container | | .CreatedAt | Creation time for container |
| .RunningFor | Time elapsed since container was started | | .RunningFor | Time elapsed since container was started |

View File

@ -170,10 +170,11 @@ var _ = Describe("Podman ps", func() {
_, ec, _ := podmanTest.RunLsContainer("test1") _, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0)) Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.Labels}}"}) result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.ImageID}} {{.Labels}}"})
result.WaitWithDefaultTimeout() result.WaitWithDefaultTimeout()
Expect(strings.Contains(result.OutputToStringArray()[0], "table")).To(BeFalse()) Expect(strings.Contains(result.OutputToStringArray()[0], "table")).To(BeFalse())
Expect(strings.Contains(result.OutputToStringArray()[0], "ID")).To(BeTrue()) Expect(strings.Contains(result.OutputToStringArray()[0], "ID")).To(BeTrue())
Expect(strings.Contains(result.OutputToStringArray()[0], "ImageID")).To(BeTrue())
Expect(strings.Contains(result.OutputToStringArray()[1], "alpine:latest")).To(BeTrue()) Expect(strings.Contains(result.OutputToStringArray()[1], "alpine:latest")).To(BeTrue())
Expect(result.ExitCode()).To(Equal(0)) Expect(result.ExitCode()).To(Equal(0))
}) })