cgv1: do not disable cpuset manager if reserved interface already exists (#16467)

* cgv1: do not disable cpuset manager if reserved interface already exists

This PR fixes a bug where restarting a Nomad Client on a machine using cgroups
v1 (e.g. Ubuntu 20.04) would cause the cpuset cgroups manager to disable itself.

This is being caused by incorrectly interpreting a "file exists" error as
problematic when ensuring the reserved cpuset exists. If we get a "file exists"
error, that just means the Client was likely restarted.

Note that a machine reboot would fix the issue - the groups interfaces are
ephemoral.

* cl: add cl
This commit is contained in:
Seth Hoenig 2023-03-13 17:00:17 -05:00 committed by GitHub
parent adf147cb36
commit a25d3ea792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

3
.changelog/16467.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a bug where cpuset initialization fails after Client restart
```

View File

@ -4,6 +4,7 @@ package cgutil
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -59,8 +60,10 @@ func NewCpusetManagerV1(cgroupParent string, _ []uint16, logger hclog.Logger) Cp
// ensure the reserved cpuset exists, but only copy the mems from the parent if creating the cgroup // ensure the reserved cpuset exists, but only copy the mems from the parent if creating the cgroup
if err = os.Mkdir(filepath.Join(cgroupParentPath, ReservedCpusetCgroupName), 0755); err != nil { if err = os.Mkdir(filepath.Join(cgroupParentPath, ReservedCpusetCgroupName), 0755); err != nil {
logger.Warn("failed to ensure reserved cpuset.cpus interface exists; disable cpuset management", "error", err) if !errors.Is(err, os.ErrExist) {
return new(NoopCpusetManager) logger.Warn("failed to ensure reserved cpuset.cpus interface exists; disable cpuset management", "error", err)
return new(NoopCpusetManager)
}
} }
if err = cgroups.WriteFile(filepath.Join(cgroupParentPath, ReservedCpusetCgroupName), "cpuset.mems", parentMems); err != nil { if err = cgroups.WriteFile(filepath.Join(cgroupParentPath, ReservedCpusetCgroupName), "cpuset.mems", parentMems); err != nil {