k3s/vendor/github.com/kubernetes-sigs/cri-tools/cmd/crictl/version.go

64 lines
1.8 KiB
Go
Raw Normal View History

2019-02-08 04:04:22 +00:00
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package crictl
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"golang.org/x/net/context"
2019-08-30 18:33:25 +00:00
pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
2019-02-08 04:04:22 +00:00
)
const (
criClientVersion = "v1alpha2"
)
var runtimeVersionCommand = cli.Command{
Name: "version",
Usage: "Display runtime version information",
Action: func(context *cli.Context) error {
2019-09-27 21:51:53 +00:00
runtimeClient, runtimeConn, err := getRuntimeClient(context)
if err != nil {
return err
}
defer closeConnection(context, runtimeConn)
err = Version(runtimeClient, criClientVersion)
2019-02-08 04:04:22 +00:00
if err != nil {
return fmt.Errorf("getting the runtime version failed: %v", err)
}
return nil
},
}
// 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
}
fmt.Println("Version: ", r.Version)
fmt.Println("RuntimeName: ", r.RuntimeName)
fmt.Println("RuntimeVersion: ", r.RuntimeVersion)
fmt.Println("RuntimeApiVersion: ", r.RuntimeApiVersion)
return nil
}