mirror of
https://github.com/kemko/nomad.git
synced 2026-01-02 00:15:43 +03:00
* drivers/raw_exec: enable setting cgroup override values
This PR enables configuration of cgroup override values on the `raw_exec`
task driver. WARNING: setting cgroup override values eliminates any
gauruntee Nomad can make about resource availability for *any* task on
the client node.
For cgroup v2 systems, set a single unified cgroup path using `cgroup_v2_override`.
The path may be either absolute or relative to the cgroup root.
config {
cgroup_v2_override = "custom.slice/app.scope"
}
or
config {
cgroup_v2_override = "/sys/fs/cgroup/custom.slice/app.scope"
}
For cgroup v1 systems, set a per-controller path for each controller using
`cgroup_v1_override`. The path(s) may be either absolute or relative to
the controller root.
config {
cgroup_v1_override = {
"pids": "custom/app",
"cpuset": "custom/app",
}
}
or
config {
cgroup_v1_override = {
"pids": "/sys/fs/cgroup/pids/custom/app",
"cpuset": "/sys/fs/cgroup/cpuset/custom/app",
}
}
* drivers/rawexec: ensure only one of v1/v2 cgroup override is set
* drivers/raw_exec: executor should error if setting cgroup does not work
* drivers/raw_exec: create cgroups in raw_exec tests
* drivers/raw_exec: ensure we fail to start if custom cgroup set and non-root
* move custom cgroup func into shared file
---------
Co-authored-by: Michael Schurter <mschurter@hashicorp.com>
46 lines
959 B
Go
46 lines
959 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
//go:build linux
|
|
|
|
package cgroupslib
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/shoenig/test/must"
|
|
)
|
|
|
|
func TestCustomPathCG1(t *testing.T) {
|
|
exp := "/sys/fs/cgroup/pids/custom/path"
|
|
|
|
t.Run("absolute", func(t *testing.T) {
|
|
result := CustomPathCG1("pids", "/sys/fs/cgroup/pids/custom/path")
|
|
must.Eq(t, result, exp)
|
|
})
|
|
|
|
t.Run("relative", func(t *testing.T) {
|
|
result := CustomPathCG1("pids", "custom/path")
|
|
must.Eq(t, result, exp)
|
|
})
|
|
}
|
|
|
|
func TestCustomPathCG2(t *testing.T) {
|
|
exp := "/sys/fs/cgroup/custom.slice/path.scope"
|
|
|
|
t.Run("unset", func(t *testing.T) {
|
|
result := CustomPathCG2("")
|
|
must.Eq(t, result, "")
|
|
})
|
|
|
|
t.Run("absolute", func(t *testing.T) {
|
|
result := CustomPathCG2("/sys/fs/cgroup/custom.slice/path.scope")
|
|
must.Eq(t, result, exp)
|
|
})
|
|
|
|
t.Run("relative", func(t *testing.T) {
|
|
result := CustomPathCG2("custom.slice/path.scope")
|
|
must.Eq(t, result, exp)
|
|
})
|
|
}
|