@@ -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,8 @@ 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 := cgroupPaths["pids"]
199
+ pidsRoot , ok := getControllerPath (cgroupPaths , "pids" , cgroup2UnifiedMode )
199
200
if ok {
200
201
if utils .FileExists (pidsRoot ) {
201
202
spec .HasProcesses = true
@@ -217,6 +218,19 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
217
218
return spec , nil
218
219
}
219
220
221
+ func getControllerPath (cgroupPaths map [string ]string , controllerName string , cgroup2UnifiedMode bool ) (string , bool ) {
222
+
223
+ ok := false
224
+ path := ""
225
+
226
+ if cgroup2UnifiedMode {
227
+ path , ok = cgroupPaths ["" ]
228
+ } else {
229
+ path , ok = cgroupPaths [controllerName ]
230
+ }
231
+ return path , ok
232
+ }
233
+
220
234
func readString (dirpath string , file string ) string {
221
235
cgroupFile := path .Join (dirpath , file )
222
236
0 commit comments