Use mountpoint as image fs identifier.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -83,8 +83,8 @@ func (c *criContainerdService) getContainerMetrics(
|
||||
}
|
||||
cs.WritableLayer = &runtime.FilesystemUsage{
|
||||
Timestamp: sn.Timestamp,
|
||||
StorageId: &runtime.StorageIdentifier{
|
||||
Uuid: c.imageFSUUID,
|
||||
FsId: &runtime.FilesystemIdentifier{
|
||||
Mountpoint: c.imageFSPath,
|
||||
},
|
||||
UsedBytes: &runtime.UInt64Value{Value: usedBytes},
|
||||
InodesUsed: &runtime.UInt64Value{Value: inodesUsed},
|
||||
|
||||
@@ -42,7 +42,7 @@ func (c *criContainerdService) ImageFsInfo(ctx context.Context, r *runtime.Image
|
||||
ImageFilesystems: []*runtime.FilesystemUsage{
|
||||
{
|
||||
Timestamp: timestamp,
|
||||
StorageId: &runtime.StorageIdentifier{Uuid: c.imageFSUUID},
|
||||
FsId: &runtime.FilesystemIdentifier{Mountpoint: c.imageFSPath},
|
||||
UsedBytes: &runtime.UInt64Value{Value: usedBytes},
|
||||
InodesUsed: &runtime.UInt64Value{Value: inodesUsed},
|
||||
},
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestImageFsInfo(t *testing.T) {
|
||||
}
|
||||
expected := &runtime.FilesystemUsage{
|
||||
Timestamp: 123456,
|
||||
StorageId: &runtime.StorageIdentifier{Uuid: testImageFSUUID},
|
||||
FsId: &runtime.FilesystemIdentifier{Mountpoint: testImageFSPath},
|
||||
UsedBytes: &runtime.UInt64Value{Value: 30},
|
||||
InodesUsed: &runtime.UInt64Value{Value: 300},
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
"github.com/opencontainers/selinux/go-selinux"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
"google.golang.org/grpc"
|
||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||
"k8s.io/kubernetes/pkg/kubelet/server/streaming"
|
||||
@@ -76,8 +75,8 @@ type CRIContainerdService interface {
|
||||
type criContainerdService struct {
|
||||
// config contains all configurations.
|
||||
config options.Config
|
||||
// imageFSUUID is the device uuid of image filesystem.
|
||||
imageFSUUID string
|
||||
// imageFSPath is the path to image filesystem.
|
||||
imageFSPath string
|
||||
// apparmorEnabled indicates whether apparmor is enabled.
|
||||
apparmorEnabled bool
|
||||
// seccompEnabled indicates whether seccomp is enabled.
|
||||
@@ -138,16 +137,8 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
|
||||
selinux.SetDisabled()
|
||||
}
|
||||
|
||||
if !c.config.SkipImageFSUUID {
|
||||
imageFSPath := imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter)
|
||||
c.imageFSUUID, err = c.getDeviceUUID(imageFSPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err)
|
||||
}
|
||||
logrus.Infof("Get device uuid %q for image filesystem %q", c.imageFSUUID, imageFSPath)
|
||||
} else {
|
||||
logrus.Warn("Skip retrieving imagefs UUID, kubelet will not be able to get imagefs capacity or perform imagefs disk eviction.")
|
||||
}
|
||||
c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter)
|
||||
logrus.Infof("Get image filesystem path %q", c.imageFSPath)
|
||||
|
||||
c.netPlugin, err = ocicni.InitCNI(config.NetworkPluginConfDir, config.NetworkPluginBinDir)
|
||||
if err != nil {
|
||||
@@ -293,16 +284,6 @@ func (c *criContainerdService) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getDeviceUUID gets device uuid for a given path.
|
||||
func (c *criContainerdService) getDeviceUUID(path string) (string, error) {
|
||||
mount, err := c.os.LookupMount(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
rdev := unix.Mkdev(uint32(mount.Major), uint32(mount.Minor))
|
||||
return c.os.DeviceUUID(rdev)
|
||||
}
|
||||
|
||||
// imageFSPath returns containerd image filesystem path.
|
||||
// Note that if containerd changes directory layout, we also needs to change this.
|
||||
func imageFSPath(rootDir, snapshotter string) string {
|
||||
|
||||
@@ -33,7 +33,7 @@ const (
|
||||
// TODO(random-liu): Change this to image name after we have complete image
|
||||
// management unit test framework.
|
||||
testSandboxImage = "sha256:c75bebcdd211f41b3a460c7bf82970ed6c75acaab9cd4c9a4e125b03ca113798"
|
||||
testImageFSUUID = "test-image-fs-uuid"
|
||||
testImageFSPath = "/test/image/fs/path"
|
||||
)
|
||||
|
||||
// newTestCRIContainerdService creates a fake criContainerdService for test.
|
||||
@@ -45,7 +45,7 @@ func newTestCRIContainerdService() *criContainerdService {
|
||||
SandboxImage: testSandboxImage,
|
||||
},
|
||||
},
|
||||
imageFSUUID: testImageFSUUID,
|
||||
imageFSPath: testImageFSPath,
|
||||
os: ostesting.NewFakeOS(),
|
||||
sandboxStore: sandboxstore.NewStore(),
|
||||
imageStore: imagestore.NewStore(),
|
||||
|
||||
Reference in New Issue
Block a user