Skip to content

Commit 1e05688

Browse files
authored
Merge pull request #311 from kestrelcjx/main
fix(): support re-enabling oom killer refs #307
2 parents fe50040 + 8d429da commit 1e05688

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

cgroup1/memory.go

+3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ func getOomControlValue(mem *specs.LinuxMemory) *int64 {
454454
if mem.DisableOOMKiller != nil && *mem.DisableOOMKiller {
455455
i := int64(1)
456456
return &i
457+
} else if mem.DisableOOMKiller != nil && !*mem.DisableOOMKiller {
458+
i := int64(0)
459+
return &i
457460
}
458461
return nil
459462
}

cgroup1/memory_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"testing"
2525

2626
v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
27+
specs "github.com/opencontainers/runtime-spec/specs-go"
2728
)
2829

2930
const memoryData = `cache 1
@@ -286,3 +287,59 @@ func buildMemoryMetrics(t *testing.T, modules []string, metrics []string) string
286287
}
287288
return tmpRoot
288289
}
290+
291+
func Test_getOomControlValue(t *testing.T) {
292+
var (
293+
oneInt64 int64 = 1
294+
zeroInt64 int64 = 0
295+
trueBool bool = true
296+
falseBool bool = false
297+
)
298+
299+
type args struct {
300+
mem *specs.LinuxMemory
301+
}
302+
tests := []struct {
303+
name string
304+
args args
305+
want *int64
306+
}{
307+
{
308+
name: "enable",
309+
args: args{
310+
mem: &specs.LinuxMemory{
311+
DisableOOMKiller: &falseBool,
312+
},
313+
},
314+
want: &zeroInt64,
315+
},
316+
{
317+
name: "disable",
318+
args: args{
319+
mem: &specs.LinuxMemory{
320+
DisableOOMKiller: &trueBool,
321+
},
322+
},
323+
want: &oneInt64,
324+
},
325+
{
326+
name: "nil",
327+
args: args{
328+
mem: &specs.LinuxMemory{},
329+
},
330+
want: nil,
331+
},
332+
}
333+
for _, tt := range tests {
334+
t.Run(tt.name, func(t *testing.T) {
335+
got := getOomControlValue(tt.args.mem)
336+
if (got == nil || tt.want == nil) && got != tt.want {
337+
t.Errorf("getOomControlValue() = %v, want %v", got, tt.want)
338+
return
339+
}
340+
if !(got == nil || tt.want == nil) && *got != *tt.want {
341+
t.Errorf("getOomControlValue() = %v, want %v", got, tt.want)
342+
}
343+
})
344+
}
345+
}

0 commit comments

Comments
 (0)