From faa66828aadbed0d0a567fba63db15fc047a8749 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Wed, 29 Nov 2017 12:04:24 -0600 Subject: [PATCH 1/3] adding verbose output switch for inspect Signed-off-by: Mike Brown --- cmd/crictl/container.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/crictl/container.go b/cmd/crictl/container.go index 9fceea3c69..6d8db18076 100644 --- a/cmd/crictl/container.go +++ b/cmd/crictl/container.go @@ -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() @@ -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) } @@ -462,12 +466,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) @@ -476,11 +485,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 != "" { @@ -504,6 +517,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 } From 0a7a812e82e653a9a09f1dc34585e03db19e609e Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Fri, 1 Dec 2017 10:51:32 -0600 Subject: [PATCH 2/3] added inspects options for verbose debug out Signed-off-by: Mike Brown --- cmd/crictl/sandbox.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index c280aafb9c..7d618deb22 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -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() @@ -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) } @@ -275,20 +279,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. @@ -324,6 +340,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 } From 0e48c9e9f895d0dc36960025405beef275e13af2 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Mon, 4 Dec 2017 14:25:29 -0600 Subject: [PATCH 3/3] adds inspecti options for verbose debug out Signed-off-by: Mike Brown --- cmd/crictl/image.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/crictl/image.go b/cmd/crictl/image.go index cc6b4fbe69..2d154ef86b 100644 --- a/cmd/crictl/image.go +++ b/cmd/crictl/image.go @@ -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() @@ -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) } @@ -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) @@ -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 }, @@ -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) } @@ -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)