Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark CGroups as off when missing essential controllers #19176

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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