Skip to content

Commit

Permalink
Merge pull request cri-o#7269 from kannon92/container-cri-change
Browse files Browse the repository at this point in the history
CRIO changes to support split filesystem
  • Loading branch information
openshift-merge-bot[bot] authored Dec 21, 2023
2 parents 6c76d99 + c30ce40 commit d59bbdc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
54 changes: 41 additions & 13 deletions server/image_fs_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"fmt"
"path"
"time"

Expand All @@ -10,35 +11,62 @@ import (
types "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func getStorageFsInfo(store storage.Store) (*types.FilesystemUsage, error) {
func getStorageFsInfo(store storage.Store) (*types.ImageFsInfoResponse, error) {
rootPath := store.GraphRoot()
imagePath := store.ImageStore()
storageDriver := store.GraphDriverName()
imagesPath := path.Join(rootPath, storageDriver+"-images")
var graphRootPath string
if imagePath == "" {
graphRootPath = path.Join(rootPath, storageDriver+"-images")
} else {
graphRootPath = path.Join(rootPath, storageDriver+"-containers")
}

bytesUsed, inodesUsed, err := crioStorage.GetDiskUsageStats(imagesPath)
graphUsage, err := getUsage(graphRootPath)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get usage for %s: %w", graphRootPath, err)
}

usage := types.FilesystemUsage{
Timestamp: time.Now().UnixNano(),
FsId: &types.FilesystemIdentifier{Mountpoint: imagesPath},
UsedBytes: &types.UInt64Value{Value: bytesUsed},
InodesUsed: &types.UInt64Value{Value: inodesUsed},
if imagePath == "" {
return &types.ImageFsInfoResponse{
ImageFilesystems: []*types.FilesystemUsage{graphUsage},
ContainerFilesystems: []*types.FilesystemUsage{graphUsage},
}, nil
}
resp := &types.ImageFsInfoResponse{
ContainerFilesystems: []*types.FilesystemUsage{graphUsage},
}

imageRoot := path.Join(imagePath, storageDriver+"-images")
imageUsage, err := getUsage(imageRoot)
if err != nil {
return nil, fmt.Errorf("unable to get usage for %s: %w", imageRoot, err)
}

return &usage, nil
resp.ImageFilesystems = []*types.FilesystemUsage{imageUsage}
return resp, nil
}

// ImageFsInfo returns information of the filesystem that is used to store images.
func (s *Server) ImageFsInfo(context.Context, *types.ImageFsInfoRequest) (*types.ImageFsInfoResponse, error) {
store := s.StorageImageServer().GetStore()
fsUsage, err := getStorageFsInfo(store)
if err != nil {
return nil, err
return nil, fmt.Errorf("get image fs info %w", err)
}

return &types.ImageFsInfoResponse{
ImageFilesystems: []*types.FilesystemUsage{fsUsage},
return fsUsage, nil
}

func getUsage(containerPath string) (*types.FilesystemUsage, error) {
bytes, inodes, err := crioStorage.GetDiskUsageStats(containerPath)
if err != nil {
return nil, fmt.Errorf("get disk usage for path %s: %w", containerPath, err)
}
return &types.FilesystemUsage{
Timestamp: time.Now().UnixNano(),
FsId: &types.FilesystemIdentifier{Mountpoint: containerPath},
UsedBytes: &types.UInt64Value{Value: bytes},
InodesUsed: &types.UInt64Value{Value: inodes},
}, nil
}
3 changes: 3 additions & 0 deletions server/image_fs_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var _ = t.Describe("ImageFsInfo", func() {
gomock.InOrder(
imageServerMock.EXPECT().GetStore().Return(storeMock),
storeMock.EXPECT().GraphRoot().Return(""),
storeMock.EXPECT().ImageStore().Return(""),
storeMock.EXPECT().GraphDriverName().Return("test"),
)
testImageDir := "test-images"
Expand All @@ -37,13 +38,15 @@ var _ = t.Describe("ImageFsInfo", func() {
Expect(err).To(BeNil())
Expect(response).NotTo(BeNil())
Expect(len(response.ImageFilesystems)).To(BeEquivalentTo(1))
Expect(len(response.ContainerFilesystems)).To(BeEquivalentTo(1))
})

It("should fail on invalid image dir", func() {
// Given
gomock.InOrder(
imageServerMock.EXPECT().GetStore().Return(storeMock),
storeMock.EXPECT().GraphRoot().Return(""),
storeMock.EXPECT().ImageStore().Return(""),
storeMock.EXPECT().GraphDriverName().Return(""),
)

Expand Down

0 comments on commit d59bbdc

Please sign in to comment.