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

72 lines
1.9 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
)
var runtimeStatusCommand = cli.Command{
Name: "info",
Usage: "Display information of the container runtime",
ArgsUsage: "",
SkipArgReorder: true,
UseShortOptionHandling: true,
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Value: "json",
Usage: "Output format, One of: json|yaml",
},
2019-07-10 03:51:02 +00:00
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not show verbose information",
},
2019-02-08 04:04:22 +00:00
},
Action: func(context *cli.Context) error {
err := Info(context, runtimeClient)
if err != nil {
return fmt.Errorf("getting status of runtime failed: %v", err)
}
return nil
},
Before: getRuntimeClient,
After: closeConnection,
}
// 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
}
return outputStatusInfo(status, r.Info, cliContext.String("output"))
}