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

Handle ps container created field as a time.Time #8427

Merged
merged 1 commit into from
Dec 1, 2020
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
6 changes: 3 additions & 3 deletions cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func checkFlags(c *cobra.Command) error {
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.CreatedAt = units.HumanDuration(time.Since(con.Created)) + " ago"
con.Status = psReporter{con}.Status()
r = append(r, con)
}
Expand Down Expand Up @@ -386,12 +386,12 @@ func (l psReporter) Ports() string {
// CreatedAt returns the container creation time in string format. podman
// and docker both return a timestamped value for createdat
func (l psReporter) CreatedAt() string {
return time.Unix(l.Created, 0).String()
return l.Created.String()
}

// CreateHuman allows us to output the created time in human readable format
func (l psReporter) CreatedHuman() string {
return units.HumanDuration(time.Since(time.Unix(l.Created, 0))) + " ago"
return units.HumanDuration(time.Since(l.Created)) + " ago"
}

// Cgroup exposes .Namespaces.Cgroup
Expand Down
5 changes: 3 additions & 2 deletions pkg/domain/entities/container_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package entities
import (
"sort"
"strings"
"time"

"github.com/containers/podman/v2/pkg/ps/define"
"github.com/cri-o/ocicni/pkg/ocicni"
Expand All @@ -14,7 +15,7 @@ type ListContainer struct {
// Container command
Command []string
// Container creation time
Created int64
Created time.Time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhatdan @jwhonce Is this going over the wire? As in, is this a breaking change to our JSON format?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is going over the wire. The time.Time came over the wire though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this may be a breaking change for anyone who has vendored in /pkg/ directories. So we might have to wait to fix this until 3.0.

// Human readable container creation time.
CreatedAt string
// If container has exited/stopped
Expand Down Expand Up @@ -137,7 +138,7 @@ func (a psSortedSize) Less(i, j int) bool {
type PsSortedCreateTime struct{ SortListContainers }

func (a PsSortedCreateTime) Less(i, j int) bool {
return a.SortListContainers[i].Created < a.SortListContainers[j].Created
return a.SortListContainers[i].Created.Before(a.SortListContainers[j].Created)
}

func SortPsOutput(sortBy string, psOutput SortListContainers) (SortListContainers, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ps/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities

ps := entities.ListContainer{
Command: conConfig.Command,
Created: conConfig.CreatedTime.Unix(),
Created: conConfig.CreatedTime,
Exited: exited,
ExitCode: exitCode,
ExitedAt: exitedTime.Unix(),
Expand Down Expand Up @@ -231,7 +231,7 @@ func ListStorageContainer(rt *libpod.Runtime, ctr storage.Container, opts entiti

ps := entities.ListContainer{
ID: ctr.ID,
Created: ctr.Created.Unix(),
Created: ctr.Created,
ImageID: ctr.ImageID,
State: "storage",
Names: []string{name},
Expand Down Expand Up @@ -301,5 +301,5 @@ func (a SortPSContainers) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type SortPSCreateTime struct{ SortPSContainers }

func (a SortPSCreateTime) Less(i, j int) bool {
return a.SortPSContainers[i].Created > a.SortPSContainers[j].Created
return a.SortPSContainers[i].Created.Before(a.SortPSContainers[j].Created)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused. Was the ">" correct for the original version of this "Less()" function? If so, does this need to be After rather than Before, or are you correcting a bad sort?

Back to my tea cup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwhonce "I'm a mistake in original code", I wasn't aware you've gone full Tron in this project. That's a bit scary! 😄
Thx for the 411

}