Skip to content

Commit

Permalink
adding imagefsinfo endpoint for both container and image filesystems
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Hannon <kehannon@redhat.com>
  • Loading branch information
kannon92 committed Nov 20, 2023
1 parent 93cf30d commit aad5cd9
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 452 deletions.
49 changes: 29 additions & 20 deletions cmd/crictl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,28 +494,37 @@ var imageFsInfoCommand = &cli.Command{
if err != nil {
return fmt.Errorf("image filesystem info request: %w", err)
}
for _, info := range r.ImageFilesystems {
status, err := protobufObjectToJSON(info)
if err != nil {
return fmt.Errorf("marshal image filesystem info to json: %w", err)
}
fileSystemReport := func(filesystem []*pb.FilesystemUsage) error {
for _, info := range filesystem {
status, err := protobufObjectToJSON(info)
if err != nil {
return fmt.Errorf("marshal filesystem info to json: %w", err)
}

switch output {
case "json", "yaml", "go-template":
if err := outputStatusInfo(status, nil, output, tmplStr); err != nil {
return fmt.Errorf("output image filesystem info: %w", err)
switch output {
case "json", "yaml", "go-template":
if err := outputStatusInfo(status, nil, output, tmplStr); err != nil {
return fmt.Errorf("output filesystem info: %w", err)
}
continue
case "table": // table output is after this switch block
default:
return fmt.Errorf("output option cannot be %s", output)
}
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("Disk: %s\n", units.HumanSize(float64(info.UsedBytes.GetValue())))
fmt.Printf("Inodes: %d\n", info.InodesUsed.GetValue())
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
// otherwise output in table format
fmt.Printf("TimeStamp: %d\n", info.Timestamp)
fmt.Printf("Disk: %s\n", units.HumanSize(float64(info.UsedBytes.GetValue())))
fmt.Printf("Inodes: %d\n", info.InodesUsed.GetValue())
fmt.Printf("Mountpoint: %s\n", info.FsId.Mountpoint)
}
return nil
}
if err := fileSystemReport(r.ImageFilesystems); err != nil {
return err
}
if err := fileSystemReport(r.ContainerFilesystems); err != nil {
return err
}

return nil
Expand Down Expand Up @@ -682,7 +691,7 @@ func ImageFsInfo(client internalapi.ImageManagerService) (*pb.ImageFsInfoRespons
if err != nil {
return nil, err
}
resp := &pb.ImageFsInfoResponse{ImageFilesystems: res}
resp := &pb.ImageFsInfoResponse{ImageFilesystems: res.ImageFilesystems, ContainerFilesystems: res.ContainerFilesystems}
logrus.Debugf("ImageFsInfoResponse: %v", resp)
return resp, nil
}
Loading

0 comments on commit aad5cd9

Please sign in to comment.