@@ -495,27 +495,7 @@ func TestStatter(t *testing.T) {
495495 t .Run ("Memory/CurrentInParent" , func (t * testing.T ) {
496496 t .Parallel ()
497497
498- // Child cgroup has memory.stat but NOT memory.current
499- // Root cgroup has both, so child should inherit memory.current from parent
500- testData := map [string ]string {
501- procOneCgroup : "0::/" ,
502- procSelfCgroup : fmt .Sprintf ("0::%s" , fsContainerCgroupV2KubernetesPath ),
503- procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
504- proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
505- sysCgroupType : "domain" ,
506-
507- // Child has memory.stat but NOT memory.current
508- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUStat ): "usage_usec 0" ,
509- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryStat ): "inactive_file 268435456" ,
510- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUMax ): "max 100000" ,
511- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryMaxBytes ): "max" ,
512-
513- // Root has memory.current that child should inherit
514- filepath .Join (cgroupRootPath , cgroupV2MemoryUsageBytes ): "536870912" ,
515- filepath .Join (cgroupRootPath , cgroupV2MemoryStat ): "inactive_file 268435456" ,
516- }
517-
518- fs := initFS (t , testData )
498+ fs := initFS (t , fsContainerCgroupV2KubernetesMissingMemoryCurrent )
519499 s , err := New (WithFS (fs ), withNoWait , withIsCgroupV2 (true ))
520500 require .NoError (t , err )
521501
@@ -530,27 +510,7 @@ proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
530510 t .Run ("Memory/StatInParent" , func (t * testing.T ) {
531511 t .Parallel ()
532512
533- // Child cgroup has memory.current but NOT memory.stat
534- // Root cgroup has both, so child should inherit memory.stat from parent
535- testData := map [string ]string {
536- procOneCgroup : "0::/" ,
537- procSelfCgroup : fmt .Sprintf ("0::%s" , fsContainerCgroupV2KubernetesPath ),
538- procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
539- proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
540- sysCgroupType : "domain" ,
541-
542- // Child has memory.current but NOT memory.stat
543- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUStat ): "usage_usec 0" ,
544- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryUsageBytes ): "536870912" ,
545- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUMax ): "max 100000" ,
546- filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryMaxBytes ): "max" ,
547-
548- // Root has memory.stat that child should inherit
549- filepath .Join (cgroupRootPath , cgroupV2MemoryStat ): "inactive_file 268435456" ,
550- filepath .Join (cgroupRootPath , cgroupV2MemoryUsageBytes ): "536870912" ,
551- }
552-
553- fs := initFS (t , testData )
513+ fs := initFS (t , fsContainerCgroupV2KubernetesMissingMemoryStat )
554514 s , err := New (WithFS (fs ), withNoWait , withIsCgroupV2 (true ))
555515 require .NoError (t , err )
556516
@@ -875,6 +835,36 @@ sysboxfs /proc/sys sysboxfs rw,nosuid,nodev,noexec,relatime 0 0`,
875835 filepath .Join (cgroupRootPath , "init.scope" , cgroupV2MemoryStat ): "inactive_file 268435456" ,
876836 filepath .Join (cgroupRootPath , "init.scope" , cgroupV2MemoryUsageBytes ): "536870912" ,
877837 }
838+ // Variant where child has memory.stat but NOT memory.current (should inherit from root)
839+ fsContainerCgroupV2KubernetesMissingMemoryCurrent = map [string ]string {
840+ procOneCgroup : "0::/" ,
841+ procSelfCgroup : fmt .Sprintf ("0::%s" , fsContainerCgroupV2KubernetesPath ),
842+ procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
843+ proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
844+ sysCgroupType : "domain" ,
845+
846+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUMax ): "max 100000" ,
847+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUStat ): "usage_usec 0" ,
848+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryMaxBytes ): "max" ,
849+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryStat ): "inactive_file 268435456" ,
850+ // memory.current purposefully missing at child - should inherit from root
851+ filepath .Join (cgroupRootPath , cgroupV2MemoryUsageBytes ): "536870912" ,
852+ }
853+ // Variant where child has memory.current but NOT memory.stat (should inherit from root)
854+ fsContainerCgroupV2KubernetesMissingMemoryStat = map [string ]string {
855+ procOneCgroup : "0::/" ,
856+ procSelfCgroup : fmt .Sprintf ("0::%s" , fsContainerCgroupV2KubernetesPath ),
857+ procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
858+ proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
859+ sysCgroupType : "domain" ,
860+
861+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUMax ): "max 100000" ,
862+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2CPUStat ): "usage_usec 0" ,
863+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryMaxBytes ): "max" ,
864+ filepath .Join (cgroupRootPath , fsContainerCgroupV2KubernetesPath , cgroupV2MemoryUsageBytes ): "536870912" ,
865+ // memory.stat purposefully missing at child - should inherit from root
866+ filepath .Join (cgroupRootPath , cgroupV2MemoryStat ): "inactive_file 268435456" ,
867+ }
878868 fsContainerCgroupV1 = map [string ]string {
879869 procOneCgroup : "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f" ,
880870 procSelfCgroup : "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f" ,
0 commit comments