@@ -105,7 +105,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
105
105
}
106
106
107
107
// CPU.
108
- cpuRoot , ok := cgroupPaths [ "cpu" ]
108
+ cpuRoot , ok := getControllerPath ( cgroupPaths , "cpu" , cgroup2UnifiedMode )
109
109
if ok {
110
110
if utils .FileExists (cpuRoot ) {
111
111
if cgroup2UnifiedMode {
@@ -152,7 +152,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
152
152
153
153
// Cpu Mask.
154
154
// 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 )
156
156
if ok {
157
157
if utils .FileExists (cpusetRoot ) {
158
158
spec .HasCpu = true
@@ -167,7 +167,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
167
167
}
168
168
169
169
// Memory
170
- memoryRoot , ok := cgroupPaths [ "memory" ]
170
+ memoryRoot , ok := getControllerPath ( cgroupPaths , "memory" , cgroup2UnifiedMode )
171
171
if ok {
172
172
if cgroup2UnifiedMode {
173
173
if utils .FileExists (path .Join (memoryRoot , "memory.max" )) {
@@ -195,7 +195,7 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
195
195
}
196
196
197
197
// Processes, read it's value from pids path directly
198
- pidsRoot , ok := cgroupPaths [ "pids" ]
198
+ pidsRoot , ok := getControllerPath ( cgroupPaths , "pids" , cgroup2UnifiedMode )
199
199
if ok {
200
200
if utils .FileExists (pidsRoot ) {
201
201
spec .HasProcesses = true
@@ -217,6 +217,19 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
217
217
return spec , nil
218
218
}
219
219
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
+
220
233
func readString (dirpath string , file string ) string {
221
234
cgroupFile := path .Join (dirpath , file )
222
235
0 commit comments