Skip to content

Commit

Permalink
Mark CGroups as off when missing essential controllers (#19176)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVentura authored Dec 15, 2023
1 parent f1fb514 commit fb43b14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/19176.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cgroupslib: Consider CGroups OFF when essential controllers are missing
```
21 changes: 20 additions & 1 deletion client/lib/cgroupslib/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bufio"
"io"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/go-set/v2"
Expand All @@ -27,7 +28,25 @@ func detect() Mode {
_ = f.Close()
}()

return scan(f)
mode := scan(f)
if mode == CG2 && !functionalCgroups2() {
return OFF
}
return mode
}

func functionalCgroups2() bool {
const controllersFile = "cgroup.controllers"
requiredCgroup2Controllers := []string{"cpuset", "cpu", "io", "memory", "pids"}

controllersRootPath := filepath.Join(root, controllersFile)
content, err := os.ReadFile(controllersRootPath)
if err != nil {
return false
}

rootSubtreeControllers := set.From[string](strings.Fields(string(content)))
return rootSubtreeControllers.ContainsSlice(requiredCgroup2Controllers)
}

func scan(in io.Reader) Mode {
Expand Down

0 comments on commit fb43b14

Please sign in to comment.