Skip to content

Commit

Permalink
Merge pull request #2108 from wenwenxiong/master
Browse files Browse the repository at this point in the history
keep chrony config file clean and consistency when install and uninstall cluster in the same nodes
  • Loading branch information
ks-ci-bot committed Feb 13, 2024
2 parents 87ff114 + 9b1f463 commit 54a42df
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/kk/pkg/bootstrap/os/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,33 @@ func (n *NodeConfigureNtpServer) Execute(runtime connector.Runtime) error {
chronyService = "chrony.service"
}

clearOldServerCmd := fmt.Sprintf(`sed -i '/^server/d' %s`, chronyConfigFile)
if _, err := runtime.GetRunner().SudoCmd(clearOldServerCmd, false); err != nil {
return errors.Wrapf(err, "delete old servers failed, please check file %s", chronyConfigFile)
}

// if NtpServers was configured
for _, server := range n.KubeConf.Cluster.System.NtpServers {

serverAddr := strings.Trim(server, " \"")
fmt.Printf("ntpserver: %s, current host: %s\n", serverAddr, currentHost.GetName())
if serverAddr == currentHost.GetName() || serverAddr == currentHost.GetInternalAddress() {
allowClientCmd := fmt.Sprintf(`sed -i '/#allow/ a\allow 0.0.0.0/0' %s`, chronyConfigFile)
deleteAllowCmd := fmt.Sprintf(`sed -i '/^allow/d' %s`, chronyConfigFile)
if _, err := runtime.GetRunner().SudoCmd(deleteAllowCmd, false); err != nil {
return errors.Wrapf(err, "delete allow failed, please check file %s", chronyConfigFile)
}
allowClientCmd := fmt.Sprintf(`echo 'allow 0.0.0.0/0' >> %s`, chronyConfigFile)
if _, err := runtime.GetRunner().SudoCmd(allowClientCmd, false); err != nil {
return errors.Wrapf(err, "change host:%s chronyd conf failed, please check file %s", serverAddr, chronyConfigFile)
}
deleteLocalCmd := fmt.Sprintf(`sed -i '/^local/d' %s`, chronyConfigFile)
if _, err := runtime.GetRunner().SudoCmd(deleteLocalCmd, false); err != nil {
return errors.Wrapf(err, "delete local stratum failed, please check file %s", chronyConfigFile)
}
AddLocalCmd := fmt.Sprintf(`echo 'local stratum 10' >> %s`, chronyConfigFile)
if _, err := runtime.GetRunner().SudoCmd(AddLocalCmd, false); err != nil {
return errors.Wrapf(err, "Add local stratum 10 conf failed, please check file %s", chronyConfigFile)
}
}

// use internal ip to client chronyd server
Expand Down

0 comments on commit 54a42df

Please sign in to comment.