Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scaledown processor checker error #4815

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apply/processor/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apply/processor/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 33 additions & 15 deletions pkg/checker/host_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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. " +
Expand All @@ -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
}
Loading