代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/eggo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From f6758397221920d240d61671cc2759eca65f6899 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Tue, 1 Mar 2022 19:24:40 +0800
Subject: [PATCH 22/24] add golangci check
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
.golangci.yaml | 18 +++++++++++++
Makefile | 6 +++++
cmd/checker.go | 2 +-
cmd/checker_test.go | 10 ++++++--
cmd/cleanup.go | 6 ++++-
cmd/delete.go | 6 ++++-
cmd/deploy.go | 6 ++++-
cmd/eggo.go | 4 ++-
cmd/join.go | 6 ++++-
cmd/opts.go | 2 +-
pkg/clusterdeployment/binary/binary.go | 18 +++++++------
.../binary/bootstrap/bootstrap_test.go | 18 ++++++++++---
.../binary/cleanupcluster/cleanupetcd.go | 4 ++-
.../binary/cleanupcluster/cleanupnode.go | 9 +++++--
.../binary/commontools/token.go | 1 +
.../binary/controlplane/controlplane.go | 4 ++-
.../binary/controlplane/controlplane_test.go | 23 +++++++++++------
.../infrastructure/infrastructure_test.go | 12 ++++++---
pkg/clusterdeployment/clusterdeploy.go | 14 ++++++++---
pkg/utils/endpoint/endpoint.go | 1 +
pkg/utils/nodemanager/nodemanager.go | 12 ++++-----
pkg/utils/nodemanager/nodemanager_test.go | 25 ++++++++++++++-----
22 files changed, 158 insertions(+), 49 deletions(-)
create mode 100644 .golangci.yaml
diff --git a/.golangci.yaml b/.golangci.yaml
new file mode 100644
index 0000000..ea8515f
--- /dev/null
+++ b/.golangci.yaml
@@ -0,0 +1,18 @@
+linters-settings:
+ golint:
+ min-confidence: 0
+ misspell:
+ locale: US
+linters:
+ disable-all: true
+ enable:
+ - typecheck
+ - goimports
+ - misspell
+ - govet
+ - ineffassign
+ - gosimple
+ - deadcode
+ - structcheck
+ - unused
+ - errcheck
\ No newline at end of file
diff --git a/Makefile b/Makefile
index d2c4d9e..e346f97 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,12 @@ test:
@$(GO) test -race -cover -count=1 -timeout=300s ./...
@echo "Units test done!"
+check:
+ @which ${GOPATH}/bin/golangci-lint > /dev/null || (echo "Installing golangci-lint" && go get -d github.com/golangci/golangci-lint/cmd/golangci-lint)
+ @echo "Code check starting..."
+ @${GOPATH}/bin/golangci-lint run --timeout 5m --config=./.golangci.yaml
+ @echo "Code check done!"
+
.PHONY: safe
safe:
@echo "build safe eggo starting..."
diff --git a/cmd/checker.go b/cmd/checker.go
index 07068e9..2f99a0c 100644
--- a/cmd/checker.go
+++ b/cmd/checker.go
@@ -335,7 +335,7 @@ func (ccr *OpenPortResponsibility) Execute() error {
return fmt.Errorf("invalid port: %v for %s", port.Port, name)
}
if _, ok := supportProtocal[port.Protocol]; !ok {
- return fmt.Errorf("invalid protocal: %s for %s", port.Protocol, name)
+ return fmt.Errorf("invalid protocol: %s for %s", port.Protocol, name)
}
}
}
diff --git a/cmd/checker_test.go b/cmd/checker_test.go
index 1fee45a..57babf9 100644
--- a/cmd/checker_test.go
+++ b/cmd/checker_test.go
@@ -27,7 +27,11 @@ func TestRunChecker(t *testing.T) {
if err != nil {
t.Fatalf("create tempdir for cmd checker failed: %v", err)
}
- defer os.RemoveAll(tempdir)
+ defer func() {
+ if terr := os.RemoveAll(tempdir); terr != nil {
+ t.Fatalf("remove temp dir failed: %v", terr)
+ }
+ }()
// init opts
if NewEggoCmd() == nil {
@@ -49,7 +53,9 @@ func TestRunChecker(t *testing.T) {
}
for _, fn := range conf.InstallConfig.PackageSrc.SrcPath {
- os.MkdirAll(fn, 0755)
+ if err := os.MkdirAll(fn, 0755); err != nil {
+ t.Fatalf("mkdir failed: %v", err)
+ }
defer os.RemoveAll(fn)
}
diff --git a/cmd/cleanup.go b/cmd/cleanup.go
index 7a78b15..e55c085 100644
--- a/cmd/cleanup.go
+++ b/cmd/cleanup.go
@@ -70,7 +70,11 @@ func cleanupCluster(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("create process holder failed: %v, mayebe other eggo is running with cluster: %s", err, conf.ClusterID)
}
- defer holder.Remove()
+ defer func() {
+ if terr := holder.Remove(); terr != nil {
+ fmt.Printf("remove process place holder failed: %v", terr)
+ }
+ }()
if err = cleanup(toClusterdeploymentConfig(conf, hooksConf)); err != nil {
return err
diff --git a/cmd/delete.go b/cmd/delete.go
index 5990a42..05a1dee 100644
--- a/cmd/delete.go
+++ b/cmd/delete.go
@@ -106,7 +106,11 @@ func deleteCluster(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("create process holder failed: %v, mayebe other eggo is running with cluster: %s", err, conf.ClusterID)
}
- defer holder.Remove()
+ defer func() {
+ if terr := holder.Remove(); terr != nil {
+ fmt.Printf("remove process place holder failed: %v", terr)
+ }
+ }()
deletedConfig, diffHostconfigs, err := getDeletedAndDiffConfigs(conf, args)
if err != nil {
diff --git a/cmd/deploy.go b/cmd/deploy.go
index 2d7c441..4d7fab4 100644
--- a/cmd/deploy.go
+++ b/cmd/deploy.go
@@ -136,7 +136,11 @@ func deployCluster(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("create process holder failed: %v, mayebe other eggo is running with cluster: %s", err, conf.ClusterID)
}
- defer holder.Remove()
+ defer func() {
+ if terr := holder.Remove(); terr != nil {
+ fmt.Printf("remove process place holder failed: %v", terr)
+ }
+ }()
if err = deploy(conf); err != nil {
return err
diff --git a/cmd/eggo.go b/cmd/eggo.go
index 272fb17..36a3f9e 100644
--- a/cmd/eggo.go
+++ b/cmd/eggo.go
@@ -86,7 +86,9 @@ func NewEggoCmd() *cobra.Command {
showVersion()
return nil
}
- cmd.Help()
+ if err := cmd.Help(); err != nil {
+ return err
+ }
return nil
},
}
diff --git a/cmd/join.go b/cmd/join.go
index d035bfe..d1d49e4 100644
--- a/cmd/join.go
+++ b/cmd/join.go
@@ -228,7 +228,11 @@ func joinCluster(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("create process holder failed: %v, mayebe other eggo is running with cluster: %s", err, conf.ClusterID)
}
- defer holder.Remove()
+ defer func() {
+ if terr := holder.Remove(); terr != nil {
+ logrus.Warnf("remove process place holder failed: %v", terr)
+ }
+ }()
mergedConf, diffConfigs, err := getMergedAndDiffConfigs(conf, joinConf)
if mergedConf == nil || diffConfigs == nil || err != nil {
diff --git a/cmd/opts.go b/cmd/opts.go
index 7bb8297..d0235fe 100644
--- a/cmd/opts.go
+++ b/cmd/opts.go
@@ -89,7 +89,7 @@ func setupJoinCmdOpts(joinCmd *cobra.Command) {
flags.StringVarP(&opts.joinHost.Name, "name", "n", "", "host's name")
flags.IntVarP(&opts.joinHost.Port, "port", "p", 0, "host's ssh port")
flags.StringVarP(&opts.joinClusterID, "id", "", "", "cluster id")
- flags.StringVarP(&opts.joinYaml, "file", "f", "", "yaml file contain nodes infomation")
+ flags.StringVarP(&opts.joinYaml, "file", "f", "", "yaml file contain nodes information")
flags.StringVarP(&opts.prehook, "prehook", "", "", "prehook when join cluster")
flags.StringVarP(&opts.posthook, "posthook", "", "", "posthook when join cluster")
}
diff --git a/pkg/clusterdeployment/binary/binary.go b/pkg/clusterdeployment/binary/binary.go
index 478e081..8bb3c1d 100644
--- a/pkg/clusterdeployment/binary/binary.go
+++ b/pkg/clusterdeployment/binary/binary.go
@@ -56,7 +56,9 @@ func New(conf *api.ClusterConfig) (api.ClusterDeploymentAPI, error) {
connections: make(map[string]runner.Runner),
}
// register and connect all nodes
- bcd.registerNodes()
+ if err := bcd.registerNodes(); err != nil {
+ return nil, err
+ }
return bcd, nil
}
@@ -177,7 +179,7 @@ func (bcp *BinaryClusterDeployment) MachineInfraSetup(hcf *api.HostConfig) error
return nil
}
- logrus.Infof("do setup %s infrastrucure...", hcf.Address)
+ logrus.Infof("do setup %s infrastructure...", hcf.Address)
if err := bcp.registerNode(hcf); err != nil {
logrus.Errorf("register node failed: %v", err)
@@ -196,7 +198,7 @@ func (bcp *BinaryClusterDeployment) MachineInfraSetup(hcf *api.HostConfig) error
}
}
- logrus.Infof("setup %s infrastrucure success", hcf.Address)
+ logrus.Infof("setup %s infrastructure success", hcf.Address)
return nil
}
@@ -206,14 +208,14 @@ func (bcp *BinaryClusterDeployment) MachineInfraDestroy(hcf *api.HostConfig) err
return nil
}
- logrus.Infof("do destroy %s infrastrucure...", hcf.Address)
+ logrus.Infof("do destroy %s infrastructure...", hcf.Address)
err := infrastructure.NodeInfrastructureDestroy(bcp.config, hcf)
if err != nil {
- logrus.Errorf("role %d infrastructure destory failed: %v", hcf.Type, err)
+ logrus.Errorf("role %d infrastructure destroy failed: %v", hcf.Type, err)
}
- logrus.Infof("destroy %s infrastrucure success", hcf.Address)
+ logrus.Infof("destroy %s infrastructure success", hcf.Address)
return nil
}
@@ -404,7 +406,9 @@ func (bcp *BinaryClusterDeployment) LoadBalancerDestroy(lb *api.HostConfig) erro
return nil
}
- cleanupcluster.CleanupLoadBalance(bcp.config, lb)
+ if terr := cleanupcluster.CleanupLoadBalance(bcp.config, lb); terr != nil {
+ logrus.Warnf("clean up loadbalance failed: %v", terr)
+ }
return nil
}
diff --git a/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go b/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
index 9b69035..7b3c1ff 100644
--- a/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
+++ b/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
@@ -99,14 +99,19 @@ func TestJoinMaster(t *testing.T) {
r := &MockRunner{}
for _, node := range conf.Nodes {
- nodemanager.RegisterNode(node, r)
+ if err := nodemanager.RegisterNode(node, r); err != nil {
+ t.Fatalf("register node failed: %v", err)
+ }
}
defer func() {
nodemanager.UnRegisterAllNodes()
}()
api.EggoHomePath = "/tmp/eggo"
- lr.RunCommand(fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki", api.EggoHomePath, conf.Name))
+ if _, err := lr.RunCommand(
+ fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki", api.EggoHomePath, conf.Name)); err != nil {
+ t.Fatalf("run command failed: %v", err)
+ }
if err := JoinMaster(conf, &masterNode); err != nil {
t.Fatalf("do bootstrap init failed: %v", err)
}
@@ -161,14 +166,19 @@ func TestJoinWorker(t *testing.T) {
r := &MockRunner{}
for _, node := range conf.Nodes {
- nodemanager.RegisterNode(node, r)
+ if err := nodemanager.RegisterNode(node, r); err != nil {
+ t.Fatalf("register node failed: %v", err)
+ }
}
defer func() {
nodemanager.UnRegisterAllNodes()
}()
api.EggoHomePath = "/tmp/eggo"
- lr.RunCommand(fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki", api.EggoHomePath, conf.Name))
+ if _, err := lr.RunCommand(
+ fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki", api.EggoHomePath, conf.Name)); err != nil {
+ t.Fatalf("run command failed: %v", err)
+ }
if err := JoinWorker(conf, &controlplane, &workerNode); err != nil {
t.Fatalf("do bootstrap init failed: %v", err)
}
diff --git a/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go b/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
index 164bbe3..59005a7 100644
--- a/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
+++ b/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
@@ -63,7 +63,9 @@ func (t *cleanupEtcdMemberTask) Run(r runner.Runner, hostConfig *api.HostConfig)
return fmt.Errorf("empty host config")
}
- stopServices(r, EtcdService)
+ if err := stopServices(r, EtcdService); err != nil {
+ logrus.Warnf("stop etcd service failed: %v", err)
+ }
removePathes(r, getEtcdPathes(t.ccfg))
diff --git a/pkg/clusterdeployment/binary/cleanupcluster/cleanupnode.go b/pkg/clusterdeployment/binary/cleanupcluster/cleanupnode.go
index 89100d1..296d411 100644
--- a/pkg/clusterdeployment/binary/cleanupcluster/cleanupnode.go
+++ b/pkg/clusterdeployment/binary/cleanupcluster/cleanupnode.go
@@ -167,12 +167,17 @@ func (t *cleanupNodeTask) Run(r runner.Runner, hostConfig *api.HostConfig) error
if err != nil {
logrus.Errorf("get worker services failed")
}
- stopServices(r, services)
+
+ if err := stopServices(r, services); err != nil {
+ logrus.Warnf("stop service failed: %v", err)
+ }
removePathes(r, getWorkerPathes(r, t.ccfg))
}
if utils.IsType(t.delType, api.Master) {
- stopServices(r, MasterService)
+ if err := stopServices(r, MasterService); err != nil {
+ logrus.Warnf("stop master service failed: %v", err)
+ }
removePathes(r, getMasterPathes(t.ccfg))
}
diff --git a/pkg/clusterdeployment/binary/commontools/token.go b/pkg/clusterdeployment/binary/commontools/token.go
index 005efcc..6f85fac 100644
--- a/pkg/clusterdeployment/binary/commontools/token.go
+++ b/pkg/clusterdeployment/binary/commontools/token.go
@@ -25,6 +25,7 @@ import (
"isula.org/eggo/pkg/api"
"isula.org/eggo/pkg/constants"
"isula.org/eggo/pkg/utils/runner"
+
kkutil "github.com/kubesphere/kubekey/pkg/util"
"github.com/lithammer/dedent"
"github.com/sirupsen/logrus"
diff --git a/pkg/clusterdeployment/binary/controlplane/controlplane.go b/pkg/clusterdeployment/binary/controlplane/controlplane.go
index 9c591c4..1f93e5e 100644
--- a/pkg/clusterdeployment/binary/controlplane/controlplane.go
+++ b/pkg/clusterdeployment/binary/controlplane/controlplane.go
@@ -446,7 +446,9 @@ func generateCertsAndKubeConfigs(r runner.Runner, ccfg *api.ClusterConfig, hcf *
defer func() {
if err != nil {
// TODO: dot not delete user configed directory, delete directories and files we addded only
- cg.CleanAll(rootPath)
+ if terr := cg.CleanAll(rootPath); terr != nil {
+ logrus.Warnf("clean certs failed: %v", terr)
+ }
}
}()
diff --git a/pkg/clusterdeployment/binary/controlplane/controlplane_test.go b/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
index 8fb769f..c4e6ab7 100644
--- a/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
+++ b/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
@@ -16,6 +16,7 @@ package controlplane
import (
"fmt"
+ "strings"
"testing"
"github.com/sirupsen/logrus"
@@ -92,7 +93,9 @@ func TestInit(t *testing.T) {
r := &MockRunner{}
var master string
for _, node := range conf.Nodes {
- nodemanager.RegisterNode(node, r)
+ if err := nodemanager.RegisterNode(node, r); err != nil {
+ t.Fatalf("register node failed: %v", err)
+ }
if utils.IsType(node.Type, api.Master) {
master = node.Address
}
@@ -103,15 +106,21 @@ func TestInit(t *testing.T) {
api.EggoHomePath = "/tmp/eggo"
// generate api server etcd client ceritifaces for testing
- lr.RunCommand(fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki/etcd", api.EggoHomePath, conf.Name))
- lr.RunCommand(fmt.Sprintf("sudo chmod -R 0777 %s/%s", api.EggoHomePath, conf.Name))
- lr.RunCommand(fmt.Sprintf("sudo touch %s/%s/pki/apiserver-etcd-client.crt", api.EggoHomePath, conf.Name))
- lr.RunCommand(fmt.Sprintf("sudo touch %s/%s/pki/apiserver-etcd-client.key", api.EggoHomePath, conf.Name))
- lr.RunCommand(fmt.Sprintf("sudo touch %s/%s/pki/etcd/ca.crt", api.EggoHomePath, conf.Name))
+ var sb strings.Builder
+ sb.WriteString(fmt.Sprintf("sudo mkdir -p -m 0777 %s/%s/pki/etcd", api.EggoHomePath, conf.Name))
+ sb.WriteString(fmt.Sprintf("&& sudo chmod -R 0777 %s/%s", api.EggoHomePath, conf.Name))
+ sb.WriteString(fmt.Sprintf("&& sudo touch %s/%s/pki/apiserver-etcd-client.crt", api.EggoHomePath, conf.Name))
+ sb.WriteString(fmt.Sprintf("&& sudo touch %s/%s/pki/apiserver-etcd-client.key", api.EggoHomePath, conf.Name))
+ sb.WriteString(fmt.Sprintf("&& sudo touch %s/%s/pki/etcd/ca.crt", api.EggoHomePath, conf.Name))
+ if _, err := lr.RunCommand(sb.String()); err != nil {
+ t.Fatalf("run command failed: %v", err)
+ }
if err := Init(conf, master); err != nil {
t.Fatalf("do control plane init failed: %v", err)
}
- lr.RunCommand(fmt.Sprintf("sudo rm -rf %s", api.EggoHomePath))
+ if _, err := lr.RunCommand(fmt.Sprintf("sudo rm -rf %s", api.EggoHomePath)); err != nil {
+ t.Fatalf("run command failed: %v", err)
+ }
t.Logf("do control plane init success")
}
diff --git a/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go b/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
index 2835fd9..c9e0946 100644
--- a/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
+++ b/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
@@ -58,11 +58,15 @@ func (m *MockRunner) Close() {
logrus.Infof("close")
}
-func addNodes(hcfs []*api.HostConfig) {
+func addNodes(hcfs []*api.HostConfig) error {
r := &MockRunner{}
for _, hcf := range hcfs {
- nodemanager.RegisterNode(hcf, r)
+ if err := nodemanager.RegisterNode(hcf, r); err != nil {
+ return err
+ }
}
+
+ return nil
}
func TestPrepareInfrastructure(t *testing.T) {
@@ -173,7 +177,9 @@ func TestPrepareInfrastructure(t *testing.T) {
},
}
- addNodes(ccfg.Nodes)
+ if err := addNodes(ccfg.Nodes); err != nil {
+ t.Fatalf("add nodes failed: %v", err)
+ }
if err := NodeInfrastructureSetup(ccfg, ccfg.Nodes[0].Address, ccfg.Nodes[0].Type); err != nil {
t.Fatalf("test NodeInfrastructureSetup failed: %v\n", err)
}
diff --git a/pkg/clusterdeployment/clusterdeploy.go b/pkg/clusterdeployment/clusterdeploy.go
index 138d584..fde1fde 100644
--- a/pkg/clusterdeployment/clusterdeploy.go
+++ b/pkg/clusterdeployment/clusterdeploy.go
@@ -215,9 +215,17 @@ func rollbackFailedNoeds(handler api.ClusterDeploymentAPI, nodes []*api.HostConf
var rollIDs []string
for _, n := range nodes {
// do best to cleanup, if error, just ignore
- handler.ClusterNodeCleanup(n, n.Type)
- handler.MachineInfraDestroy(n)
- handler.CleanupLastStep(n.Name)
+ if terr := handler.ClusterNodeCleanup(n, n.Type); terr != nil {
+ logrus.Warnf("cluster node cleanup failed: %v", terr)
+ }
+
+ if terr := handler.MachineInfraDestroy(n); terr != nil {
+ logrus.Warnf("machine infrastructure destroy failed: %v", terr)
+ }
+
+ if terr := handler.CleanupLastStep(n.Name); terr != nil {
+ logrus.Warnf("cleanup last step failed: %v", terr)
+ }
rollIDs = append(rollIDs, n.Address)
}
diff --git a/pkg/utils/endpoint/endpoint.go b/pkg/utils/endpoint/endpoint.go
index 85d932a..a2b82d3 100644
--- a/pkg/utils/endpoint/endpoint.go
+++ b/pkg/utils/endpoint/endpoint.go
@@ -21,6 +21,7 @@ import (
"strconv"
"isula.org/eggo/pkg/api"
+
"github.com/sirupsen/logrus"
validation "k8s.io/apimachinery/pkg/util/validation"
)
diff --git a/pkg/utils/nodemanager/nodemanager.go b/pkg/utils/nodemanager/nodemanager.go
index 25f7d4e..5fff50e 100644
--- a/pkg/utils/nodemanager/nodemanager.go
+++ b/pkg/utils/nodemanager/nodemanager.go
@@ -125,7 +125,7 @@ func RunTaskOnNodes(t task.Task, nodes []string) error {
logrus.Warnf("node: %s work with too much tasks, will retry it", id)
retryNodes = append(retryNodes, n)
} else {
- return fmt.Errorf("unkown node %s", id)
+ return fmt.Errorf("unknown node %s", id)
}
}
@@ -165,8 +165,8 @@ func RunTasksOnNode(tasks []task.Task, node string) error {
return fmt.Errorf("node: %s work with too much tasks, will retry it", node)
}
} else {
- logrus.Errorf("unkown node %s", node)
- return fmt.Errorf("unkown node %s", node)
+ logrus.Errorf("unknown node %s", node)
+ return fmt.Errorf("unknown node %s", node)
}
}
@@ -191,7 +191,7 @@ func RunTaskOnOneNode(t task.Task, nodes []string) (string, error) {
for _, id := range nodes {
n, ok := manager.nodes[id]
if !ok {
- logrus.Warnf("unkown node %s for task %s", id, t.Name())
+ logrus.Warnf("unknown node %s for task %s", id, t.Name())
continue
}
if n.PushTask(t) {
@@ -206,7 +206,7 @@ func checkNodeFinish(nodeID string) (bool, string, error) {
defer manager.lock.RUnlock()
n, ok := manager.nodes[nodeID]
if !ok {
- return true, fmt.Sprintf("unknow node: %s", nodeID), fmt.Errorf("unkown node %s", nodeID)
+ return true, fmt.Sprintf("unknow node: %s", nodeID), fmt.Errorf("unknown node %s", nodeID)
}
s := n.GetStatus()
if s.TasksFinished() {
@@ -270,7 +270,7 @@ func WaitNodesFinish(nodes []string, timeout time.Duration) error {
for _, id := range nodes {
n, ok := manager.nodes[id]
if !ok {
- return fmt.Errorf("unkown node %s", id)
+ return fmt.Errorf("unknown node %s", id)
}
err := n.WaitNodeTasksFinish(timeout)
if err != nil {
diff --git a/pkg/utils/nodemanager/nodemanager_test.go b/pkg/utils/nodemanager/nodemanager_test.go
index b1b321a..52ad91c 100644
--- a/pkg/utils/nodemanager/nodemanager_test.go
+++ b/pkg/utils/nodemanager/nodemanager_test.go
@@ -74,7 +74,7 @@ func (m *MockTask) Run(r runner.Runner, hcf *api.HostConfig) error {
}
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
- r.Reconnect()
+ err = r.Reconnect()
return err
}
@@ -83,7 +83,7 @@ func (m *MockTask) Name() string {
return m.name
}
-func addNodes() {
+func addNodes() error {
hcf1 := &api.HostConfig{
Arch: "x86_64",
Name: "master",
@@ -103,8 +103,15 @@ func addNodes() {
Type: api.Worker,
}
r := &MockRunner{}
- RegisterNode(hcf1, r)
- RegisterNode(hcf2, r)
+
+ if err := RegisterNode(hcf1, r); err != nil {
+ return err
+ }
+ if err := RegisterNode(hcf2, r); err != nil {
+ return err
+ }
+
+ return nil
}
func releaseNodes(nodes []string) {
@@ -114,7 +121,10 @@ func releaseNodes(nodes []string) {
}
func TestRunTaskOnNodes(t *testing.T) {
- addNodes()
+ if err := addNodes(); err != nil {
+ t.Fatalf("add nodes failed: %v", err)
+ }
+
tt := task.NewTaskInstance(
&MockTask{
name: "precheck",
@@ -146,7 +156,10 @@ func TestRunTaskOnNodes(t *testing.T) {
}
func TestRunTaskOnAll(t *testing.T) {
- addNodes()
+ if err := addNodes(); err != nil {
+ t.Fatalf("add nodes failed: %v", err)
+ }
+
tt := task.NewTaskInstance(
&MockTask{
name: "precheck",
--
2.25.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。