Skip to content

Commit

Permalink
fix(): support re-enabling oom killer refs #307
Browse files Browse the repository at this point in the history
  • Loading branch information
kestrelchen committed Nov 28, 2023
1 parent a0ae1c2 commit 88dc234
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cgroup1/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ func getOomControlValue(mem *specs.LinuxMemory) *int64 {
if mem.DisableOOMKiller != nil && *mem.DisableOOMKiller {
i := int64(1)
return &i
} else if mem.DisableOOMKiller != nil && !*mem.DisableOOMKiller {
i := int64(0)
return &i
}
return nil
}
Expand Down
57 changes: 57 additions & 0 deletions cgroup1/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

const memoryData = `cache 1
Expand Down Expand Up @@ -286,3 +287,59 @@ func buildMemoryMetrics(t *testing.T, modules []string, metrics []string) string
}
return tmpRoot
}

func Test_getOomControlValue(t *testing.T) {
var (
oneInt64 int64 = 1
zeroInt64 int64 = 0
trueBool bool = true
falseBool bool = false
)

type args struct {
mem *specs.LinuxMemory
}
tests := []struct {
name string
args args
want *int64
}{
{
name: "enable",
args: args{
mem: &specs.LinuxMemory{
DisableOOMKiller: &falseBool,
},
},
want: &zeroInt64,
},
{
name: "disable",
args: args{
mem: &specs.LinuxMemory{
DisableOOMKiller: &trueBool,
},
},
want: &oneInt64,
},
{
name: "nil",
args: args{
mem: &specs.LinuxMemory{},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := getOomControlValue(tt.args.mem)
if (got == nil || tt.want == nil) && got != tt.want {
t.Errorf("getOomControlValue() = %v, want %v", got, tt.want)
return
}
if !(got == nil || tt.want == nil) && *got != *tt.want {
t.Errorf("getOomControlValue() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 88dc234

Please sign in to comment.