diff --git a/pkg/koordlet/koordlet.go b/pkg/koordlet/koordlet.go index d9ccce11f..99c4f094b 100644 --- a/pkg/koordlet/koordlet.go +++ b/pkg/koordlet/koordlet.go @@ -76,6 +76,7 @@ func NewDaemon(config *config.Configuration) (Daemon, error) { klog.Infof("NODE_NAME is %v, start time %v", nodeName, float64(time.Now().Unix())) metrics.RecordKoordletStartTime(nodeName, float64(time.Now().Unix())) + system.InitSupportConfigs() klog.Infof("sysconf: %+v, agentMode: %v", system.Conf, system.AgentMode) klog.Infof("kernel version INFO: %+v", system.HostSystemInfo) diff --git a/pkg/koordlet/runtimehooks/runtimehooks.go b/pkg/koordlet/runtimehooks/runtimehooks.go index 49e4eb5b7..9a888ba42 100644 --- a/pkg/koordlet/runtimehooks/runtimehooks.go +++ b/pkg/koordlet/runtimehooks/runtimehooks.go @@ -111,7 +111,7 @@ func NewRuntimeHook(si statesinformer.StatesInformer, cfg *Config) (RuntimeHook, } nriServer, err = nri.NewNriServer(nriServerOptions) if err != nil { - klog.Errorf("new nri mode runtimehooks server error: %v", err) + klog.Warningf("new nri mode runtimehooks server error: %v", err) } } else { klog.V(4).Info("nri mode runtimehooks is disabled") diff --git a/pkg/koordlet/util/system/config.go b/pkg/koordlet/util/system/config.go index 10f5d0435..9dda99659 100644 --- a/pkg/koordlet/util/system/config.go +++ b/pkg/koordlet/util/system/config.go @@ -21,6 +21,7 @@ import ( "os" "go.uber.org/atomic" + "k8s.io/klog/v2" ) const ( @@ -57,10 +58,20 @@ func init() { } } -func initSupportConfigs() { +// InitSupportConfigs initializes the system support status. +// e.g. the cgroup version, resctrl capability +func InitSupportConfigs() { + // $ getconf CLK_TCK > jiffies + if err := initJiffies(); err != nil { + klog.Warningf("failed to get Jiffies, use the default %v, err: %v", Jiffies, err) + } initCgroupsVersion() HostSystemInfo = collectVersionInfo() - _, _ = IsSupportResctrl() + if isResctrlSupported, err := IsSupportResctrl(); err != nil { + klog.Warningf("failed to check resctrl support status, use %d, err: %v", isResctrlSupported, err) + } else { + klog.V(4).Infof("resctrl supported: %v", isResctrlSupported) + } } func NewHostModeConfig() *Config { @@ -110,6 +121,4 @@ func (c *Config) InitFlags(fs *flag.FlagSet) { fs.StringVar(&c.PouchEndpoint, "pouch-endpoint", c.PouchEndpoint, "pouch endPoint") fs.StringVar(&c.DefaultRuntimeType, "default-runtime-type", c.DefaultRuntimeType, "default runtime type during runtime hooks handle request, candidates are containerd/docker/pouch.") - - initSupportConfigs() } diff --git a/pkg/koordlet/util/system/config_test.go b/pkg/koordlet/util/system/config_test.go index 2d970f22b..4de788b70 100644 --- a/pkg/koordlet/util/system/config_test.go +++ b/pkg/koordlet/util/system/config_test.go @@ -60,3 +60,54 @@ func Test_InitFlags(t *testing.T) { assert.NotNil(t, cfg) }) } + +func Test_InitSupportConfigs(t *testing.T) { + type fields struct { + prepareFn func(helper *FileTestUtil) + } + type expects struct { + hostSystemInfo VersionInfo + } + tests := []struct { + name string + fields fields + expects expects + }{ + { + name: "not anolis os, not support resctrl", + fields: fields{ + prepareFn: func(helper *FileTestUtil) {}, + }, + expects: expects{ + hostSystemInfo: VersionInfo{ + IsAnolisOS: false, + }, + }, + }, + { + name: "anolis os, not support resctrl", + fields: fields{ + prepareFn: func(helper *FileTestUtil) { + bvtResource, _ := GetCgroupResource(CPUBVTWarpNsName) + helper.WriteCgroupFileContents("", bvtResource, "0") + }, + }, + expects: expects{ + hostSystemInfo: VersionInfo{ + IsAnolisOS: true, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + helper := NewFileTestUtil(t) + defer helper.Cleanup() + if tt.fields.prepareFn != nil { + tt.fields.prepareFn(helper) + } + InitSupportConfigs() + assert.Equal(t, tt.expects.hostSystemInfo, HostSystemInfo) + }) + } +} diff --git a/pkg/koordlet/util/system/resctrl.go b/pkg/koordlet/util/system/resctrl.go index 4f90cc275..9580bdd15 100644 --- a/pkg/koordlet/util/system/resctrl.go +++ b/pkg/koordlet/util/system/resctrl.go @@ -103,7 +103,7 @@ func IsSupportResctrl() (bool, error) { return false, err } // Kernel cmdline not set resctrl features does not ensure feature must be disabled. - klog.V(4).Infof("isResctrlAvailableByKernelCmd result, cpuSupport: %v, kernelSupport: %v", + klog.Infof("IsSupportResctrl result, cpuSupport: %v, kernelSupport: %v", cpuSupport, kernelCmdSupport) isSupportResctrl = cpuSupport isInit = true @@ -560,21 +560,6 @@ func CheckAndTryEnableResctrlCat() error { return nil } -func InitCatGroupIfNotExist(group string) error { - path := GetResctrlGroupRootDirPath(group) - _, err := os.Stat(path) - if err == nil { - return nil - } else if !os.IsNotExist(err) { - return fmt.Errorf("check dir %v for group %s but got unexpected err: %v", path, group, err) - } - err = os.Mkdir(path, 0755) - if err != nil { - return fmt.Errorf("create dir %v failed for group %s, err: %v", path, group, err) - } - return nil -} - func CheckResctrlSchemataValid() error { schemataPath := GetResctrlSchemataFilePath("") schemataRaw, err := ReadResctrlSchemataRaw(schemataPath, -1) diff --git a/pkg/koordlet/util/system/system_file.go b/pkg/koordlet/util/system/system_file.go index c28ccb0d1..39e31d663 100644 --- a/pkg/koordlet/util/system/system_file.go +++ b/pkg/koordlet/util/system/system_file.go @@ -51,19 +51,12 @@ var ( Jiffies = float64(10 * time.Millisecond) ) -func init() { - // $ getconf CLK_TCK > jiffies - if err := initJiffies(); err != nil { - klog.Warningf("failed to get Jiffies, use the default %v, err: %v", Jiffies, err) - } -} - // initJiffies use command "getconf CLK_TCK" to fetch the clock tick on current host, // if the command doesn't exist, uses the default value 10ms for jiffies func initJiffies() error { getconf, err := exec.LookPath("getconf") if err != nil { - return nil + return err } cmd := exec.Command(getconf, "CLK_TCK") var out bytes.Buffer diff --git a/pkg/koordlet/util/system/util_test_tool.go b/pkg/koordlet/util/system/util_test_tool.go index f5f80957a..4384e7726 100644 --- a/pkg/koordlet/util/system/util_test_tool.go +++ b/pkg/koordlet/util/system/util_test_tool.go @@ -81,7 +81,7 @@ func NewFileTestUtil(t testing.TB) *FileTestUtil { Conf.SysFSRootDir = filepath.Join(tempDir, "fs") Conf.VarRunRootDir = tempDir - initSupportConfigs() + InitSupportConfigs() return &FileTestUtil{ TempDir: tempDir,