mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Merge pull request #8427 from rhatdan/ps
Handle ps container created field as a time.Time
This commit is contained in:
@ -144,7 +144,7 @@ func checkFlags(c *cobra.Command) error {
|
|||||||
func jsonOut(responses []entities.ListContainer) error {
|
func jsonOut(responses []entities.ListContainer) error {
|
||||||
r := make([]entities.ListContainer, 0)
|
r := make([]entities.ListContainer, 0)
|
||||||
for _, con := range responses {
|
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()
|
con.Status = psReporter{con}.Status()
|
||||||
r = append(r, con)
|
r = append(r, con)
|
||||||
}
|
}
|
||||||
@ -404,12 +404,12 @@ func (l psReporter) Ports() string {
|
|||||||
// CreatedAt returns the container creation time in string format. podman
|
// CreatedAt returns the container creation time in string format. podman
|
||||||
// and docker both return a timestamped value for createdat
|
// and docker both return a timestamped value for createdat
|
||||||
func (l psReporter) CreatedAt() string {
|
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
|
// CreateHuman allows us to output the created time in human readable format
|
||||||
func (l psReporter) CreatedHuman() string {
|
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
|
// Cgroup exposes .Namespaces.Cgroup
|
||||||
|
@ -3,6 +3,7 @@ package entities
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containers/podman/v2/pkg/ps/define"
|
"github.com/containers/podman/v2/pkg/ps/define"
|
||||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||||
@ -14,7 +15,7 @@ type ListContainer struct {
|
|||||||
// Container command
|
// Container command
|
||||||
Command []string
|
Command []string
|
||||||
// Container creation time
|
// Container creation time
|
||||||
Created int64
|
Created time.Time
|
||||||
// Human readable container creation time.
|
// Human readable container creation time.
|
||||||
CreatedAt string
|
CreatedAt string
|
||||||
// If container has exited/stopped
|
// If container has exited/stopped
|
||||||
@ -137,7 +138,7 @@ func (a psSortedSize) Less(i, j int) bool {
|
|||||||
type PsSortedCreateTime struct{ SortListContainers }
|
type PsSortedCreateTime struct{ SortListContainers }
|
||||||
|
|
||||||
func (a PsSortedCreateTime) Less(i, j int) bool {
|
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) {
|
func SortPsOutput(sortBy string, psOutput SortListContainers) (SortListContainers, error) {
|
||||||
|
@ -180,7 +180,7 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
|||||||
|
|
||||||
ps := entities.ListContainer{
|
ps := entities.ListContainer{
|
||||||
Command: conConfig.Command,
|
Command: conConfig.Command,
|
||||||
Created: conConfig.CreatedTime.Unix(),
|
Created: conConfig.CreatedTime,
|
||||||
Exited: exited,
|
Exited: exited,
|
||||||
ExitCode: exitCode,
|
ExitCode: exitCode,
|
||||||
ExitedAt: exitedTime.Unix(),
|
ExitedAt: exitedTime.Unix(),
|
||||||
@ -231,7 +231,7 @@ func ListStorageContainer(rt *libpod.Runtime, ctr storage.Container, opts entiti
|
|||||||
|
|
||||||
ps := entities.ListContainer{
|
ps := entities.ListContainer{
|
||||||
ID: ctr.ID,
|
ID: ctr.ID,
|
||||||
Created: ctr.Created.Unix(),
|
Created: ctr.Created,
|
||||||
ImageID: ctr.ImageID,
|
ImageID: ctr.ImageID,
|
||||||
State: "storage",
|
State: "storage",
|
||||||
Names: []string{name},
|
Names: []string{name},
|
||||||
@ -301,5 +301,5 @@ func (a SortPSContainers) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|||||||
type SortPSCreateTime struct{ SortPSContainers }
|
type SortPSCreateTime struct{ SortPSContainers }
|
||||||
|
|
||||||
func (a SortPSCreateTime) Less(i, j int) bool {
|
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)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user