Skip to content

Commit

Permalink
Merge pull request #206 from mikebrow/verbose-inspect
Browse files Browse the repository at this point in the history
adding verbose debug output for inspect & inspects
  • Loading branch information
Random-Liu authored Dec 4, 2017
2 parents d736f60 + 0e48c9e commit 6462875
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
24 changes: 20 additions & 4 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ var containerStatusCommand = cli.Command{
Name: "output, o",
Usage: "Output format, One of: json|yaml|table",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not show verbose information",
},
},
Action: func(context *cli.Context) error {
containerID := context.Args().First()
Expand All @@ -232,7 +236,7 @@ var containerStatusCommand = cli.Command{
return err
}

err := ContainerStatus(runtimeClient, containerID, context.String("output"))
err := ContainerStatus(runtimeClient, containerID, context.String("output"), context.Bool("quiet"))
if err != nil {
return fmt.Errorf("Getting the status of the container failed: %v", err)
}
Expand Down Expand Up @@ -457,12 +461,17 @@ func RemoveContainer(client pb.RuntimeServiceClient, ID string) error {

// ContainerStatus sends a ContainerStatusRequest to the server, and parses
// the returned ContainerStatusResponse.
func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error {
func ContainerStatus(client pb.RuntimeServiceClient, ID, output string, quiet bool) error {
verbose := !(quiet)
if output == "" { // default to json output
output = "json"
}
if ID == "" {
return fmt.Errorf("ID cannot be empty")
}
request := &pb.ContainerStatusRequest{
ContainerId: ID,
Verbose: verbose,
}
logrus.Debugf("ContainerStatusRequest: %v", request)
r, err := client.ContainerStatus(context.Background(), request)
Expand All @@ -471,11 +480,15 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error {
return err
}

if output == "json" || output == "yaml" {
switch output {
case "json", "yaml":
return outputStatusInfo(r.Status, r.Info, output)
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}

// output in table format by default.
// output in table format
fmt.Printf("ID: %s\n", r.Status.Id)
if r.Status.Metadata != nil {
if r.Status.Metadata.Name != "" {
Expand All @@ -499,6 +512,9 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error {
}
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
}
if verbose {
fmt.Printf("Info: %v\n", r.GetInfo())
}

return nil
}
Expand Down
32 changes: 26 additions & 6 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ var imageStatusCommand = cli.Command{
Name: "output, o",
Usage: "Output format, One of: json|yaml|table",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not show verbose information",
},
},
Action: func(context *cli.Context) error {
id := context.Args().First()
Expand All @@ -198,7 +202,8 @@ var imageStatusCommand = cli.Command{
return err
}

r, err := ImageStatus(imageClient, id)
verbose := !(context.Bool("quiet"))
r, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status request failed: %v", err)
}
Expand All @@ -208,11 +213,19 @@ var imageStatusCommand = cli.Command{
}

output := context.String("output")
if output == "json" || output == "yaml" {
if output == "" { // default to json output
output = "json"
}

switch output {
case "json", "yaml":
return outputStatusInfo(r.Image, r.Info, output)
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}

// output in table format by default.
// otherwise output in table format
fmt.Printf("ID: %s\n", image.Id)
for _, tag := range image.RepoTags {
fmt.Printf("Tag: %s\n", tag)
Expand All @@ -222,6 +235,9 @@ var imageStatusCommand = cli.Command{
}
size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3)
fmt.Printf("Size: %s\n", size)
if verbose {
fmt.Printf("Info: %v\n", r.GetInfo())
}

return nil
},
Expand All @@ -241,7 +257,8 @@ var removeImageCommand = cli.Command{
return err
}

status, err := ImageStatus(imageClient, id)
var verbose = false
status, err := ImageStatus(imageClient, id, verbose)
if err != nil {
return fmt.Errorf("image status request failed: %v", err)
}
Expand Down Expand Up @@ -342,8 +359,11 @@ func ListImages(client pb.ImageServiceClient, image string) (resp *pb.ListImages

// ImageStatus sends an ImageStatusRequest to the server, and parses
// the returned ImageStatusResponse.
func ImageStatus(client pb.ImageServiceClient, image string) (resp *pb.ImageStatusResponse, err error) {
request := &pb.ImageStatusRequest{Image: &pb.ImageSpec{Image: image}}
func ImageStatus(client pb.ImageServiceClient, image string, verbose bool) (resp *pb.ImageStatusResponse, err error) {
request := &pb.ImageStatusRequest{
Image: &pb.ImageSpec{Image: image},
Verbose: verbose,
}
logrus.Debugf("ImageStatusRequest: %v", request)
resp, err = client.ImageStatus(context.Background(), request)
logrus.Debugf("ImageStatusResponse: %v", resp)
Expand Down
30 changes: 25 additions & 5 deletions cmd/crictl/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ var podSandboxStatusCommand = cli.Command{
Name: "output, o",
Usage: "Output format, One of: json|yaml|table",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not show verbose information",
},
},
Action: func(context *cli.Context) error {
id := context.Args().First()
Expand All @@ -139,7 +143,7 @@ var podSandboxStatusCommand = cli.Command{
return err
}

err := PodSandboxStatus(runtimeClient, id, context.String("output"))
err := PodSandboxStatus(runtimeClient, id, context.String("output"), context.Bool("quiet"))
if err != nil {
return fmt.Errorf("getting the pod sandbox status failed: %v", err)
}
Expand Down Expand Up @@ -270,20 +274,32 @@ func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error {

// PodSandboxStatus sends a PodSandboxStatusRequest to the server, and parses
// the returned PodSandboxStatusResponse.
func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string) error {
func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string, quiet bool) error {
verbose := !(quiet)
if output == "" { // default to json output
output = "json"
}
if ID == "" {
return fmt.Errorf("ID cannot be empty")
}
request := &pb.PodSandboxStatusRequest{PodSandboxId: ID}

request := &pb.PodSandboxStatusRequest{
PodSandboxId: ID,
Verbose: verbose,
}
logrus.Debugf("PodSandboxStatusRequest: %v", request)
r, err := client.PodSandboxStatus(context.Background(), &pb.PodSandboxStatusRequest{PodSandboxId: ID})
r, err := client.PodSandboxStatus(context.Background(), request)
logrus.Debugf("PodSandboxStatusResponse: %v", r)
if err != nil {
return err
}

if output == "json" || output == "yaml" {
switch output {
case "json", "yaml":
return outputStatusInfo(r.Status, r.Info, output)
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}

// output in table format by default.
Expand Down Expand Up @@ -319,6 +335,10 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string) error {
fmt.Printf("\t%s -> %s\n", k, r.Status.Annotations[k])
}
}
if verbose {
fmt.Printf("Info: %v\n", r.GetInfo())
}

return nil
}

Expand Down

0 comments on commit 6462875

Please sign in to comment.