Skip to content

Commit 22b9ed4

Browse files
authored
Merge pull request #417 from jorgesece/master
Add ImageFSInfo method
2 parents 04babd3 + ce63f6d commit 22b9ed4

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

cmd/crictl/image.go

+62
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,58 @@ var removeImageCommand = cli.Command{
313313
},
314314
}
315315

316+
var imageFsInfoCommand = cli.Command{
317+
Name: "imagefsinfo",
318+
Usage: "Return image filesystem info",
319+
SkipArgReorder: true,
320+
UseShortOptionHandling: true,
321+
Flags: []cli.Flag{
322+
cli.StringFlag{
323+
Name: "output, o",
324+
Usage: "Output format, One of: json|yaml|table",
325+
},
326+
},
327+
Action: func(context *cli.Context) error {
328+
if err := getImageClient(context); err != nil {
329+
return err
330+
}
331+
output := context.String("output")
332+
if output == "" { // default to json output
333+
output = "json"
334+
}
335+
336+
r, err := ImageFsInfo(imageClient)
337+
if err != nil {
338+
return fmt.Errorf("image filesystem info request failed: %v", err)
339+
}
340+
for _, info := range r.ImageFilesystems {
341+
status, err := protobufObjectToJSON(info)
342+
if err != nil {
343+
return fmt.Errorf("failed to marshal image filesystem info to json: %v", err)
344+
}
345+
346+
switch output {
347+
case "json", "yaml":
348+
if err := outputStatusInfo(status, nil, output); err != nil {
349+
return fmt.Errorf("failed to output image filesystem info %v", err)
350+
}
351+
continue
352+
case "table": // table output is after this switch block
353+
default:
354+
return fmt.Errorf("output option cannot be %s", output)
355+
}
356+
357+
// otherwise output in table format
358+
fmt.Printf("TimeStamp: %d\n", info.Timestamp)
359+
fmt.Printf("UsedBytes: %s\n", info.UsedBytes)
360+
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
361+
}
362+
363+
return nil
364+
365+
},
366+
}
367+
316368
func parseCreds(creds string) (string, string, error) {
317369
if creds == "" {
318370
return "", "", errors.New("credentials can't be empty")
@@ -439,3 +491,13 @@ func RemoveImage(client pb.ImageServiceClient, image string) (resp *pb.RemoveIma
439491
logrus.Debugf("RemoveImageResponse: %v", resp)
440492
return
441493
}
494+
495+
// ImageFsInfo sends an ImageStatusRequest to the server, and parses
496+
// the returned ImageFsInfoResponse.
497+
func ImageFsInfo(client pb.ImageServiceClient) (resp *pb.ImageFsInfoResponse, err error) {
498+
request := &pb.ImageFsInfoRequest{}
499+
logrus.Debugf("ImageFsInfoRequest: %v", request)
500+
resp, err = client.ImageFsInfo(context.Background(), request)
501+
logrus.Debugf("ImageFsInfoResponse: %v", resp)
502+
return
503+
}

cmd/crictl/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func main() {
102102
listImageCommand,
103103
containerStatusCommand,
104104
imageStatusCommand,
105+
imageFsInfoCommand,
105106
podStatusCommand,
106107
logsCommand,
107108
runtimePortForwardCommand,

0 commit comments

Comments
 (0)