Skip to content

Commit 4715971

Browse files
committed
koordlet: revise system support status initialization
Signed-off-by: saintube <saintube@foxmail.com>
1 parent eabe076 commit 4715971

File tree

7 files changed

+69
-30
lines changed

7 files changed

+69
-30
lines changed

pkg/koordlet/koordlet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewDaemon(config *config.Configuration) (Daemon, error) {
7676
klog.Infof("NODE_NAME is %v, start time %v", nodeName, float64(time.Now().Unix()))
7777
metrics.RecordKoordletStartTime(nodeName, float64(time.Now().Unix()))
7878

79+
system.InitSupportConfigs()
7980
klog.Infof("sysconf: %+v, agentMode: %v", system.Conf, system.AgentMode)
8081
klog.Infof("kernel version INFO: %+v", system.HostSystemInfo)
8182

pkg/koordlet/runtimehooks/runtimehooks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func NewRuntimeHook(si statesinformer.StatesInformer, cfg *Config) (RuntimeHook,
111111
}
112112
nriServer, err = nri.NewNriServer(nriServerOptions)
113113
if err != nil {
114-
klog.Errorf("new nri mode runtimehooks server error: %v", err)
114+
klog.Warningf("new nri mode runtimehooks server error: %v", err)
115115
}
116116
} else {
117117
klog.V(4).Info("nri mode runtimehooks is disabled")

pkg/koordlet/util/system/config.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222

2323
"go.uber.org/atomic"
24+
"k8s.io/klog/v2"
2425
)
2526

2627
const (
@@ -57,10 +58,20 @@ func init() {
5758
}
5859
}
5960

60-
func initSupportConfigs() {
61+
// InitSupportConfigs initializes the system support status.
62+
// e.g. the cgroup version, resctrl capability
63+
func InitSupportConfigs() {
64+
// $ getconf CLK_TCK > jiffies
65+
if err := initJiffies(); err != nil {
66+
klog.Warningf("failed to get Jiffies, use the default %v, err: %v", Jiffies, err)
67+
}
6168
initCgroupsVersion()
6269
HostSystemInfo = collectVersionInfo()
63-
_, _ = IsSupportResctrl()
70+
if isResctrlSupported, err := IsSupportResctrl(); err != nil {
71+
klog.Warningf("failed to check resctrl support status, use %d, err: %v", isResctrlSupported, err)
72+
} else {
73+
klog.V(4).Infof("resctrl supported: %v", isResctrlSupported)
74+
}
6475
}
6576

6677
func NewHostModeConfig() *Config {
@@ -110,6 +121,4 @@ func (c *Config) InitFlags(fs *flag.FlagSet) {
110121
fs.StringVar(&c.PouchEndpoint, "pouch-endpoint", c.PouchEndpoint, "pouch endPoint")
111122

112123
fs.StringVar(&c.DefaultRuntimeType, "default-runtime-type", c.DefaultRuntimeType, "default runtime type during runtime hooks handle request, candidates are containerd/docker/pouch.")
113-
114-
initSupportConfigs()
115124
}

pkg/koordlet/util/system/config_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,54 @@ func Test_InitFlags(t *testing.T) {
6060
assert.NotNil(t, cfg)
6161
})
6262
}
63+
64+
func Test_InitSupportConfigs(t *testing.T) {
65+
type fields struct {
66+
prepareFn func(helper *FileTestUtil)
67+
}
68+
type expects struct {
69+
hostSystemInfo VersionInfo
70+
}
71+
tests := []struct {
72+
name string
73+
fields fields
74+
expects expects
75+
}{
76+
{
77+
name: "not anolis os, not support resctrl",
78+
fields: fields{
79+
prepareFn: func(helper *FileTestUtil) {},
80+
},
81+
expects: expects{
82+
hostSystemInfo: VersionInfo{
83+
IsAnolisOS: false,
84+
},
85+
},
86+
},
87+
{
88+
name: "anolis os, not support resctrl",
89+
fields: fields{
90+
prepareFn: func(helper *FileTestUtil) {
91+
bvtResource, _ := GetCgroupResource(CPUBVTWarpNsName)
92+
helper.WriteCgroupFileContents("", bvtResource, "0")
93+
},
94+
},
95+
expects: expects{
96+
hostSystemInfo: VersionInfo{
97+
IsAnolisOS: true,
98+
},
99+
},
100+
},
101+
}
102+
for _, tt := range tests {
103+
t.Run(tt.name, func(t *testing.T) {
104+
helper := NewFileTestUtil(t)
105+
defer helper.Cleanup()
106+
if tt.fields.prepareFn != nil {
107+
tt.fields.prepareFn(helper)
108+
}
109+
InitSupportConfigs()
110+
assert.Equal(t, tt.expects.hostSystemInfo, HostSystemInfo)
111+
})
112+
}
113+
}

pkg/koordlet/util/system/resctrl.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func IsSupportResctrl() (bool, error) {
103103
return false, err
104104
}
105105
// Kernel cmdline not set resctrl features does not ensure feature must be disabled.
106-
klog.V(4).Infof("isResctrlAvailableByKernelCmd result, cpuSupport: %v, kernelSupport: %v",
106+
klog.Infof("IsSupportResctrl result, cpuSupport: %v, kernelSupport: %v",
107107
cpuSupport, kernelCmdSupport)
108108
isSupportResctrl = cpuSupport
109109
isInit = true
@@ -560,21 +560,6 @@ func CheckAndTryEnableResctrlCat() error {
560560
return nil
561561
}
562562

563-
func InitCatGroupIfNotExist(group string) error {
564-
path := GetResctrlGroupRootDirPath(group)
565-
_, err := os.Stat(path)
566-
if err == nil {
567-
return nil
568-
} else if !os.IsNotExist(err) {
569-
return fmt.Errorf("check dir %v for group %s but got unexpected err: %v", path, group, err)
570-
}
571-
err = os.Mkdir(path, 0755)
572-
if err != nil {
573-
return fmt.Errorf("create dir %v failed for group %s, err: %v", path, group, err)
574-
}
575-
return nil
576-
}
577-
578563
func CheckResctrlSchemataValid() error {
579564
schemataPath := GetResctrlSchemataFilePath("")
580565
schemataRaw, err := ReadResctrlSchemataRaw(schemataPath, -1)

pkg/koordlet/util/system/system_file.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,12 @@ var (
5151
Jiffies = float64(10 * time.Millisecond)
5252
)
5353

54-
func init() {
55-
// $ getconf CLK_TCK > jiffies
56-
if err := initJiffies(); err != nil {
57-
klog.Warningf("failed to get Jiffies, use the default %v, err: %v", Jiffies, err)
58-
}
59-
}
60-
6154
// initJiffies use command "getconf CLK_TCK" to fetch the clock tick on current host,
6255
// if the command doesn't exist, uses the default value 10ms for jiffies
6356
func initJiffies() error {
6457
getconf, err := exec.LookPath("getconf")
6558
if err != nil {
66-
return nil
59+
return err
6760
}
6861
cmd := exec.Command(getconf, "CLK_TCK")
6962
var out bytes.Buffer

pkg/koordlet/util/system/util_test_tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewFileTestUtil(t testing.TB) *FileTestUtil {
8181
Conf.SysFSRootDir = filepath.Join(tempDir, "fs")
8282
Conf.VarRunRootDir = tempDir
8383

84-
initSupportConfigs()
84+
InitSupportConfigs()
8585

8686
return &FileTestUtil{
8787
TempDir: tempDir,

0 commit comments

Comments
 (0)