فهرست منبع

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>
Sebastiaan van Stijn 4 سال پیش
والد
کامیت
5cc20ad9e5
5فایلهای تغییر یافته به همراه12 افزوده شده و 37 حذف شده
  1. 3 8
      pkg/sysinfo/cgroup2_linux.go
  2. 3 0
      pkg/sysinfo/sysinfo.go
  3. 4 9
      pkg/sysinfo/sysinfo_linux.go
  4. 2 8
      pkg/sysinfo/sysinfo_other.go
  5. 0 12
      pkg/sysinfo/sysinfo_windows.go

+ 3 - 8
pkg/sysinfo/cgroup2_linux.go

@@ -18,17 +18,12 @@ func newV2(quiet bool, options ...Opt) *SysInfo {
 	var warnings []string
 	var warnings []string
 	sysInfo := &SysInfo{
 	sysInfo := &SysInfo{
 		CgroupUnified: true,
 		CgroupUnified: true,
+		cg2GroupPath:  "/",
 	}
 	}
-	var opts opts
 	for _, o := range options {
 	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 {
 	if err != nil {
 		logrus.Warn(err)
 		logrus.Warn(err)
 	} else {
 	} else {

+ 3 - 0
pkg/sysinfo/sysinfo.go

@@ -2,6 +2,9 @@ package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
 
 
 import "github.com/docker/docker/pkg/parsers"
 import "github.com/docker/docker/pkg/parsers"
 
 
+// Opt for New().
+type Opt func(info *SysInfo)
+
 // SysInfo stores information about which features a kernel supports.
 // SysInfo stores information about which features a kernel supports.
 // TODO Windows: Factor out platform specific capabilities.
 // TODO Windows: Factor out platform specific capabilities.
 type SysInfo struct {
 type SysInfo struct {

+ 4 - 9
pkg/sysinfo/sysinfo_linux.go

@@ -30,13 +30,6 @@ func findCgroupMountpoints() (map[string]string, error) {
 
 
 type infoCollector func(info *SysInfo) (warnings []string)
 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
 // WithCgroup2GroupPath specifies the cgroup v2 group path to inspect availability
 // of the controllers.
 // of the controllers.
 //
 //
@@ -44,8 +37,10 @@ type Opt func(*opts)
 //
 //
 // e.g. g = "/user.slice/user-1000.slice/user@1000.service"
 // e.g. g = "/user.slice/user-1000.slice/user@1000.service"
 func WithCgroup2GroupPath(g string) Opt {
 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
+		}
 	}
 	}
 }
 }
 
 

+ 2 - 8
pkg/sysinfo/sysinfo_unix.go → pkg/sysinfo/sysinfo_other.go

@@ -1,14 +1,8 @@
-// +build !linux,!windows
+// +build !linux
 
 
 package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
 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.
 // New returns an empty SysInfo for non linux for now.
 func New(quiet bool, options ...Opt) *SysInfo {
 func New(quiet bool, options ...Opt) *SysInfo {
-	sysInfo := &SysInfo{}
-	return sysInfo
+	return &SysInfo{}
 }
 }

+ 0 - 12
pkg/sysinfo/sysinfo_windows.go

@@ -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
-}