Skip to content

Commit

Permalink
ctr: drop labels from ctr containers subcommand list
Browse files Browse the repository at this point in the history
The labels can be very long (e.g. cri-containerd stores a large JSON metadata
blob as `io.cri-containerd.container.metadata`) which renders the output
useless due to all the line wrapping etc.

The information is still available in `ctr containers info «name»`.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
  • Loading branch information
ijc committed Aug 31, 2017
1 parent c1c2aaf commit 94b0d0e
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions cmd/ctr/containers.go
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"strings"
"text/tabwriter"

"github.com/urfave/cli"
Expand Down Expand Up @@ -48,26 +47,17 @@ var containersCommand = cli.Command{
return nil
}
w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, ' ', 0)
fmt.Fprintln(w, "CONTAINER\tIMAGE\tRUNTIME\tLABELS\t")
fmt.Fprintln(w, "CONTAINER\tIMAGE\tRUNTIME\t")
for _, c := range containers {
var labelStrings []string
for k, v := range c.Info().Labels {
labelStrings = append(labelStrings, strings.Join([]string{k, v}, "="))
}
labels := strings.Join(labelStrings, ",")
if labels == "" {
labels = "-"
}
imageName := c.Info().Image
if imageName == "" {
imageName = "-"
}
record := c.Info()
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\t\n",
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t\n",
c.ID(),
imageName,
record.Runtime.Name,
labels,
); err != nil {
return err
}
Expand Down

0 comments on commit 94b0d0e

Please sign in to comment.