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>
This commit is contained in:
Sebastiaan van Stijn 2021-07-14 12:36:38 +02:00
parent 22d6671db2
commit 10ce0d84c2
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 9 additions and 6 deletions

View File

@ -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 = "/"

View File

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