Skip to content

Commit 93c8113

Browse files
author
Yanqiang Miao
committed
Rename 'crictl info' to 'crictl version' and add verbose for crictl status
Signed-off-by: Yanqiang Miao <[email protected]>
1 parent dfc2e77 commit 93c8113

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

cmd/crictl/info.go

+29-20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122

2223
"github.com/Sirupsen/logrus"
@@ -25,36 +26,44 @@ import (
2526
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
2627
)
2728

28-
const (
29-
criClientVersion = "v1alpha1"
30-
)
31-
32-
var runtimeVersionCommand = cli.Command{
33-
Name: "info",
34-
Usage: "Display runtime version information",
29+
var runtimeStatusCommand = cli.Command{
30+
Name: "info",
31+
Usage: "Display status and extra information of the container runtime",
32+
ArgsUsage: "",
3533
Action: func(context *cli.Context) error {
36-
err := Version(runtimeClient, criClientVersion)
34+
err := Info(runtimeClient)
3735
if err != nil {
38-
return fmt.Errorf("Getting the runtime version failed: %v", err)
36+
return fmt.Errorf("Getting status of runtime failed: %v", err)
3937
}
4038
return nil
4139
},
4240
Before: getRuntimeClient,
4341
After: closeConnection,
4442
}
4543

46-
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
47-
func Version(client pb.RuntimeServiceClient, version string) error {
48-
request := &pb.VersionRequest{Version: version}
49-
logrus.Debugf("VersionRequest: %v", request)
50-
r, err := client.Version(context.Background(), request)
51-
logrus.Debugf("VersionResponse: %v", r)
44+
// Info sends a StatusRequest to the server, and parses the returned StatusResponse.
45+
func Info(client pb.RuntimeServiceClient) error {
46+
request := &pb.StatusRequest{}
47+
logrus.Debugf("StatusRequest: %v", request)
48+
r, err := client.Status(context.Background(), request)
49+
logrus.Debugf("StatusResponse: %v", r)
5250
if err != nil {
5351
return err
5452
}
55-
fmt.Println("Version: ", r.Version)
56-
fmt.Println("RuntimeName: ", r.RuntimeName)
57-
fmt.Println("RuntimeVersion: ", r.RuntimeVersion)
58-
fmt.Println("RuntimeApiVersion: ", r.RuntimeApiVersion)
59-
return nil
53+
54+
statusInfo := struct {
55+
Status *pb.RuntimeStatus
56+
ExtrInfo map[string]interface{}
57+
}{
58+
Status: r.Status,
59+
}
60+
for key, value := range r.Info {
61+
var buf map[string]interface{}
62+
err := json.Unmarshal([]byte(value), &buf)
63+
if err != nil {
64+
return err
65+
}
66+
statusInfo.ExtrInfo[key] = buf
67+
}
68+
return outputJSON(statusInfo)
6069
}

cmd/crictl/status.go cmd/crictl/version.go

+19-21
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,43 @@ package main
1818

1919
import (
2020
"fmt"
21-
"os"
22-
"text/tabwriter"
2321

2422
"github.com/Sirupsen/logrus"
2523
"github.com/urfave/cli"
2624
"golang.org/x/net/context"
2725
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
2826
)
2927

30-
var runtimeStatusCommand = cli.Command{
31-
Name: "status",
32-
Usage: "Display status of the container runtime",
33-
ArgsUsage: "",
28+
const (
29+
criClientVersion = "v1alpha1"
30+
)
31+
32+
var runtimeVersionCommand = cli.Command{
33+
Name: "version",
34+
Usage: "Display runtime version information",
3435
Action: func(context *cli.Context) error {
35-
err := Status(runtimeClient)
36+
err := Version(runtimeClient, criClientVersion)
3637
if err != nil {
37-
return fmt.Errorf("Getting status of runtime failed: %v", err)
38+
return fmt.Errorf("Getting the runtime version failed: %v", err)
3839
}
3940
return nil
4041
},
4142
Before: getRuntimeClient,
4243
After: closeConnection,
4344
}
4445

45-
// Status sends a StatusRequest to the server, and parses the returned StatusResponse.
46-
func Status(client pb.RuntimeServiceClient) error {
47-
request := &pb.StatusRequest{}
48-
logrus.Debugf("StatusRequest: %v", request)
49-
r, err := client.Status(context.Background(), request)
50-
logrus.Debugf("StatusResponse: %v", r)
46+
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
47+
func Version(client pb.RuntimeServiceClient, version string) error {
48+
request := &pb.VersionRequest{Version: version}
49+
logrus.Debugf("VersionRequest: %v", request)
50+
r, err := client.Version(context.Background(), request)
51+
logrus.Debugf("VersionResponse: %v", r)
5152
if err != nil {
5253
return err
5354
}
54-
55-
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
56-
fmt.Fprintln(w, "CONDITION\tSTATUS\tREASON\tMESSAGE")
57-
for _, c := range r.GetStatus().GetConditions() {
58-
fmt.Fprintf(w, "%s\t%v\t%s\t%s\n", c.Type, c.Status, c.Reason, c.Message)
59-
}
60-
w.Flush()
55+
fmt.Println("Version: ", r.Version)
56+
fmt.Println("RuntimeName: ", r.RuntimeName)
57+
fmt.Println("RuntimeVersion: ", r.RuntimeVersion)
58+
fmt.Println("RuntimeApiVersion: ", r.RuntimeApiVersion)
6159
return nil
6260
}

0 commit comments

Comments
 (0)