mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
drivers/raw_exec: enable configuring raw_exec task to have no memory limit (#19670)
* drivers/raw_exec: enable configuring raw_exec task to have no memory limit This PR makes it possible to configure a raw_exec task to not have an upper memory limit, which is how the driver would behave pre-1.7. This is done by setting memory_max = -1. The cluster (or node pool) must have memory oversubscription enabled. * cl: add cl
This commit is contained in:
68
drivers/shared/executor/executor_universal_linux_test.go
Normal file
68
drivers/shared/executor/executor_universal_linux_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//go:build linux
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
func Test_computeMemory(t *testing.T) {
|
||||
cases := []struct {
|
||||
memory int64
|
||||
memoryMax int64
|
||||
expSoft int64
|
||||
expHard int64
|
||||
}{
|
||||
{
|
||||
// typical case; only 'memory' is set and that is used as the hard
|
||||
// memory limit
|
||||
memory: 100,
|
||||
memoryMax: 0,
|
||||
expSoft: 0,
|
||||
expHard: mbToBytes(100),
|
||||
},
|
||||
{
|
||||
// oversub case; both 'memory' and 'memory_max' are set and used as
|
||||
// the soft and hard memory limits
|
||||
memory: 100,
|
||||
memoryMax: 200,
|
||||
expSoft: mbToBytes(100),
|
||||
expHard: mbToBytes(200),
|
||||
},
|
||||
{
|
||||
// special oversub case; 'memory' is set and 'memory_max' is set to
|
||||
// -1; which indicates there should be no hard limit (i.e. -1 / max)
|
||||
memory: 100,
|
||||
memoryMax: memoryNoLimit,
|
||||
expSoft: mbToBytes(100),
|
||||
expHard: memoryNoLimit,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
name := fmt.Sprintf("(%d,%d)", tc.memory, tc.memoryMax)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
command := &ExecCommand{
|
||||
Resources: &drivers.Resources{
|
||||
NomadResources: &structs.AllocatedTaskResources{
|
||||
Memory: structs.AllocatedMemoryResources{
|
||||
MemoryMB: tc.memory,
|
||||
MemoryMaxMB: tc.memoryMax,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
hard, soft := (*UniversalExecutor)(nil).computeMemory(command)
|
||||
must.Eq(t, tc.expSoft, soft)
|
||||
must.Eq(t, tc.expHard, hard)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user