Skip to content

Commit 79196bb

Browse files
committed
adding imagefsinfo endpoint for both container and image filesystems
Signed-off-by: Kevin Hannon <kehannon@redhat.com>
1 parent 53e28eb commit 79196bb

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

cmd/crictl/image.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -494,28 +494,37 @@ var imageFsInfoCommand = &cli.Command{
494494
if err != nil {
495495
return fmt.Errorf("image filesystem info request: %w", err)
496496
}
497-
for _, info := range r.ImageFilesystems {
498-
status, err := protobufObjectToJSON(info)
499-
if err != nil {
500-
return fmt.Errorf("marshal image filesystem info to json: %w", err)
501-
}
497+
fileSystemReport := func(filesystem []*pb.FilesystemUsage) error {
498+
for _, info := range filesystem {
499+
status, err := protobufObjectToJSON(info)
500+
if err != nil {
501+
return fmt.Errorf("marshal filesystem info to json: %w", err)
502+
}
502503

503-
switch output {
504-
case "json", "yaml", "go-template":
505-
if err := outputStatusInfo(status, nil, output, tmplStr); err != nil {
506-
return fmt.Errorf("output image filesystem info: %w", err)
504+
switch output {
505+
case "json", "yaml", "go-template":
506+
if err := outputStatusInfo(status, nil, output, tmplStr); err != nil {
507+
return fmt.Errorf("output filesystem info: %w", err)
508+
}
509+
continue
510+
case "table": // table output is after this switch block
511+
default:
512+
return fmt.Errorf("output option cannot be %s", output)
507513
}
508-
continue
509-
case "table": // table output is after this switch block
510-
default:
511-
return fmt.Errorf("output option cannot be %s", output)
512-
}
513514

514-
// otherwise output in table format
515-
fmt.Printf("TimeStamp: %d\n", info.Timestamp)
516-
fmt.Printf("Disk: %s\n", units.HumanSize(float64(info.UsedBytes.GetValue())))
517-
fmt.Printf("Inodes: %d\n", info.InodesUsed.GetValue())
518-
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
515+
// otherwise output in table format
516+
fmt.Printf("TimeStamp: %d\n", info.Timestamp)
517+
fmt.Printf("Disk: %s\n", units.HumanSize(float64(info.UsedBytes.GetValue())))
518+
fmt.Printf("Inodes: %d\n", info.InodesUsed.GetValue())
519+
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
520+
}
521+
return nil
522+
}
523+
if err := fileSystemReport(r.ImageFilesystems); err != nil {
524+
return err
525+
}
526+
if err := fileSystemReport(r.ContainerFilesystems); err != nil {
527+
return err
519528
}
520529

521530
return nil

0 commit comments

Comments
 (0)