Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Status field in the ps --format=json #7261

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", " ")
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/container_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down