@@ -17,44 +17,75 @@ limitations under the License.
17
17
package main
18
18
19
19
import (
20
+ "bytes"
21
+ "encoding/json"
20
22
"fmt"
21
23
22
24
"github.com/Sirupsen/logrus"
25
+ "github.com/ghodss/yaml"
23
26
"github.com/urfave/cli"
24
27
"golang.org/x/net/context"
25
28
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
26
29
)
27
30
28
- const (
29
- criClientVersion = "v1alpha1"
30
- )
31
-
32
- var runtimeVersionCommand = cli.Command {
33
- Name : "info" ,
34
- Usage : "Display runtime version information" ,
31
+ var runtimeStatusCommand = cli.Command {
32
+ Name : "info" ,
33
+ Usage : "Display information of the container runtime" ,
34
+ ArgsUsage : "" ,
35
+ Flags : []cli.Flag {
36
+ cli.StringFlag {
37
+ Name : "output, o" ,
38
+ Value : "json" ,
39
+ Usage : "Output format, One of: json|yaml" ,
40
+ },
41
+ },
35
42
Action : func (context * cli.Context ) error {
36
- err := Version ( runtimeClient , criClientVersion )
43
+ err := Info ( context , runtimeClient )
37
44
if err != nil {
38
- return fmt .Errorf ("Getting the runtime version failed: %v" , err )
45
+ return fmt .Errorf ("getting status of runtime failed: %v" , err )
39
46
}
40
47
return nil
41
48
},
42
49
Before : getRuntimeClient ,
43
50
After : closeConnection ,
44
51
}
45
52
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 )
53
+ // Info sends a StatusRequest to the server, and parses the returned StatusResponse.
54
+ func Info (cliContext * cli.Context , client pb.RuntimeServiceClient ) error {
55
+ request := & pb.StatusRequest {}
56
+ logrus .Debugf ("StatusRequest: %v" , request )
57
+ r , err := client .Status (context .Background (), request )
58
+ logrus .Debugf ("StatusResponse: %v" , r )
59
+ if err != nil {
60
+ return err
61
+ }
62
+
63
+ statusByte , err := json .Marshal (r .Status )
52
64
if err != nil {
53
65
return err
54
66
}
55
- fmt .Println ("Version: " , r .Version )
56
- fmt .Println ("RuntimeName: " , r .RuntimeName )
57
- fmt .Println ("RuntimeVersion: " , r .RuntimeVersion )
58
- fmt .Println ("RuntimeApiVersion: " , r .RuntimeApiVersion )
67
+ jsonInfo := "{" + "\" status\" :" + string (statusByte ) + ","
68
+ for k , v := range r .Info {
69
+ jsonInfo += "\" " + k + "\" " + v + ","
70
+ }
71
+ jsonInfo = jsonInfo [:len (jsonInfo )- 1 ]
72
+ jsonInfo += "}"
73
+
74
+ switch cliContext .String ("output" ) {
75
+ case "yaml" :
76
+ yamlInfo , err := yaml .JSONToYAML ([]byte (jsonInfo ))
77
+ if err != nil {
78
+ return err
79
+ }
80
+ fmt .Println (string (yamlInfo ))
81
+ case "json" :
82
+ var output bytes.Buffer
83
+ if err := json .Indent (& output , []byte (jsonInfo ), "" , " " ); err != nil {
84
+ return err
85
+ }
86
+ fmt .Println (output .String ())
87
+ default :
88
+ fmt .Printf ("Don't support %q format\n " , cliContext .String ("output" ))
89
+ }
59
90
return nil
60
91
}
0 commit comments