mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Drivers
This commit is contained in:
@@ -105,7 +105,7 @@ func (l *LibcontainerExecutor) Launch(command *ExecCommand) (*ProcessState, erro
|
||||
|
||||
if command.Resources == nil {
|
||||
command.Resources = &drivers.Resources{
|
||||
NomadResources: &structs.Resources{},
|
||||
NomadResources: &structs.AllocatedTaskResources{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,20 +578,21 @@ func configureCgroups(cfg *lconfigs.Config, command *ExecCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if command.Resources.NomadResources.MemoryMB > 0 {
|
||||
if mb := command.Resources.NomadResources.Memory.MemoryMB; mb > 0 {
|
||||
// Total amount of memory allowed to consume
|
||||
cfg.Cgroups.Resources.Memory = int64(command.Resources.NomadResources.MemoryMB * 1024 * 1024)
|
||||
cfg.Cgroups.Resources.Memory = int64(mb * 1024 * 1024)
|
||||
// Disable swap to avoid issues on the machine
|
||||
var memSwappiness uint64
|
||||
cfg.Cgroups.Resources.MemorySwappiness = &memSwappiness
|
||||
}
|
||||
|
||||
if command.Resources.NomadResources.CPU < 2 {
|
||||
return fmt.Errorf("resources.CPU must be equal to or greater than 2: %v", command.Resources.NomadResources.CPU)
|
||||
cpuShares := command.Resources.NomadResources.Cpu.CpuShares
|
||||
if cpuShares < 2 {
|
||||
return fmt.Errorf("resources.Cpu.CpuShares must be equal to or greater than 2: %v", cpuShares)
|
||||
}
|
||||
|
||||
// Set the relative CPU shares for this cgroup.
|
||||
cfg.Cgroups.Resources.CpuShares = uint64(command.Resources.NomadResources.CPU)
|
||||
cfg.Cgroups.Resources.CpuShares = uint64(cpuShares)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func testExecutorCommandWithChroot(t *testing.T) (*ExecCommand, *allocdir.AllocD
|
||||
Env: taskEnv.List(),
|
||||
TaskDir: td.Dir,
|
||||
Resources: &drivers.Resources{
|
||||
NomadResources: task.Resources,
|
||||
NomadResources: alloc.AllocatedResources.Tasks[task.Name],
|
||||
},
|
||||
}
|
||||
configureTLogging(cmd)
|
||||
@@ -109,7 +109,7 @@ func TestExecutor_IsolationAndConstraints(t *testing.T) {
|
||||
data, err := ioutil.ReadFile(memLimits)
|
||||
require.NoError(err)
|
||||
|
||||
expectedMemLim := strconv.Itoa(execCmd.Resources.NomadResources.MemoryMB * 1024 * 1024)
|
||||
expectedMemLim := strconv.Itoa(int(execCmd.Resources.NomadResources.Memory.MemoryMB * 1024 * 1024))
|
||||
actualMemLim := strings.TrimSpace(string(data))
|
||||
require.Equal(actualMemLim, expectedMemLim)
|
||||
require.NoError(executor.Shutdown("", 0))
|
||||
|
||||
@@ -13,15 +13,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
tu "github.com/hashicorp/nomad/testutil"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/helper/testlog"
|
||||
"github.com/hashicorp/nomad/nomad/mock"
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
tu "github.com/hashicorp/nomad/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -55,7 +54,7 @@ func testExecutorCommand(t *testing.T) (*ExecCommand, *allocdir.AllocDir) {
|
||||
Env: taskEnv.List(),
|
||||
TaskDir: td.Dir,
|
||||
Resources: &drivers.Resources{
|
||||
NomadResources: task.Resources,
|
||||
NomadResources: alloc.AllocatedResources.Tasks[task.Name],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user