Skip to content

Commit

Permalink
fix: scaledown processor checker error (#4815)
Browse files Browse the repository at this point in the history
* fix: scaledown processor checker error
ghostloda authored Jul 2, 2024
1 parent 694ddb9 commit 8382b4b
Showing 3 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/apply/processor/create.go
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ func (c *CreateProcessor) Check(cluster *v2.Cluster) error {
// the order doesn't matter
ips = append(ips, cluster.GetMasterIPAndPortList()...)
ips = append(ips, cluster.GetNodeIPAndPortList()...)
return NewCheckError(checker.RunCheckList([]checker.Interface{checker.NewIPsHostChecker(ips)}, cluster, checker.PhasePre))
return NewCheckError(checker.RunCheckList([]checker.Interface{checker.NewIPsHostChecker(ips), checker.NewContainerdChecker(ips)}, cluster, checker.PhasePre))
}

func (c *CreateProcessor) PreProcess(cluster *v2.Cluster) error {
8 changes: 4 additions & 4 deletions pkg/apply/processor/scale.go
Original file line number Diff line number Diff line change
@@ -154,11 +154,11 @@ func (c ScaleProcessor) UnMountRootfs(cluster *v2.Cluster) error {

func (c *ScaleProcessor) JoinCheck(cluster *v2.Cluster) error {
logger.Info("Executing pipeline JoinCheck in ScaleProcessor.")
var ips []string
var ips, scales []string
ips = append(ips, cluster.GetMaster0IPAndPort())
ips = append(ips, c.MastersToJoin...)
ips = append(ips, c.NodesToJoin...)
return NewCheckError(checker.RunCheckList([]checker.Interface{checker.NewIPsHostChecker(ips)}, cluster, checker.PhasePre))
scales = append(c.MastersToJoin, c.NodesToJoin...)
ips = append(ips, scales...)
return NewCheckError(checker.RunCheckList([]checker.Interface{checker.NewIPsHostChecker(ips), checker.NewContainerdChecker(scales)}, cluster, checker.PhasePre))
}

func (c *ScaleProcessor) DeleteCheck(cluster *v2.Cluster) error {
48 changes: 33 additions & 15 deletions pkg/checker/host_checker.go
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ func (a HostChecker) Check(cluster *v2.Cluster, _ string) error {
if err := checkHostnameUnique(execer, ipList); err != nil {
return err
}
if err := checkContainerd(execer, ipList); err != nil {
return err
}
return checkTimeSync(execer, ipList)
}

@@ -94,18 +91,6 @@ func checkTimeSync(s exec.Interface, ipList []string) error {
return nil
}

// Check whether the containerd is installed
func checkContainerd(s exec.Interface, ipList []string) error {
logger.Info("checker:containerd %v", ipList)
for _, ip := range ipList {
_, err := s.CmdToString(ip, "containerd --version", "")
if err == nil {
return fmt.Errorf("containerd is installed on %s please uninstall it first", ip)
}
}
return nil
}

func confirmNonOddMasters() error {
prompt := "Warning: Using an even number of master nodes is a risky operation and can lead to reduced high availability and potential resource wastage. " +
"It is strongly recommended to use an odd number of master nodes for optimal cluster stability. " +
@@ -120,3 +105,36 @@ func confirmNonOddMasters() error {
}
return nil
}

type ContainerdChecker struct {
IPs []string
}

func NewContainerdChecker(ips []string) Interface {
return &ContainerdChecker{IPs: ips}
}

func (a ContainerdChecker) Check(cluster *v2.Cluster, _ string) error {
var ipList []string
if len(a.IPs) != 0 {
ipList = a.IPs
}
sshClient := ssh.NewCacheClientFromCluster(cluster, false)
execer, err := exec.New(sshClient)
if err != nil {
return err
}
return checkContainerd(execer, ipList)
}

// Check whether the containerd is installed
func checkContainerd(s exec.Interface, ipList []string) error {
logger.Info("checker:containerd %v", ipList)
for _, ip := range ipList {
_, err := s.CmdToString(ip, "containerd --version", "")
if err == nil {
return fmt.Errorf("containerd is installed on %s please uninstall it first", ip)
}
}
return nil
}

0 comments on commit 8382b4b

Please sign in to comment.