Skip to content

Commit

Permalink
Merge pull request #361 from yanxuean/concise-imageid
Browse files Browse the repository at this point in the history
show concise image info for crictl ps
  • Loading branch information
Random-Liu authored Aug 13, 2018
2 parents d658483 + eb736dc commit 9d4dd73
Show file tree
Hide file tree
Showing 14 changed files with 1,228 additions and 17 deletions.
12 changes: 8 additions & 4 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

units "github.com/docker/go-units"
godigest "github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"golang.org/x/net/context"
Expand Down Expand Up @@ -625,14 +626,17 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
ctm := units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago"
if !opts.verbose {
id := c.Id
image := c.Image.Image
if !opts.noTrunc {
id = strings.TrimPrefix(c.Id, "")
if len(id) > truncatedIDLen {
id = id[:truncatedIDLen]
id = getTruncatedID(id, "")

// Now c.Image.Image is imageID in kubelet.
if digest, err := godigest.Parse(image); err == nil {
image = getTruncatedID(digest.String(), string(digest.Algorithm())+":")
}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\n",
id, c.Image.Image, ctm, convertContainerState(c.State), c.Metadata.Name, c.Metadata.Attempt)
id, image, ctm, convertContainerState(c.State), c.Metadata.Name, c.Metadata.Attempt)
continue
}

Expand Down
5 changes: 1 addition & 4 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ var listImageCommand = cli.Command{
size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3)
id := image.Id
if !noTrunc {
id = strings.TrimPrefix(image.Id, "sha256:")
if len(id) > truncatedIDLen {
id = id[:truncatedIDLen]
}
id = getTruncatedID(id, "sha256:")
}
for _, repoTagPair := range repoTagPairs {
if showDigest {
Expand Down
5 changes: 1 addition & 4 deletions cmd/crictl/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,7 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
ctm := units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago"
id := pod.Id
if !opts.noTrunc {
id = strings.TrimPrefix(pod.Id, "")
if len(id) > truncatedIDLen {
id = id[:truncatedIDLen]
}
id = getTruncatedID(id, "")
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\n",
id, ctm, convertPodState(pod.State), pod.Metadata.Name, pod.Metadata.Namespace, pod.Metadata.Attempt)
Expand Down
6 changes: 1 addition & 5 deletions cmd/crictl/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"sort"
"strings"
"text/tabwriter"
"time"

Expand Down Expand Up @@ -163,10 +162,7 @@ func ContainerStats(client pb.RuntimeServiceClient, opts statsOptions) error {
// Use `+` to work around go vet bug
fmt.Fprintln(w, "CONTAINER\tCPU %"+"\tMEM\tDISK\tINODES")
for _, s := range r.GetStats() {
id := strings.TrimPrefix(s.Attributes.Id, "")
if len(id) > truncatedIDLen {
id = id[:truncatedIDLen]
}
id := getTruncatedID(s.Attributes.Id, "")
cpu := s.GetCpu().GetUsageCoreNanoSeconds().GetValue()
mem := s.GetMemory().GetWorkingSetBytes().GetValue()
disk := s.GetWritableLayer().GetUsedBytes().GetValue()
Expand Down
8 changes: 8 additions & 0 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,11 @@ func jsonFieldFromTag(tag reflect.StructTag) string {
}
return field
}

func getTruncatedID(id, prefix string) string {
id = strings.TrimPrefix(id, prefix)
if len(id) > truncatedIDLen {
id = id[:truncatedIDLen]
}
return id
}
1 change: 1 addition & 0 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/modern-go/reflect2 05fbef0ca5da472bbf96c9322b84a53edc03c9fd
github.com/onsi/ginkgo 67b9df7f55fe1165fd9ad49aca7754cce01a42b8
github.com/onsi/gomega d59fa0ac68bb5dd932ee8d24eed631cdd519efc3
github.com/opencontainers/selinux 4a2974bf1ee960774ffd517717f1f45325af0206
github.com/opencontainers/go-digest c9281466c8b2f606084ac71339773efd177436e7
github.com/pborman/uuid ca53cad383cad2479bbba7f7a1a05797ec1386e4
github.com/sirupsen/logrus 89742aefa4b206dcf400792f3bd35b542998eb3b
github.com/urfave/cli 8e01ec4cd3e2d84ab2fe90d8210528ffbb06d8ff
Expand Down
191 changes: 191 additions & 0 deletions vendor/github.com/opencontainers/go-digest/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9d4dd73

Please sign in to comment.