Browse Source

pkg/sysinfo.New() move v1 code to a newV1() function

This makes it clearer that this code is the cgroups v1 equivalent of newV2().

Also moves the "options" handling to newV2() because it's currently only used
for cgroupsv2.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 years ago
parent
commit
10ce0d84c2
2 changed files with 9 additions and 6 deletions
  1. 5 1
      pkg/sysinfo/cgroup2_linux.go
  2. 4 5
      pkg/sysinfo/sysinfo_linux.go

+ 5 - 1
pkg/sysinfo/cgroup2_linux.go

@@ -14,11 +14,15 @@ import (
 
 type infoCollectorV2 func(info *SysInfo, controllers map[string]struct{}, dirPath string) (warnings []string)
 
-func newV2(quiet bool, opts *opts) *SysInfo {
+func newV2(quiet bool, options ...Opt) *SysInfo {
 	var warnings []string
 	sysInfo := &SysInfo{
 		CgroupUnified: true,
 	}
+	var opts opts
+	for _, o := range options {
+		o(&opts)
+	}
 	g := opts.cg2GroupPath
 	if g == "" {
 		g = "/"

+ 4 - 5
pkg/sysinfo/sysinfo_linux.go

@@ -53,14 +53,13 @@ func WithCgroup2GroupPath(g string) Opt {
 // the kernel supports. If `quiet` is `false` warnings are printed in logs
 // whenever an error occurs or misconfigurations are present.
 func New(quiet bool, options ...Opt) *SysInfo {
-	var opts opts
-	for _, o := range options {
-		o(&opts)
-	}
 	if cdcgroups.Mode() == cdcgroups.Unified {
-		return newV2(quiet, &opts)
+		return newV2(quiet, options...)
 	}
+	return newV1(quiet)
+}
 
+func newV1(quiet bool) *SysInfo {
 	var ops []infoCollector
 	var warnings []string
 	sysInfo := &SysInfo{}