cri-o/cmd/client/main.go
Haiyan Meng 5c4a79543f Add Server.Version and cmd/client test code
Signed-off-by: Haiyan Meng <hmeng@redhat.com>
2016-09-09 14:41:03 -07:00

57 lines
1.4 KiB
Go

package main
import (
"log"
"os"
pb "github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"github.com/urfave/cli"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const (
address = "localhost:49999"
)
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
func Version(client pb.RuntimeServiceClient, version string) error {
r, err := client.Version(context.Background(), &pb.VersionRequest{Version: &version})
if err != nil {
return err
}
log.Printf("VersionResponse: Version: %s, RuntimeName: %s, RuntimeVersion: %s, RuntimeApiVersion: %s\n", *r.Version, *r.RuntimeName, *r.RuntimeVersion, *r.RuntimeApiVersion)
return nil
}
func main() {
app := cli.NewApp()
app.Name = "ocidclient"
app.Usage = "Testing services provided by ocid"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "runtimeversion",
Value: "715fec664d75c6b5cb5b12718458621d4b75df37",
Usage: "the version of the gPRC client API",
},
}
app.Action = func(cxt *cli.Context) error {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer conn.Close()
client := pb.NewRuntimeServiceClient(conn)
// Test RuntimeServiceClient.Version
err = Version(client, cxt.String("runtimeversion"))
if err != nil {
log.Fatalf("%s.Version failed: %v", app.Name, err)
}
return nil
}
app.Run(os.Args)
}