Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): support re-enabling oom killer #310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}
Loading