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 (
|
2020-08-10 17:43:49 +00:00
|
|
|
"github.com/pkg/errors"
|
2019-02-08 04:04:22 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-03-26 21:07:15 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-02-08 04:04:22 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2020-03-26 21:07:15 +00:00
|
|
|
var runtimeStatusCommand = &cli.Command{
|
2019-02-08 04:04:22 +00:00
|
|
|
Name: "info",
|
|
|
|
Usage: "Display information of the container runtime",
|
|
|
|
ArgsUsage: "",
|
|
|
|
UseShortOptionHandling: true,
|
|
|
|
Flags: []cli.Flag{
|
2020-03-26 21:07:15 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "output",
|
|
|
|
Aliases: []string{"o"},
|
|
|
|
Value: "json",
|
|
|
|
Usage: "Output format, One of: json|yaml|go-template",
|
2019-02-08 04:04:22 +00:00
|
|
|
},
|
2020-03-26 21:07:15 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "quiet",
|
|
|
|
Aliases: []string{"q"},
|
|
|
|
Usage: "Do not show verbose information",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "template",
|
|
|
|
Usage: "The template string is only used when output is go-template; The Template format is golang template",
|
2019-07-10 03:51:02 +00:00
|
|
|
},
|
2019-02-08 04:04:22 +00:00
|
|
|
},
|
|
|
|
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 = Info(context, runtimeClient)
|
2019-02-08 04:04:22 +00:00
|
|
|
if err != nil {
|
2020-08-10 17:43:49 +00:00
|
|
|
return errors.Wrap(err, "getting status of runtime")
|
2019-02-08 04:04:22 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info sends a StatusRequest to the server, and parses the returned StatusResponse.
|
|
|
|
func Info(cliContext *cli.Context, client pb.RuntimeServiceClient) error {
|
2019-07-10 03:51:02 +00:00
|
|
|
request := &pb.StatusRequest{Verbose: !cliContext.Bool("quiet")}
|
2019-02-08 04:04:22 +00:00
|
|
|
logrus.Debugf("StatusRequest: %v", request)
|
|
|
|
r, err := client.Status(context.Background(), request)
|
|
|
|
logrus.Debugf("StatusResponse: %v", r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := protobufObjectToJSON(r.Status)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-26 21:07:15 +00:00
|
|
|
return outputStatusInfo(status, r.Info, cliContext.String("output"), cliContext.String("template"))
|
2019-02-08 04:04:22 +00:00
|
|
|
}
|