Skip to content

Commit e94388d

Browse files
committed
common/pkg/cgroups.AvailableControllers simplification
Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 26e4421 commit e94388d

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

common/pkg/cgroups/cgroups_linux.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ type CgroupControl struct {
4141
systemd bool
4242
}
4343

44-
type controller struct {
45-
name string
46-
symlink bool
47-
}
48-
4944
type controllerHandler interface {
5045
Apply(*CgroupControl, *cgroups.Resources) error
5146
Stat(*CgroupControl, *cgroups.Stats) error
@@ -80,8 +75,8 @@ func init() {
8075
}
8176

8277
// getAvailableControllers get the available controllers.
83-
func getAvailableControllers() ([]controller, error) {
84-
controllers := []controller{}
78+
func getAvailableControllers() ([]string, error) {
79+
controllers := []string{}
8580
controllersFile := filepath.Join(cgroupRoot, "cgroup.controllers")
8681

8782
// rootless cgroupv2: check available controllers for current user, systemd or servicescope will inherit
@@ -99,27 +94,14 @@ func getAvailableControllers() ([]controller, error) {
9994
return nil, fmt.Errorf("failed while reading controllers for cgroup v2: %w", err)
10095
}
10196
for controllerName := range strings.FieldsSeq(string(controllersFileBytes)) {
102-
c := controller{
103-
name: controllerName,
104-
symlink: false,
105-
}
106-
controllers = append(controllers, c)
97+
controllers = append(controllers, controllerName)
10798
}
10899
return controllers, nil
109100
}
110101

111102
// AvailableControllers get string:bool map of all the available controllers.
112103
func AvailableControllers(exclude map[string]controllerHandler) ([]string, error) {
113-
availableControllers, err := getAvailableControllers()
114-
if err != nil {
115-
return nil, err
116-
}
117-
controllerList := []string{}
118-
for _, controller := range availableControllers {
119-
controllerList = append(controllerList, controller.name)
120-
}
121-
122-
return controllerList, nil
104+
return getAvailableControllers()
123105
}
124106

125107
func getCgroupPathForCurrentProcess() (string, error) {

0 commit comments

Comments
 (0)