Merge pull request #7261 from zhangguanzhang/ps-format-add-field

Add the `Status` field in the ps --format=json
This commit is contained in:
OpenShift Merge Robot 2020-08-11 04:22:30 -04:00 committed by GitHub
commit a90ae00df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -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, "", " ")

View File

@ -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

View File

@ -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")