Skip to content

Commit

Permalink
add cadvisor and crio upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kannon92 committed Dec 18, 2023
1 parent 2129e1c commit db33cc7
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 4 deletions.
1 change: 1 addition & 0 deletions container/crio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
type Info struct {
StorageDriver string `json:"storage_driver"`
StorageRoot string `json:"storage_root"`
StorageImage string `json:"storage_image"`
}

// ContainerInfo represents a given container information
Expand Down
2 changes: 1 addition & 1 deletion container/crio/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *plugin) InitializeFSContext(context *fs.Context) error {
if err != nil {
klog.V(5).Infof("CRI-O not connected: %v", err)
} else {
context.Crio = fs.CrioContext{Root: crioInfo.StorageRoot}
context.Crio = fs.CrioContext{Root: crioInfo.StorageRoot, ImageStore: crioInfo.StorageImage, Driver: crioInfo.StorageDriver}
}
return nil
}
Expand Down
28 changes: 26 additions & 2 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
LabelSystemRoot = "root"
LabelDockerImages = "docker-images"
LabelCrioImages = "crio-images"
LabelCrioContainers = "crio-containers"
DriverStatusPoolName = "Pool Name"
DriverStatusDataLoopFile = "Data loop file"
)
Expand Down Expand Up @@ -295,14 +296,37 @@ func (i *RealFsInfo) addDockerImagesLabel(context Context, mounts []*mount.Info)
}

func (i *RealFsInfo) addCrioImagesLabel(context Context, mounts []*mount.Info) {
labelCrioImageOrContainers := LabelCrioContainers
// If imagestore is not specified, let's fall back to the original case.
// Everything will be stored in crio-images
if context.Crio.ImageStore == "" {
labelCrioImageOrContainers = LabelCrioImages
}
if context.Crio.Root != "" {
crioPath := context.Crio.Root
crioImagePaths := map[string]struct{}{
"/": {},
}
for _, dir := range []string{"devicemapper", "btrfs", "aufs", "overlay", "zfs"} {
crioImagePaths[path.Join(crioPath, dir+"-images")] = struct{}{}
imageOrContainerPath := context.Crio.Driver + "-containers"
if context.Crio.ImageStore == "" {
// If ImageStore is not specified then we will assume ImageFs is complete separate.
// No need to split the image store.
imageOrContainerPath = context.Crio.Driver + "-images"

}
crioImagePaths[path.Join(crioPath, imageOrContainerPath)] = struct{}{}
for crioPath != "/" && crioPath != "." {
crioImagePaths[crioPath] = struct{}{}
crioPath = filepath.Dir(crioPath)
}
i.updateContainerImagesPath(labelCrioImageOrContainers, mounts, crioImagePaths)
}
if context.Crio.ImageStore != "" {
crioPath := context.Crio.ImageStore
crioImagePaths := map[string]struct{}{
"/": {},
}
crioImagePaths[path.Join(crioPath, context.Crio.Driver+"-images")] = struct{}{}
for crioPath != "/" && crioPath != "." {
crioImagePaths[crioPath] = struct{}{}
crioPath = filepath.Dir(crioPath)
Expand Down
110 changes: 110 additions & 0 deletions fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,116 @@ func TestAddDockerImagesLabel(t *testing.T) {
}
}

func TestAddCrioImagesLabel(t *testing.T) {
tests := []struct {
name string
driver string
driverStatus map[string]string
dmsetupTable string
mounts []*mount.Info
imageStore string
expectedCrioImages string
expectedCrioContainers string
expectedPartition *partition
}{
{
name: "single partition, no dedicated image fs",
driver: "overlay2",
mounts: []*mount.Info{
{
Source: "/dev/root",
Mountpoint: "/",
FSType: "ext4",
},
{
Source: "/sys/fs/cgroup",
Mountpoint: "/sys/fs/cgroup",
FSType: "tmpfs",
},
},
expectedCrioImages: "/dev/root",
expectedCrioContainers: "",
},
{
name: "root fs inside container, docker-images bindmount",
driver: "overlay2",
mounts: []*mount.Info{
{
Source: "overlay",
Mountpoint: "/",
FSType: "overlay",
},
{
Source: "/dev/sda1",
Mountpoint: "/var/lib/container",
FSType: "ext4",
},
},
expectedCrioImages: "/dev/sda1",
},
{
name: "[overlay2] image and container separate",
driver: "overlay2",
mounts: []*mount.Info{
{
Source: "/dev/sdb1",
Mountpoint: "/imagestore",
FSType: "ext4",
},
{
Source: "/dev/sdb2",
Mountpoint: "/var/lib/container",
FSType: "ext4",
},
},
expectedCrioImages: "/dev/sdb1",
expectedCrioContainers: "/dev/sdb2",
imageStore: "/imagestore",
},
}

for _, tt := range tests {
fsInfo := &RealFsInfo{
labels: map[string]string{},
partitions: map[string]partition{},
dmsetup: &testDmsetup{
data: []byte(tt.dmsetupTable),
},
}

context := Context{
Crio: CrioContext{
Root: "/var/lib/container",
ImageStore: tt.imageStore,
Driver: "overlay",
},
}

fsInfo.addCrioImagesLabel(context, tt.mounts)

if tt.imageStore != "" {
if e, a := tt.expectedCrioImages, fsInfo.labels[LabelCrioImages]; e != a {
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
}

if e, a := tt.expectedCrioContainers, fsInfo.labels[LabelCrioContainers]; e != a {
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
}

}
if tt.imageStore == "" {
if e, a := tt.expectedCrioImages, fsInfo.labels[LabelCrioImages]; e != a {
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
}

}

if tt.expectedPartition == nil {
continue
}
}
}

func TestProcessMounts(t *testing.T) {
tests := []struct {
name string
Expand Down
4 changes: 3 additions & 1 deletion fs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ type PodmanContext struct {
}

type CrioContext struct {
Root string
Root string
ImageStore string
Driver string
}

type DeviceInfo struct {
Expand Down

0 comments on commit db33cc7

Please sign in to comment.