diff --git a/cmd/crictl/image.go b/cmd/crictl/image.go index f0652043d9..3ff1df5b96 100644 --- a/cmd/crictl/image.go +++ b/cmd/crictl/image.go @@ -313,6 +313,58 @@ var removeImageCommand = cli.Command{ }, } +var imageFsInfoCommand = cli.Command{ + Name: "imagefsinfo", + Usage: "Return image filesystem info", + SkipArgReorder: true, + UseShortOptionHandling: true, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "output, o", + Usage: "Output format, One of: json|yaml|table", + }, + }, + Action: func(context *cli.Context) error { + if err := getImageClient(context); err != nil { + return err + } + output := context.String("output") + if output == "" { // default to json output + output = "json" + } + + r, err := ImageFsInfo(imageClient) + if err != nil { + return fmt.Errorf("image filesystem info request failed: %v", err) + } + for _, info := range r.ImageFilesystems { + status, err := protobufObjectToJSON(info) + if err != nil { + return fmt.Errorf("failed to marshal image filesystem info to json: %v", err) + } + + switch output { + case "json", "yaml": + if err := outputStatusInfo(status, nil, output); err != nil { + return fmt.Errorf("failed to output image filesystem info %v", err) + } + continue + case "table": // table output is after this switch block + default: + return fmt.Errorf("output option cannot be %s", output) + } + + // otherwise output in table format + fmt.Printf("TimeStamp: %d\n", info.Timestamp) + fmt.Printf("UsedBytes: %s\n", info.UsedBytes) + fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint) + } + + return nil + + }, +} + func parseCreds(creds string) (string, string, error) { if creds == "" { return "", "", errors.New("credentials can't be empty") @@ -439,3 +491,13 @@ func RemoveImage(client pb.ImageServiceClient, image string) (resp *pb.RemoveIma logrus.Debugf("RemoveImageResponse: %v", resp) return } + +// ImageFsInfo sends an ImageStatusRequest to the server, and parses +// the returned ImageFsInfoResponse. +func ImageFsInfo(client pb.ImageServiceClient) (resp *pb.ImageFsInfoResponse, err error) { + request := &pb.ImageFsInfoRequest{} + logrus.Debugf("ImageFsInfoRequest: %v", request) + resp, err = client.ImageFsInfo(context.Background(), request) + logrus.Debugf("ImageFsInfoResponse: %v", resp) + return +} diff --git a/cmd/crictl/main.go b/cmd/crictl/main.go index 6f25e72ac2..5419bca044 100644 --- a/cmd/crictl/main.go +++ b/cmd/crictl/main.go @@ -102,6 +102,7 @@ func main() { listImageCommand, containerStatusCommand, imageStatusCommand, + imageFsInfoCommand, podStatusCommand, logsCommand, runtimePortForwardCommand,