fix(cli): create symlink to sysconf if none exists (#1679)

This commit is contained in:
dkeven 2025-08-05 15:44:42 +08:00 committed by GitHub
parent beed97f704
commit 83e070761c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View file

@ -166,6 +166,15 @@ func (c *ConfigureOSModule) Init() {
Parallel: true,
}
symlinkSysconf := &task.RemoteTask{
Name: "SymlinkSysconf",
Desc: "Create symbolic link to sysconf if non-existing",
Hosts: c.Runtime.GetAllHosts(),
Prepare: &kubernetes.NodeInCluster{Not: true},
Action: new(SymLinkSysconf),
Parallel: true,
}
ConfigureNtpServer := &task.RemoteTask{
Name: "ConfigureNtpServer",
Desc: "configure the ntp server for each node",
@ -191,6 +200,7 @@ func (c *ConfigureOSModule) Init() {
initOS,
GenerateScript,
ExecScript,
symlinkSysconf,
ConfigureNtpServer,
configureSwap,
}

View file

@ -371,6 +371,35 @@ func (n *NodeExecScript) Execute(runtime connector.Runtime) error {
return nil
}
type SymLinkSysconf struct {
common.KubeAction
}
func (a *SymLinkSysconf) Execute(runtime connector.Runtime) error {
sysconfPath := "/etc/sysctl.conf"
sysconfSymLinkPath := "/etc/sysctl.d/99-sysctl.conf"
linkExists, err := runtime.GetRunner().FileExist(sysconfSymLinkPath)
if err != nil {
return fmt.Errorf("failed to check if %s exists", sysconfSymLinkPath)
}
if linkExists {
return nil
}
sysconfDir := filepath.Dir(sysconfSymLinkPath)
dirExists, err := runtime.GetRunner().DirExist(sysconfDir)
if err != nil {
return fmt.Errorf("failed to check if %s exists", sysconfDir)
}
if !dirExists {
err = runtime.GetRunner().MkDir(sysconfDir)
if err != nil {
return err
}
}
_, err = runtime.GetRunner().SudoCmd(fmt.Sprintf("ln -s %s %s", sysconfPath, sysconfSymLinkPath), true, false)
return err
}
var (
etcdFiles = []string{
"/usr/local/bin/etcd",