Skip to content

Commit

Permalink
fix!: adjust auto cgroup root detection
Browse files Browse the repository at this point in the history
Signed-off-by: black-desk <me@black-desk.cn>
  • Loading branch information
black-desk committed Jan 4, 2024
1 parent c2587e1 commit f1fbacd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/black-desk/lib/go v0.0.0-20231023094454-94c87a910679
github.com/deniswernert/go-fstab v0.0.0-20141204152952-eb4090f26517
github.com/go-playground/validator/v10 v10.16.0
github.com/google/nftables v0.1.1-0.20231024065723-32bfbb662717
github.com/onsi/ginkgo/v2 v2.13.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deniswernert/go-fstab v0.0.0-20141204152952-eb4090f26517 h1:YMvaGdOIUowdD6ZybqLsUamGvWONZViUeW6T22U7fP0=
github.com/deniswernert/go-fstab v0.0.0-20141204152952-eb4090f26517/go.mod h1:ixLGX4GUQg44igA/iJawr+KYZLyWOoAzAgTCQcJ/K9Y=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cgtproxy/config/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
)

var (
ErrCannotFoundCgroupv2Mount = errors.New("`cgroup2` mount point not found in /proc/mounts.")
ErrCannotFoundCgroupv2Root = errors.New("`cgroup2` mount point not found.")
)
35 changes: 11 additions & 24 deletions pkg/cgtproxy/config/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package config

import (
"fmt"
"os"

. "github.com/black-desk/lib/go/errwrap"
fstab "github.com/deniswernert/go-fstab"
"github.com/go-playground/validator/v10"
)

Expand Down Expand Up @@ -58,36 +58,23 @@ func (c *Config) check() (err error) {
func getCgroupRoot() (cgroupRoot CGroupRoot, err error) {
defer Wrap(&err, "get cgroupv2 mount point")

var mounts fstab.Mounts
mounts, err = fstab.ParseProc()
if err != nil {
return
}
paths := []string{"/sys/fs/cgroup/unified", "/sys/fs/cgroup"}

var (
mountFound bool
fsFile CGroupRoot
)
for i := range mounts {
mount := mounts[i]
fsVfsType := mount.VfsType

if fsVfsType != "cgroup2" {
for i := range paths {
var fileInfo os.FileInfo
fileInfo, err = os.Stat(paths[i])
if err != nil {
continue
}

fsFile = CGroupRoot(mount.File)
mountFound = true

break
}
if !fileInfo.IsDir() {
continue
}

if !mountFound {
err = ErrCannotFoundCgroupv2Mount
cgroupRoot = CGroupRoot(paths[i])
return
}

cgroupRoot = fsFile

err = ErrCannotFoundCgroupv2Root
return
}

0 comments on commit f1fbacd

Please sign in to comment.