diff --git a/v2/cpuv2_test.go b/v2/cpuv2_test.go index 4f75f7c4..91b726a6 100644 --- a/v2/cpuv2_test.go +++ b/v2/cpuv2_test.go @@ -68,6 +68,25 @@ func TestSystemdCgroupCpuController(t *testing.T) { checkFileContent(t, c.path, "cpu.weight", strconv.FormatUint(weight, 10)) } +func TestSystemdCgroupCpuController_NilWeight(t *testing.T) { + checkCgroupMode(t) + group := "testingCpuNilWeight.slice" + // nil weight defaults to 100 + var quota int64 = 10000 + var period uint64 = 8000 + cpuMax := NewCPUMax("a, &period) + res := Resources{ + CPU: &CPU{ + Weight: nil, + Max: cpuMax, + }, + } + _, err := NewSystemd("/", group, -1, &res) + if err != nil { + t.Fatal("failed to init new cgroup systemd manager: ", err) + } +} + func TestExtractQuotaAndPeriod(t *testing.T) { var ( period uint64 diff --git a/v2/manager.go b/v2/manager.go index afed14c6..f5466785 100644 --- a/v2/manager.go +++ b/v2/manager.go @@ -734,12 +734,12 @@ func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, e properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)})) } - if resources.Memory != nil && *resources.Memory.Max != 0 { + if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 { properties = append(properties, newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max))) } - if resources.CPU != nil && *resources.CPU.Weight != 0 { + if resources.CPU != nil && resources.CPU.Weight != nil && *resources.CPU.Weight != 0 { properties = append(properties, newSystemdProperty("CPUWeight", *resources.CPU.Weight)) }