From 8382b4b594e7ae157a77f1903c19aae1bf0de5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=B4=E8=8E=B2=E6=A6=B4=E8=8E=B2?= <78798447@qq.com> Date: Tue, 2 Jul 2024 10:55:55 +0800 Subject: [PATCH] fix: scaledown processor checker error (#4815) * fix: scaledown processor checker error --- pkg/apply/processor/create.go | 2 +- pkg/apply/processor/scale.go | 8 +++--- pkg/checker/host_checker.go | 48 ++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pkg/apply/processor/create.go b/pkg/apply/processor/create.go index dcf4d03657a..55a61243dd8 100644 --- a/pkg/apply/processor/create.go +++ b/pkg/apply/processor/create.go @@ -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 { diff --git a/pkg/apply/processor/scale.go b/pkg/apply/processor/scale.go index eadad06b555..e6e64e7e1da 100644 --- a/pkg/apply/processor/scale.go +++ b/pkg/apply/processor/scale.go @@ -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 { diff --git a/pkg/checker/host_checker.go b/pkg/checker/host_checker.go index 7b004bca0b3..5d8e9418cc8 100644 --- a/pkg/checker/host_checker.go +++ b/pkg/checker/host_checker.go @@ -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 +}