@@ -105,7 +105,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
105105 }
106106
107107 // CPU.
108- cpuRoot , ok := cgroupPaths [ "cpu" ]
108+ cpuRoot , ok := getControllerPath ( cgroupPaths , "cpu" , cgroup2UnifiedMode )
109109 if ok {
110110 if utils .FileExists (cpuRoot ) {
111111 if cgroup2UnifiedMode {
@@ -152,7 +152,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
152152
153153 // Cpu Mask.
154154 // This will fail for non-unified hierarchies. We'll return the whole machine mask in that case.
155- cpusetRoot , ok := cgroupPaths [ "cpuset" ]
155+ cpusetRoot , ok := getControllerPath ( cgroupPaths , "cpuset" , cgroup2UnifiedMode )
156156 if ok {
157157 if utils .FileExists (cpusetRoot ) {
158158 spec .HasCpu = true
@@ -167,7 +167,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
167167 }
168168
169169 // Memory
170- memoryRoot , ok := cgroupPaths [ "memory" ]
170+ memoryRoot , ok := getControllerPath ( cgroupPaths , "memory" , cgroup2UnifiedMode )
171171 if ok {
172172 if cgroup2UnifiedMode {
173173 if utils .FileExists (path .Join (memoryRoot , "memory.max" )) {
@@ -195,7 +195,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
195195 }
196196
197197 // Processes, read it's value from pids path directly
198- pidsRoot , ok := cgroupPaths [ "pids" ]
198+ pidsRoot , ok := getControllerPath ( cgroupPaths , "pids" , cgroup2UnifiedMode )
199199 if ok {
200200 if utils .FileExists (pidsRoot ) {
201201 spec .HasProcesses = true
@@ -217,6 +217,19 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
217217 return spec , nil
218218}
219219
220+ func getControllerPath (cgroupPaths map [string ]string , controllerName string , cgroup2UnifiedMode bool ) (string , bool ) {
221+
222+ ok := false
223+ path := ""
224+
225+ if cgroup2UnifiedMode {
226+ path , ok = cgroupPaths ["" ]
227+ } else {
228+ path , ok = cgroupPaths [controllerName ]
229+ }
230+ return path , ok
231+ }
232+
220233func readString (dirpath string , file string ) string {
221234 cgroupFile := path .Join (dirpath , file )
222235
0 commit comments