From 10ce0d84c2bdaf9b9a887e9af7bd517c029de658 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 14 Jul 2021 12:36:38 +0200 Subject: [PATCH] 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 --- pkg/sysinfo/cgroup2_linux.go | 6 +++++- pkg/sysinfo/sysinfo_linux.go | 9 ++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/sysinfo/cgroup2_linux.go b/pkg/sysinfo/cgroup2_linux.go index 1ea3cd51d9..559f04adca 100644 --- a/pkg/sysinfo/cgroup2_linux.go +++ b/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 = "/" diff --git a/pkg/sysinfo/sysinfo_linux.go b/pkg/sysinfo/sysinfo_linux.go index 42709a4d35..30209f7dd7 100644 --- a/pkg/sysinfo/sysinfo_linux.go +++ b/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{}