mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
docker: use correct effective cpuset filename on legacy cgroups v1 systems (#20294)
This commit is contained in:
3
.changelog/20294.txt
Normal file
3
.changelog/20294.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
docker: Fixed a bug where cpuset cgroup would not be updated on cgroup v1 systems
|
||||||
|
```
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/nomad/client/lib/cgroupslib"
|
||||||
"github.com/hashicorp/nomad/helper"
|
"github.com/hashicorp/nomad/helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,8 +50,17 @@ func (c *cpuset) watch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func effectiveCpusetFile() string {
|
||||||
|
switch cgroupslib.GetMode() {
|
||||||
|
case cgroupslib.CG1:
|
||||||
|
return "cpuset.effective_cpus"
|
||||||
|
default:
|
||||||
|
return "cpuset.cpus.effective"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *cpuset) copyCpuset(source, destination string) {
|
func (c *cpuset) copyCpuset(source, destination string) {
|
||||||
source = filepath.Join(source, "cpuset.cpus.effective")
|
source = filepath.Join(source, effectiveCpusetFile())
|
||||||
destination = filepath.Join(destination, "cpuset.cpus")
|
destination = filepath.Join(destination, "cpuset.cpus")
|
||||||
|
|
||||||
// read the current value of usable cores
|
// read the current value of usable cores
|
||||||
@@ -67,7 +77,7 @@ func (c *cpuset) copyCpuset(source, destination string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// otherwise write the new value
|
// otherwise write the new value
|
||||||
err = os.WriteFile(destination, b, 0644)
|
err = os.WriteFile(destination, b, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/nomad/ci"
|
"github.com/hashicorp/nomad/ci"
|
||||||
|
"github.com/hashicorp/nomad/client/testutil"
|
||||||
"github.com/shoenig/test/must"
|
"github.com/shoenig/test/must"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,3 +43,21 @@ func Test_cpuset_watch(t *testing.T) {
|
|||||||
|
|
||||||
must.Eq(t, 1, hits)
|
must.Eq(t, 1, hits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_effectiveCpusetFile_cgroupsv1(t *testing.T) {
|
||||||
|
testutil.CgroupsCompatibleV1(t)
|
||||||
|
|
||||||
|
ci.Parallel(t)
|
||||||
|
|
||||||
|
result := effectiveCpusetFile()
|
||||||
|
must.Eq(t, "cpuset.effective_cpus", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_effectiveCpusetFile_cgroupsv2(t *testing.T) {
|
||||||
|
testutil.CgroupsCompatibleV2(t)
|
||||||
|
|
||||||
|
ci.Parallel(t)
|
||||||
|
|
||||||
|
result := effectiveCpusetFile()
|
||||||
|
must.Eq(t, "cpuset.cpus.effective", result)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user