@@ -61,6 +61,10 @@ var bootTime = func() time.Time {
61
61
}()
62
62
63
63
func GetSpec (cgroupPaths map [string ]string , machineInfoFactory info.MachineInfoFactory , hasNetwork , hasFilesystem bool ) (info.ContainerSpec , error ) {
64
+ return getSpecInternal (cgroupPaths , machineInfoFactory , hasNetwork , hasFilesystem , cgroups .IsCgroup2UnifiedMode ())
65
+ }
66
+
67
+ func getSpecInternal (cgroupPaths map [string ]string , machineInfoFactory info.MachineInfoFactory , hasNetwork , hasFilesystem , cgroup2UnifiedMode bool ) (info.ContainerSpec , error ) {
64
68
var spec info.ContainerSpec
65
69
66
70
// Assume unified hierarchy containers.
@@ -77,7 +81,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
77
81
// Use clone_children/events as a workaround as it isn't usually modified. It is only likely changed
78
82
// immediately after creating a container. If the directory modified time is lower, we use that.
79
83
cgroupPathFile := path .Join (cgroupPathDir , "cgroup.clone_children" )
80
- if cgroups . IsCgroup2UnifiedMode () {
84
+ if cgroup2UnifiedMode {
81
85
cgroupPathFile = path .Join (cgroupPathDir , "cgroup.events" )
82
86
}
83
87
fi , err := os .Stat (cgroupPathFile )
@@ -103,7 +107,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
103
107
cpuRoot , ok := cgroupPaths ["cpu" ]
104
108
if ok {
105
109
if utils .FileExists (cpuRoot ) {
106
- if cgroups . IsCgroup2UnifiedMode () {
110
+ if cgroup2UnifiedMode {
107
111
spec .HasCpu = true
108
112
109
113
weight := readUInt64 (cpuRoot , "cpu.weight" )
@@ -152,7 +156,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
152
156
if utils .FileExists (cpusetRoot ) {
153
157
spec .HasCpu = true
154
158
mask := ""
155
- if cgroups . IsCgroup2UnifiedMode () {
159
+ if cgroup2UnifiedMode {
156
160
mask = readString (cpusetRoot , "cpuset.cpus.effective" )
157
161
} else {
158
162
mask = readString (cpusetRoot , "cpuset.cpus" )
@@ -164,20 +168,20 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
164
168
// Memory
165
169
memoryRoot , ok := cgroupPaths ["memory" ]
166
170
if ok {
167
- if ! cgroups .IsCgroup2UnifiedMode () {
168
- if utils .FileExists (memoryRoot ) {
169
- spec .HasMemory = true
170
- spec .Memory .Limit = readUInt64 (memoryRoot , "memory.limit_in_bytes" )
171
- spec .Memory .SwapLimit = readUInt64 (memoryRoot , "memory.memsw.limit_in_bytes" )
172
- spec .Memory .Reservation = readUInt64 (memoryRoot , "memory.soft_limit_in_bytes" )
173
- }
174
- } else {
171
+ if cgroup2UnifiedMode {
175
172
if utils .FileExists (path .Join (memoryRoot , "memory.max" )) {
176
173
spec .HasMemory = true
177
174
spec .Memory .Reservation = readUInt64 (memoryRoot , "memory.high" )
178
175
spec .Memory .Limit = readUInt64 (memoryRoot , "memory.max" )
179
176
spec .Memory .SwapLimit = readUInt64 (memoryRoot , "memory.swap.max" )
180
177
}
178
+ } else {
179
+ if utils .FileExists (memoryRoot ) {
180
+ spec .HasMemory = true
181
+ spec .Memory .Limit = readUInt64 (memoryRoot , "memory.limit_in_bytes" )
182
+ spec .Memory .SwapLimit = readUInt64 (memoryRoot , "memory.memsw.limit_in_bytes" )
183
+ spec .Memory .Reservation = readUInt64 (memoryRoot , "memory.soft_limit_in_bytes" )
184
+ }
181
185
}
182
186
}
183
187
@@ -202,7 +206,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
202
206
spec .HasFilesystem = hasFilesystem
203
207
204
208
ioControllerName := "blkio"
205
- if cgroups . IsCgroup2UnifiedMode () {
209
+ if cgroup2UnifiedMode {
206
210
ioControllerName = "io"
207
211
}
208
212
if blkioRoot , ok := cgroupPaths [ioControllerName ]; ok && utils .FileExists (blkioRoot ) {
0 commit comments