Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update k8s to 53965 and add verbose for crictl status #167

Merged
merged 2 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 50 additions & 19 deletions cmd/crictl/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,75 @@ limitations under the License.
package main

import (
"bytes"
"encoding/json"
"fmt"

"github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
"github.com/urfave/cli"
"golang.org/x/net/context"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

const (
criClientVersion = "v1alpha1"
)

var runtimeVersionCommand = cli.Command{
Name: "info",
Usage: "Display runtime version information",
var runtimeStatusCommand = cli.Command{
Name: "info",
Usage: "Display information of the container runtime",
ArgsUsage: "",
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Value: "json",
Usage: "Output format, One of: json|yaml",
},
},
Action: func(context *cli.Context) error {
err := Version(runtimeClient, criClientVersion)
err := Info(context, runtimeClient)
if err != nil {
return fmt.Errorf("Getting the runtime version failed: %v", err)
return fmt.Errorf("getting status of runtime failed: %v", err)
}
return nil
},
Before: getRuntimeClient,
After: closeConnection,
}

// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
func Version(client pb.RuntimeServiceClient, version string) error {
request := &pb.VersionRequest{Version: version}
logrus.Debugf("VersionRequest: %v", request)
r, err := client.Version(context.Background(), request)
logrus.Debugf("VersionResponse: %v", r)
// Info sends a StatusRequest to the server, and parses the returned StatusResponse.
func Info(cliContext *cli.Context, client pb.RuntimeServiceClient) error {
request := &pb.StatusRequest{}
logrus.Debugf("StatusRequest: %v", request)
r, err := client.Status(context.Background(), request)
logrus.Debugf("StatusResponse: %v", r)
if err != nil {
return err
}

statusByte, err := json.Marshal(r.Status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this a helper function, because we'll need it for container/sandbox/image status.
I'm fine with doing that in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do late. :)

if err != nil {
return err
}
fmt.Println("Version: ", r.Version)
fmt.Println("RuntimeName: ", r.RuntimeName)
fmt.Println("RuntimeVersion: ", r.RuntimeVersion)
fmt.Println("RuntimeApiVersion: ", r.RuntimeApiVersion)
jsonInfo := "{" + "\"status\":" + string(statusByte) + ","
for k, v := range r.Info {
jsonInfo += "\"" + k + "\"" + v + ","
}
jsonInfo = jsonInfo[:len(jsonInfo)-1]
jsonInfo += "}"

switch cliContext.String("output") {
case "yaml":
yamlInfo, err := yaml.JSONToYAML([]byte(jsonInfo))
if err != nil {
return err
}
fmt.Println(string(yamlInfo))
case "json":
var output bytes.Buffer
if err := json.Indent(&output, []byte(jsonInfo), "", " "); err != nil {
return err
}
fmt.Println(output.String())
default:
fmt.Printf("Don't support %q format\n", cliContext.String("output"))
}
return nil
}
40 changes: 19 additions & 21 deletions cmd/crictl/status.go → cmd/crictl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,43 @@ package main

import (
"fmt"
"os"
"text/tabwriter"

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

var runtimeStatusCommand = cli.Command{
Name: "status",
Usage: "Display status of the container runtime",
ArgsUsage: "",
const (
criClientVersion = "v1alpha1"
)

var runtimeVersionCommand = cli.Command{
Name: "version",
Usage: "Display runtime version information",
Action: func(context *cli.Context) error {
err := Status(runtimeClient)
err := Version(runtimeClient, criClientVersion)
if err != nil {
return fmt.Errorf("Getting status of runtime failed: %v", err)
return fmt.Errorf("getting the runtime version failed: %v", err)
}
return nil
},
Before: getRuntimeClient,
After: closeConnection,
}

// Status sends a StatusRequest to the server, and parses the returned StatusResponse.
func Status(client pb.RuntimeServiceClient) error {
request := &pb.StatusRequest{}
logrus.Debugf("StatusRequest: %v", request)
r, err := client.Status(context.Background(), request)
logrus.Debugf("StatusResponse: %v", r)
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
func Version(client pb.RuntimeServiceClient, version string) error {
request := &pb.VersionRequest{Version: version}
logrus.Debugf("VersionRequest: %v", request)
r, err := client.Version(context.Background(), request)
logrus.Debugf("VersionResponse: %v", r)
if err != nil {
return err
}

w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
fmt.Fprintln(w, "CONDITION\tSTATUS\tREASON\tMESSAGE")
for _, c := range r.GetStatus().GetConditions() {
fmt.Fprintf(w, "%s\t%v\t%s\t%s\n", c.Type, c.Status, c.Reason, c.Message)
}
w.Flush()
fmt.Println("Version: ", r.Version)
fmt.Println("RuntimeName: ", r.RuntimeName)
fmt.Println("RuntimeVersion: ", r.RuntimeVersion)
fmt.Println("RuntimeApiVersion: ", r.RuntimeApiVersion)
return nil
}
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ k8s.io/api 0b011bb8613011ab0909c6a759d9d811dc21a156
k8s.io/apimachinery 1168e538ea3ccf444854d1fdd5681d2d876680a7
k8s.io/client-go 82aa063804cf055e16e8911250f888bc216e8b61
k8s.io/kube-openapi abfc5fbe1cf87ee697db107fdfd24c32fe4397a8
k8s.io/kubernetes acbfde39148a5545c9a09bcf3f5f295ca2f7e376
k8s.io/kubernetes b958430ec2654bac10f74abbeab402c71cf5fa3b
k8s.io/utils 4fe312863be2155a7b68acd2aff1c9221b24e68c
Loading