aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-08-08 18:35:21 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-08-11 13:47:54 +0800
commit6ebd257245a611246bb3ce9c6712c5eb19a9efb4 (patch)
tree737a742e1328cc08d91e54956a6306212caada28
parentdf0ad51075102c49d170bfeb77085b3c9c251ed6 (diff)
downloadpodman-6ebd257245a611246bb3ce9c6712c5eb19a9efb4.tar.gz
podman-6ebd257245a611246bb3ce9c6712c5eb19a9efb4.tar.bz2
podman-6ebd257245a611246bb3ce9c6712c5eb19a9efb4.zip
Add the Status field in the ps --format=json
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
-rw-r--r--cmd/podman/containers/ps.go1
-rw-r--r--pkg/domain/entities/container_ps.go2
-rw-r--r--test/e2e/ps_test.go15
3 files changed, 18 insertions, 0 deletions
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index 64271031d..ebb6ed98f 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -109,6 +109,7 @@ func jsonOut(responses []entities.ListContainer) error {
r := make([]entities.ListContainer, 0)
for _, con := range responses {
con.CreatedAt = units.HumanDuration(time.Since(time.Unix(con.Created, 0))) + " ago"
+ con.Status = psReporter{con}.Status()
r = append(r, con)
}
b, err := json.MarshalIndent(r, "", " ")
diff --git a/pkg/domain/entities/container_ps.go b/pkg/domain/entities/container_ps.go
index 50dd4933b..ed40a37ab 100644
--- a/pkg/domain/entities/container_ps.go
+++ b/pkg/domain/entities/container_ps.go
@@ -56,6 +56,8 @@ type ListContainer struct {
StartedAt int64
// State of container
State string
+ // Status is a human-readable approximation of a duration for json output
+ Status string
}
// ListContainer Namespaces contains the identifiers of the container's Linux namespaces
diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go
index f10ef5c99..a734d399d 100644
--- a/test/e2e/ps_test.go
+++ b/test/e2e/ps_test.go
@@ -188,6 +188,21 @@ var _ = Describe("Podman ps", func() {
Expect(result.IsJSONOutputValid()).To(BeTrue())
})
+ It("podman ps print a human-readable `Status` with json format", func() {
+ _, ec, _ := podmanTest.RunLsContainer("test1")
+ Expect(ec).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"ps", "-a", "--format", "json"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.IsJSONOutputValid()).To(BeTrue())
+ // must contain "Status"
+ match, StatusLine := result.GrepString(`Status`)
+ Expect(match).To(BeTrue())
+ // container is running or exit, so it must contain `ago`
+ Expect(StatusLine[0]).To(ContainSubstring("ago"))
+ })
+
It("podman ps namespace flag with go template format", func() {
Skip(v2fail)
_, ec, _ := podmanTest.RunLsContainer("test1")