Skip to content

Commit db3c917

Browse files
authored
Merge pull request #3395 from kannon92/crio-split-disk
allow for cadvisor to detect disk stats when the read-only and writeable layers are on separate disks.
2 parents 2129e1c + db33cc7 commit db3c917

File tree

5 files changed

+141
-4
lines changed

5 files changed

+141
-4
lines changed

container/crio/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
type Info struct {
4545
StorageDriver string `json:"storage_driver"`
4646
StorageRoot string `json:"storage_root"`
47+
StorageImage string `json:"storage_image"`
4748
}
4849

4950
// ContainerInfo represents a given container information

container/crio/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (p *plugin) InitializeFSContext(context *fs.Context) error {
4040
if err != nil {
4141
klog.V(5).Infof("CRI-O not connected: %v", err)
4242
} else {
43-
context.Crio = fs.CrioContext{Root: crioInfo.StorageRoot}
43+
context.Crio = fs.CrioContext{Root: crioInfo.StorageRoot, ImageStore: crioInfo.StorageImage, Driver: crioInfo.StorageDriver}
4444
}
4545
return nil
4646
}

fs/fs.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
LabelSystemRoot = "root"
4444
LabelDockerImages = "docker-images"
4545
LabelCrioImages = "crio-images"
46+
LabelCrioContainers = "crio-containers"
4647
DriverStatusPoolName = "Pool Name"
4748
DriverStatusDataLoopFile = "Data loop file"
4849
)
@@ -295,14 +296,37 @@ func (i *RealFsInfo) addDockerImagesLabel(context Context, mounts []*mount.Info)
295296
}
296297

297298
func (i *RealFsInfo) addCrioImagesLabel(context Context, mounts []*mount.Info) {
299+
labelCrioImageOrContainers := LabelCrioContainers
300+
// If imagestore is not specified, let's fall back to the original case.
301+
// Everything will be stored in crio-images
302+
if context.Crio.ImageStore == "" {
303+
labelCrioImageOrContainers = LabelCrioImages
304+
}
298305
if context.Crio.Root != "" {
299306
crioPath := context.Crio.Root
300307
crioImagePaths := map[string]struct{}{
301308
"/": {},
302309
}
303-
for _, dir := range []string{"devicemapper", "btrfs", "aufs", "overlay", "zfs"} {
304-
crioImagePaths[path.Join(crioPath, dir+"-images")] = struct{}{}
310+
imageOrContainerPath := context.Crio.Driver + "-containers"
311+
if context.Crio.ImageStore == "" {
312+
// If ImageStore is not specified then we will assume ImageFs is complete separate.
313+
// No need to split the image store.
314+
imageOrContainerPath = context.Crio.Driver + "-images"
315+
316+
}
317+
crioImagePaths[path.Join(crioPath, imageOrContainerPath)] = struct{}{}
318+
for crioPath != "/" && crioPath != "." {
319+
crioImagePaths[crioPath] = struct{}{}
320+
crioPath = filepath.Dir(crioPath)
321+
}
322+
i.updateContainerImagesPath(labelCrioImageOrContainers, mounts, crioImagePaths)
323+
}
324+
if context.Crio.ImageStore != "" {
325+
crioPath := context.Crio.ImageStore
326+
crioImagePaths := map[string]struct{}{
327+
"/": {},
305328
}
329+
crioImagePaths[path.Join(crioPath, context.Crio.Driver+"-images")] = struct{}{}
306330
for crioPath != "/" && crioPath != "." {
307331
crioImagePaths[crioPath] = struct{}{}
308332
crioPath = filepath.Dir(crioPath)

fs/fs_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,116 @@ func TestAddDockerImagesLabel(t *testing.T) {
520520
}
521521
}
522522

523+
func TestAddCrioImagesLabel(t *testing.T) {
524+
tests := []struct {
525+
name string
526+
driver string
527+
driverStatus map[string]string
528+
dmsetupTable string
529+
mounts []*mount.Info
530+
imageStore string
531+
expectedCrioImages string
532+
expectedCrioContainers string
533+
expectedPartition *partition
534+
}{
535+
{
536+
name: "single partition, no dedicated image fs",
537+
driver: "overlay2",
538+
mounts: []*mount.Info{
539+
{
540+
Source: "/dev/root",
541+
Mountpoint: "/",
542+
FSType: "ext4",
543+
},
544+
{
545+
Source: "/sys/fs/cgroup",
546+
Mountpoint: "/sys/fs/cgroup",
547+
FSType: "tmpfs",
548+
},
549+
},
550+
expectedCrioImages: "/dev/root",
551+
expectedCrioContainers: "",
552+
},
553+
{
554+
name: "root fs inside container, docker-images bindmount",
555+
driver: "overlay2",
556+
mounts: []*mount.Info{
557+
{
558+
Source: "overlay",
559+
Mountpoint: "/",
560+
FSType: "overlay",
561+
},
562+
{
563+
Source: "/dev/sda1",
564+
Mountpoint: "/var/lib/container",
565+
FSType: "ext4",
566+
},
567+
},
568+
expectedCrioImages: "/dev/sda1",
569+
},
570+
{
571+
name: "[overlay2] image and container separate",
572+
driver: "overlay2",
573+
mounts: []*mount.Info{
574+
{
575+
Source: "/dev/sdb1",
576+
Mountpoint: "/imagestore",
577+
FSType: "ext4",
578+
},
579+
{
580+
Source: "/dev/sdb2",
581+
Mountpoint: "/var/lib/container",
582+
FSType: "ext4",
583+
},
584+
},
585+
expectedCrioImages: "/dev/sdb1",
586+
expectedCrioContainers: "/dev/sdb2",
587+
imageStore: "/imagestore",
588+
},
589+
}
590+
591+
for _, tt := range tests {
592+
fsInfo := &RealFsInfo{
593+
labels: map[string]string{},
594+
partitions: map[string]partition{},
595+
dmsetup: &testDmsetup{
596+
data: []byte(tt.dmsetupTable),
597+
},
598+
}
599+
600+
context := Context{
601+
Crio: CrioContext{
602+
Root: "/var/lib/container",
603+
ImageStore: tt.imageStore,
604+
Driver: "overlay",
605+
},
606+
}
607+
608+
fsInfo.addCrioImagesLabel(context, tt.mounts)
609+
610+
if tt.imageStore != "" {
611+
if e, a := tt.expectedCrioImages, fsInfo.labels[LabelCrioImages]; e != a {
612+
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
613+
}
614+
615+
if e, a := tt.expectedCrioContainers, fsInfo.labels[LabelCrioContainers]; e != a {
616+
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
617+
}
618+
619+
}
620+
if tt.imageStore == "" {
621+
if e, a := tt.expectedCrioImages, fsInfo.labels[LabelCrioImages]; e != a {
622+
t.Errorf("%s: docker device: expected %q, got %q", tt.name, e, a)
623+
}
624+
625+
}
626+
627+
if tt.expectedPartition == nil {
628+
continue
629+
}
630+
}
631+
}
632+
523633
func TestProcessMounts(t *testing.T) {
524634
tests := []struct {
525635
name string

fs/types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ type PodmanContext struct {
3838
}
3939

4040
type CrioContext struct {
41-
Root string
41+
Root string
42+
ImageStore string
43+
Driver string
4244
}
4345

4446
type DeviceInfo struct {

0 commit comments

Comments
 (0)