Skip to content

Commit

Permalink
koordlet: revise system support status initialization
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed Jan 30, 2024
1 parent eabe076 commit 4715971
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 30 deletions.
1 change: 1 addition & 0 deletions pkg/koordlet/koordlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/runtimehooks/runtimehooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 13 additions & 4 deletions pkg/koordlet/util/system/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"go.uber.org/atomic"
"k8s.io/klog/v2"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
51 changes: 51 additions & 0 deletions pkg/koordlet/util/system/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
17 changes: 1 addition & 16 deletions pkg/koordlet/util/system/resctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions pkg/koordlet/util/system/system_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/util/system/util_test_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4715971

Please sign in to comment.