mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/sysinfo: adjust Opt to set new field
This removes the need to have the opts type. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
ca27b473cc
commit
5cc20ad9e5
5 changed files with 12 additions and 37 deletions
|
@ -18,17 +18,12 @@ func newV2(quiet bool, options ...Opt) *SysInfo {
|
|||
var warnings []string
|
||||
sysInfo := &SysInfo{
|
||||
CgroupUnified: true,
|
||||
cg2GroupPath: "/",
|
||||
}
|
||||
var opts opts
|
||||
for _, o := range options {
|
||||
o(&opts)
|
||||
o(sysInfo)
|
||||
}
|
||||
g := opts.cg2GroupPath
|
||||
if g == "" {
|
||||
g = "/"
|
||||
}
|
||||
sysInfo.cg2GroupPath = g
|
||||
m, err := cgroupsV2.LoadManager("/sys/fs/cgroup", g)
|
||||
m, err := cgroupsV2.LoadManager("/sys/fs/cgroup", sysInfo.cg2GroupPath)
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,9 @@ package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
|||
|
||||
import "github.com/docker/docker/pkg/parsers"
|
||||
|
||||
// Opt for New().
|
||||
type Opt func(info *SysInfo)
|
||||
|
||||
// SysInfo stores information about which features a kernel supports.
|
||||
// TODO Windows: Factor out platform specific capabilities.
|
||||
type SysInfo struct {
|
||||
|
|
|
@ -30,13 +30,6 @@ func findCgroupMountpoints() (map[string]string, error) {
|
|||
|
||||
type infoCollector func(info *SysInfo) (warnings []string)
|
||||
|
||||
type opts struct {
|
||||
cg2GroupPath string
|
||||
}
|
||||
|
||||
// Opt for New().
|
||||
type Opt func(*opts)
|
||||
|
||||
// WithCgroup2GroupPath specifies the cgroup v2 group path to inspect availability
|
||||
// of the controllers.
|
||||
//
|
||||
|
@ -44,8 +37,10 @@ type Opt func(*opts)
|
|||
//
|
||||
// e.g. g = "/user.slice/user-1000.slice/user@1000.service"
|
||||
func WithCgroup2GroupPath(g string) Opt {
|
||||
return func(o *opts) {
|
||||
o.cg2GroupPath = path.Clean(g)
|
||||
return func(o *SysInfo) {
|
||||
if p := path.Clean(g); p != "" {
|
||||
o.cg2GroupPath = p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
// +build !linux,!windows
|
||||
// +build !linux
|
||||
|
||||
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||
|
||||
type opts struct{}
|
||||
|
||||
// Opt for New().
|
||||
type Opt func(*opts)
|
||||
|
||||
// New returns an empty SysInfo for non linux for now.
|
||||
func New(quiet bool, options ...Opt) *SysInfo {
|
||||
sysInfo := &SysInfo{}
|
||||
return sysInfo
|
||||
return &SysInfo{}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
||||
|
||||
type opts struct{}
|
||||
|
||||
// Opt for New().
|
||||
type Opt func(*opts)
|
||||
|
||||
// New returns an empty SysInfo for windows for now.
|
||||
func New(quiet bool, options ...Opt) *SysInfo {
|
||||
sysInfo := &SysInfo{}
|
||||
return sysInfo
|
||||
}
|
Loading…
Reference in a new issue