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

show concise image info for crictl ps #361

Merged
merged 2 commits into from
Aug 13, 2018
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
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