!41 update from openeuler
From: @zh_xiaoyu Reviewed-by: @duguhaotian Signed-off-by: @duguhaotian
This commit is contained in:
commit
52a472507f
846
0018-implement-cmd-hooks.patch
Normal file
846
0018-implement-cmd-hooks.patch
Normal file
@ -0,0 +1,846 @@
|
|||||||
|
From 27a99ca97da9540200068d75152896492ecd0064 Mon Sep 17 00:00:00 2001
|
||||||
|
From: jikui <jikui2@huawei.com>
|
||||||
|
Date: Tue, 14 Dec 2021 16:33:02 +0800
|
||||||
|
Subject: [PATCH 18/24] implement cmd hooks
|
||||||
|
|
||||||
|
---
|
||||||
|
cmd/checker.go | 52 ++++++++++
|
||||||
|
cmd/cleanup.go | 10 +-
|
||||||
|
cmd/configs.go | 125 ++++++++++++++++++++++++-
|
||||||
|
cmd/configs_test.go | 2 +-
|
||||||
|
cmd/delete.go | 12 ++-
|
||||||
|
cmd/deploy.go | 9 +-
|
||||||
|
cmd/join.go | 14 ++-
|
||||||
|
cmd/opts.go | 12 +++
|
||||||
|
docs/hooks_of_eggo.md | 3 +-
|
||||||
|
pkg/api/types.go | 18 ++--
|
||||||
|
pkg/clusterdeployment/binary/binary.go | 25 +++++
|
||||||
|
pkg/constants/constants.go | 5 +
|
||||||
|
pkg/utils/dependency/cmdhooks.go | 115 +++++++++++++++++++++++
|
||||||
|
pkg/utils/dependency/cmdhooks_test.go | 43 +++++++++
|
||||||
|
pkg/utils/runner/runner.go | 4 +-
|
||||||
|
pkg/utils/utils.go | 15 +++
|
||||||
|
16 files changed, 444 insertions(+), 20 deletions(-)
|
||||||
|
create mode 100644 pkg/utils/dependency/cmdhooks.go
|
||||||
|
create mode 100644 pkg/utils/dependency/cmdhooks_test.go
|
||||||
|
|
||||||
|
diff --git a/cmd/checker.go b/cmd/checker.go
|
||||||
|
index 9d1fda6..07068e9 100644
|
||||||
|
--- a/cmd/checker.go
|
||||||
|
+++ b/cmd/checker.go
|
||||||
|
@@ -19,11 +19,15 @@ import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/url"
|
||||||
|
+ "os"
|
||||||
|
+ "path"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
+ "strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isula.org/eggo/pkg/api"
|
||||||
|
+ "isula.org/eggo/pkg/constants"
|
||||||
|
"isula.org/eggo/pkg/utils"
|
||||||
|
"isula.org/eggo/pkg/utils/endpoint"
|
||||||
|
chain "isula.org/eggo/pkg/utils/responsibilitychain"
|
||||||
|
@@ -383,6 +387,54 @@ func checkPackageConfig(pc *PackageConfig) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
+func checkCmdHooksParameter(pa ...string) error {
|
||||||
|
+ for _, v := range pa {
|
||||||
|
+ if v == "" {
|
||||||
|
+ continue
|
||||||
|
+ }
|
||||||
|
+ res := strings.Split(v, ",")
|
||||||
|
+ if len(res) < 1 || len(res) > 2 {
|
||||||
|
+ return fmt.Errorf("invalid hook parameter with:%s\n", v)
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func checkHookFile(fileName string) error {
|
||||||
|
+ file, err := os.Stat(fileName)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return err
|
||||||
|
+
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if !path.IsAbs(fileName) {
|
||||||
|
+ return fmt.Errorf("%s is not Abs path", fileName)
|
||||||
|
+ }
|
||||||
|
+ if !file.Mode().IsRegular() {
|
||||||
|
+ return fmt.Errorf("%s is not regular file", file.Name())
|
||||||
|
+ }
|
||||||
|
+ if file.Mode().Perm() != os.FileMode(constants.HookFileMode) {
|
||||||
|
+ return fmt.Errorf("file mode of %s is incorrect", file.Name())
|
||||||
|
+ }
|
||||||
|
+ if file.Size() > constants.MaxHookFileSize || file.Size() == 0 {
|
||||||
|
+ return fmt.Errorf("%s is too large or small", file.Name())
|
||||||
|
+ }
|
||||||
|
+ if !(strings.HasSuffix(fileName, ".sh") || strings.HasSuffix(fileName, ".bash")) {
|
||||||
|
+ return fmt.Errorf("%s is not shell file", file.Name())
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ user, group, err := utils.GetUserIDAndGroupID(fileName)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return fmt.Errorf("get user ID and group ID with file %s failed", file.Name())
|
||||||
|
+ }
|
||||||
|
+ if user != os.Getuid() && group != os.Getgid() {
|
||||||
|
+ return fmt.Errorf("user id and group id of %s mismatch with process", file.Name())
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
func (ccr *InstallConfigResponsibility) Execute() error {
|
||||||
|
if ccr.conf.PackageSrc != nil {
|
||||||
|
if ccr.conf.PackageSrc.DstPath != "" {
|
||||||
|
diff --git a/cmd/cleanup.go b/cmd/cleanup.go
|
||||||
|
index 37bb87f..7a78b15 100644
|
||||||
|
--- a/cmd/cleanup.go
|
||||||
|
+++ b/cmd/cleanup.go
|
||||||
|
@@ -54,17 +54,25 @@ func cleanupCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
return fmt.Errorf("load deploy config file %v failed: %v", confPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
+ if err = checkCmdHooksParameter(opts.clusterPrehook, opts.clusterPosthook); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
if err = RunChecker(conf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
+ hooksConf, err := getClusterHookConf(api.HookOpCleanup)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return fmt.Errorf("get cmd hooks config failed:%v", err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
holder, err := NewProcessPlaceHolder(eggoPlaceHolderPath(conf.ClusterID))
|
||||||
|
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()
|
||||||
|
|
||||||
|
- if err = cleanup(toClusterdeploymentConfig(conf)); err != nil {
|
||||||
|
+ if err = cleanup(toClusterdeploymentConfig(conf, hooksConf)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/cmd/configs.go b/cmd/configs.go
|
||||||
|
index 326e889..4d7a4b9 100644
|
||||||
|
--- a/cmd/configs.go
|
||||||
|
+++ b/cmd/configs.go
|
||||||
|
@@ -20,6 +20,7 @@ import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
+ "path"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
@@ -559,7 +560,7 @@ func fillExtrArgs(ccfg *api.ClusterConfig, eargs []*ConfigExtraArgs) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-func toClusterdeploymentConfig(conf *DeployConfig) *api.ClusterConfig {
|
||||||
|
+func toClusterdeploymentConfig(conf *DeployConfig, hooks []*api.ClusterHookConf) *api.ClusterConfig {
|
||||||
|
ccfg := getDefaultClusterdeploymentConfig()
|
||||||
|
|
||||||
|
setIfStrConfigNotEmpty(&ccfg.Name, conf.ClusterID)
|
||||||
|
@@ -601,10 +602,132 @@ func toClusterdeploymentConfig(conf *DeployConfig) *api.ClusterConfig {
|
||||||
|
ccfg.WorkerConfig.KubeletConf.EnableServer = conf.EnableKubeletServing
|
||||||
|
|
||||||
|
fillExtrArgs(ccfg, conf.ConfigExtraArgs)
|
||||||
|
+ ccfg.HooksConf = hooks
|
||||||
|
|
||||||
|
return ccfg
|
||||||
|
}
|
||||||
|
|
||||||
|
+func getClusterHookConf(op api.HookOperator) ([]*api.ClusterHookConf, error) {
|
||||||
|
+ var hooks []*api.ClusterHookConf
|
||||||
|
+
|
||||||
|
+ if opts.clusterPrehook != "" {
|
||||||
|
+ hook, err := getCmdHooks(opts.clusterPrehook, api.ClusterPrehookType, op)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ hooks = append(hooks, hook)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if opts.clusterPosthook != "" {
|
||||||
|
+ hook, err := getCmdHooks(opts.clusterPosthook, api.ClusterPosthookType, op)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ hooks = append(hooks, hook)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if opts.prehook != "" {
|
||||||
|
+ hook, err := getCmdHooks(opts.prehook, api.PreHookType, op)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ hooks = append(hooks, hook)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if opts.posthook != "" {
|
||||||
|
+ hook, err := getCmdHooks(opts.posthook, api.PostHookType, op)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ hooks = append(hooks, hook)
|
||||||
|
+ }
|
||||||
|
+ return hooks, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func getCmdHooks(hopts string, ty api.HookType, op api.HookOperator) (*api.ClusterHookConf, error) {
|
||||||
|
+ path, target, err := getHookPathAndTarget(hopts)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ hook, err := getResolvedHook(path, ty, op, target)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+ return hook, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func getHookPathAndTarget(hook string) (string, uint16, error) {
|
||||||
|
+ pathAndTarget := strings.Split(hook, ",")
|
||||||
|
+ if len(pathAndTarget) == 1 {
|
||||||
|
+ pathAndTarget = append(pathAndTarget, "master")
|
||||||
|
+ }
|
||||||
|
+ target, ok := toTypeInt[pathAndTarget[1]]
|
||||||
|
+ if !ok {
|
||||||
|
+ return "", 0x0, fmt.Errorf("invalid role:%s", pathAndTarget[1])
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return pathAndTarget[0], target, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func getResolvedHook(path string, ty api.HookType, op api.HookOperator, target uint16) (*api.ClusterHookConf, error) {
|
||||||
|
+
|
||||||
|
+ dir, shells, err := getDirAndShells(path)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return nil, err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return &api.ClusterHookConf{
|
||||||
|
+ Type: ty,
|
||||||
|
+ Operator: op,
|
||||||
|
+ Target: target,
|
||||||
|
+ HookSrcDir: dir,
|
||||||
|
+ HookFiles: shells,
|
||||||
|
+ }, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func getDirAndShells(path string) (string, []string, error) {
|
||||||
|
+ file, err := os.Stat(path)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return "", nil, err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if !file.IsDir() {
|
||||||
|
+ return resolveFile(path)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return resolvePath(path)
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func resolveFile(p string) (string, []string, error) {
|
||||||
|
+ dir := path.Dir(p)
|
||||||
|
+ fileName := path.Base(p)
|
||||||
|
+ if err := checkHookFile(p); err != nil {
|
||||||
|
+ return "", nil, err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return dir, []string{fileName}, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func resolvePath(p string) (string, []string, error) {
|
||||||
|
+ var files []string
|
||||||
|
+ rd, err := ioutil.ReadDir(p)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return "", nil, err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for _, fi := range rd {
|
||||||
|
+ if err := checkHookFile(path.Join(p, fi.Name())); err == nil {
|
||||||
|
+ files = append(files, fi.Name())
|
||||||
|
+ } else {
|
||||||
|
+ logrus.Debugf("check hook file failed:%v", err)
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if len(files) == 0 {
|
||||||
|
+ return "", nil, fmt.Errorf("empty folder:%s", p)
|
||||||
|
+ }
|
||||||
|
+ return p, files, nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
func getHostconfigs(format string, ips []string) []*HostConfig {
|
||||||
|
var confs []*HostConfig
|
||||||
|
for i, ip := range ips {
|
||||||
|
diff --git a/cmd/configs_test.go b/cmd/configs_test.go
|
||||||
|
index 46cb163..04afc51 100644
|
||||||
|
--- a/cmd/configs_test.go
|
||||||
|
+++ b/cmd/configs_test.go
|
||||||
|
@@ -44,7 +44,7 @@ func TestCmdConfigs(t *testing.T) {
|
||||||
|
t.Fatalf("load deploy config file failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
- ccfg := toClusterdeploymentConfig(conf)
|
||||||
|
+ ccfg := toClusterdeploymentConfig(conf, nil)
|
||||||
|
d, err := yaml.Marshal(ccfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("marshal cluster config failed: %v", err)
|
||||||
|
diff --git a/cmd/delete.go b/cmd/delete.go
|
||||||
|
index 9d911a9..5990a42 100644
|
||||||
|
--- a/cmd/delete.go
|
||||||
|
+++ b/cmd/delete.go
|
||||||
|
@@ -63,7 +63,7 @@ func getDeletedAndDiffConfigs(conf *DeployConfig, delNames []string) (*DeployCon
|
||||||
|
return nil, nil, fmt.Errorf("forbidden to delete first master")
|
||||||
|
}
|
||||||
|
|
||||||
|
- clusterConfig := toClusterdeploymentConfig(&diffConfig)
|
||||||
|
+ clusterConfig := toClusterdeploymentConfig(&diffConfig, nil)
|
||||||
|
if len(clusterConfig.Nodes) == 0 {
|
||||||
|
return nil, nil, fmt.Errorf("no valid ip or name found")
|
||||||
|
}
|
||||||
|
@@ -89,11 +89,19 @@ func deleteCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
return fmt.Errorf("load saved deploy config failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
+ if err := checkCmdHooksParameter(opts.prehook, opts.posthook); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
// check saved deploy config
|
||||||
|
if err = RunChecker(conf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
+ hooksConf, err := getClusterHookConf(api.HookOpDelete)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return fmt.Errorf("get cmd hooks config failed:%v", err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
holder, err := NewProcessPlaceHolder(eggoPlaceHolderPath(conf.ClusterID))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create process holder failed: %v, mayebe other eggo is running with cluster: %s", err, conf.ClusterID)
|
||||||
|
@@ -110,7 +118,7 @@ func deleteCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
- if err = clusterdeployment.DeleteNodes(toClusterdeploymentConfig(conf), diffHostconfigs); err != nil {
|
||||||
|
+ if err = clusterdeployment.DeleteNodes(toClusterdeploymentConfig(conf, hooksConf), diffHostconfigs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/cmd/deploy.go b/cmd/deploy.go
|
||||||
|
index e21bcc5..2d7c441 100644
|
||||||
|
--- a/cmd/deploy.go
|
||||||
|
+++ b/cmd/deploy.go
|
||||||
|
@@ -71,7 +71,11 @@ func deploy(conf *DeployConfig) error {
|
||||||
|
return fmt.Errorf("save deploy config failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
- ccfg := toClusterdeploymentConfig(conf)
|
||||||
|
+ hooksConf, err := getClusterHookConf(api.HookOpDeploy)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return fmt.Errorf("get cmd hooks config failed:%v", err)
|
||||||
|
+ }
|
||||||
|
+ ccfg := toClusterdeploymentConfig(conf, hooksConf)
|
||||||
|
|
||||||
|
cstatus, err := clusterdeployment.CreateCluster(ccfg, opts.deployEnableRollback)
|
||||||
|
if err != nil {
|
||||||
|
@@ -116,6 +120,9 @@ func deployCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
return fmt.Errorf("load deploy config file failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
+ if err = checkCmdHooksParameter(opts.clusterPrehook, opts.clusterPosthook); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
if err = RunChecker(conf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
diff --git a/cmd/join.go b/cmd/join.go
|
||||||
|
index 79d68fc..d035bfe 100644
|
||||||
|
--- a/cmd/join.go
|
||||||
|
+++ b/cmd/join.go
|
||||||
|
@@ -128,7 +128,7 @@ func getMergedAndDiffConfigs(conf *DeployConfig, joinConf *DeployConfig) (*Deplo
|
||||||
|
diffConfig.Workers = append(diffConfig.Workers, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
- return &mergedConfig, toClusterdeploymentConfig(&diffConfig).Nodes, nil
|
||||||
|
+ return &mergedConfig, toClusterdeploymentConfig(&diffConfig, nil).Nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFailedConfigs(diffConfigs []*api.HostConfig, cstatus api.ClusterStatus) []*api.HostConfig {
|
||||||
|
@@ -206,6 +206,9 @@ func joinCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
+ if err = checkCmdHooksParameter(opts.prehook, opts.posthook); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
joinConf, err := parseJoinInput(opts.joinYaml, &opts.joinHost, opts.joinType, opts.joinClusterID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
@@ -237,11 +240,16 @@ func joinCluster(cmd *cobra.Command, args []string) error {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
- cstatus, err := clusterdeployment.JoinNodes(toClusterdeploymentConfig(conf), diffConfigs)
|
||||||
|
+ hooksConf, err := getClusterHookConf(api.HookOpJoin)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return fmt.Errorf("get cmd hooks config failed:%v", err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ cstatus, err := clusterdeployment.JoinNodes(toClusterdeploymentConfig(conf, hooksConf), diffConfigs)
|
||||||
|
if err != nil {
|
||||||
|
failedConfigs := getFailedConfigs(diffConfigs, cstatus)
|
||||||
|
// rollback
|
||||||
|
- if err1 := clusterdeployment.DeleteNodes(toClusterdeploymentConfig(mergedConf), failedConfigs); err1 != nil {
|
||||||
|
+ if err1 := clusterdeployment.DeleteNodes(toClusterdeploymentConfig(mergedConf, nil), failedConfigs); err1 != nil {
|
||||||
|
logrus.Errorf("delete nodes failed when join failed: %v", err1)
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/cmd/opts.go b/cmd/opts.go
|
||||||
|
index f5204f2..7bb8297 100644
|
||||||
|
--- a/cmd/opts.go
|
||||||
|
+++ b/cmd/opts.go
|
||||||
|
@@ -43,6 +43,10 @@ type eggoOptions struct {
|
||||||
|
joinYaml string
|
||||||
|
joinHost HostConfig
|
||||||
|
delClusterID string
|
||||||
|
+ clusterPrehook string
|
||||||
|
+ clusterPosthook string
|
||||||
|
+ prehook string
|
||||||
|
+ posthook string
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts eggoOptions
|
||||||
|
@@ -66,12 +70,16 @@ func setupDeployCmdOpts(deployCmd *cobra.Command) {
|
||||||
|
flags := deployCmd.Flags()
|
||||||
|
flags.StringVarP(&opts.deployConfig, "file", "f", defaultDeployConfigPath(), "location of cluster deploy config file, default $HOME/.eggo/deploy.yaml")
|
||||||
|
flags.BoolVarP(&opts.deployEnableRollback, "rollback", "", true, "rollback failed node to cleanup")
|
||||||
|
+ flags.StringVarP(&opts.clusterPrehook, "cluster-prehook", "", "", "cluser prehooks when deploy cluser")
|
||||||
|
+ flags.StringVarP(&opts.clusterPosthook, "cluster-posthook", "", "", "cluster posthook when deploy cluster")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupCleanupCmdOpts(cleanupCmd *cobra.Command) {
|
||||||
|
flags := cleanupCmd.Flags()
|
||||||
|
flags.StringVarP(&opts.cleanupConfig, "file", "f", "", "location of cluster deploy config file")
|
||||||
|
flags.StringVarP(&opts.cleanupClusterID, "id", "", "", "cluster id")
|
||||||
|
+ flags.StringVarP(&opts.clusterPrehook, "cluster-prehook", "", "", "cluser prehooks when clenaup cluser")
|
||||||
|
+ flags.StringVarP(&opts.clusterPosthook, "cluster-posthook", "", "", "cluster posthook when cleaup cluster")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupJoinCmdOpts(joinCmd *cobra.Command) {
|
||||||
|
@@ -82,11 +90,15 @@ func setupJoinCmdOpts(joinCmd *cobra.Command) {
|
||||||
|
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.prehook, "prehook", "", "", "prehook when join cluster")
|
||||||
|
+ flags.StringVarP(&opts.posthook, "posthook", "", "", "posthook when join cluster")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupDeleteCmdOpts(deleteCmd *cobra.Command) {
|
||||||
|
flags := deleteCmd.Flags()
|
||||||
|
flags.StringVarP(&opts.delClusterID, "id", "", "", "cluster id")
|
||||||
|
+ flags.StringVarP(&opts.prehook, "prehook", "", "", "prehook when delete cluster")
|
||||||
|
+ flags.StringVarP(&opts.posthook, "posthook", "", "", "posthook when delete cluster")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupTemplateCmdOpts(templateCmd *cobra.Command) {
|
||||||
|
diff --git a/docs/hooks_of_eggo.md b/docs/hooks_of_eggo.md
|
||||||
|
index b1f09cb..fd9ce35 100644
|
||||||
|
--- a/docs/hooks_of_eggo.md
|
||||||
|
+++ b/docs/hooks_of_eggo.md
|
||||||
|
@@ -21,8 +21,9 @@
|
||||||
|
说明:
|
||||||
|
|
||||||
|
- 脚本目录下的所有脚本都会被执行,而子目录中的脚本不会被执行;
|
||||||
|
-- 每个脚本的超时时间为60s;
|
||||||
|
+- 每个脚本的超时时间为120s;
|
||||||
|
- role可以为master,worker,etcd或者loadbalance;
|
||||||
|
+- 命令行参数指定的hooks脚本默认拷贝到目标机器的/root/.eggo/package/file/cmdhooks目录下,脚本大小限制1M字节;
|
||||||
|
|
||||||
|
### 配置文件参数方式
|
||||||
|
|
||||||
|
diff --git a/pkg/api/types.go b/pkg/api/types.go
|
||||||
|
index e5e1958..5cb7121 100644
|
||||||
|
--- a/pkg/api/types.go
|
||||||
|
+++ b/pkg/api/types.go
|
||||||
|
@@ -47,8 +47,10 @@ const (
|
||||||
|
type HookType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
- PreHookType HookType = "prehook"
|
||||||
|
- PostHookType HookType = "posthook"
|
||||||
|
+ ClusterPrehookType HookType = "cluster-prehook"
|
||||||
|
+ ClusterPosthookType HookType = "cluster-posthook"
|
||||||
|
+ PreHookType HookType = "prehook"
|
||||||
|
+ PostHookType HookType = "posthook"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HookRunConfig struct {
|
||||||
|
@@ -233,11 +235,11 @@ type AddonConfig struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClusterHookConf struct {
|
||||||
|
- Type HookType
|
||||||
|
- Operator HookOperator
|
||||||
|
- Target uint16
|
||||||
|
- HookDir string
|
||||||
|
- HookFiles []string
|
||||||
|
+ Type HookType
|
||||||
|
+ Operator HookOperator
|
||||||
|
+ Target uint16
|
||||||
|
+ HookSrcDir string
|
||||||
|
+ HookFiles []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClusterConfig struct {
|
||||||
|
@@ -258,7 +260,7 @@ type ClusterConfig struct {
|
||||||
|
RoleInfra map[uint16]*RoleInfra `json:"role-infra"`
|
||||||
|
|
||||||
|
// do not encode hooks, just set before use it
|
||||||
|
- HooksConf *ClusterHookConf `json:"-"`
|
||||||
|
+ HooksConf []*ClusterHookConf `json:"-"`
|
||||||
|
|
||||||
|
// TODO: add other configurations at here
|
||||||
|
}
|
||||||
|
diff --git a/pkg/clusterdeployment/binary/binary.go b/pkg/clusterdeployment/binary/binary.go
|
||||||
|
index 363de0e..478e081 100644
|
||||||
|
--- a/pkg/clusterdeployment/binary/binary.go
|
||||||
|
+++ b/pkg/clusterdeployment/binary/binary.go
|
||||||
|
@@ -419,6 +419,10 @@ func (bcp *BinaryClusterDeployment) Finish() {
|
||||||
|
|
||||||
|
func (bcp *BinaryClusterDeployment) PreCreateClusterHooks() error {
|
||||||
|
role := []uint16{api.LoadBalance, api.ETCD, api.Master, api.Worker}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, bcp.config.Nodes, api.HookOpDeploy, api.ClusterPrehookType); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
if err := dependency.HookSchedule(bcp.config, bcp.config.Nodes, role, api.SchedulePreJoin); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@@ -434,11 +438,17 @@ func (bcp *BinaryClusterDeployment) PostCreateClusterHooks(nodes []*api.HostConf
|
||||||
|
if err := checkK8sServices(nodes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, bcp.config.Nodes, api.HookOpDeploy, api.ClusterPosthookType); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcp *BinaryClusterDeployment) PreDeleteClusterHooks() {
|
||||||
|
role := []uint16{api.Worker, api.Master, api.ETCD, api.LoadBalance}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, bcp.config.Nodes, api.HookOpCleanup, api.ClusterPrehookType); err != nil {
|
||||||
|
+ logrus.Warnf("Ignore: Delete cluster prehook failed:%v", err)
|
||||||
|
+ }
|
||||||
|
if err := dependency.HookSchedule(bcp.config, bcp.config.Nodes, role, api.SchedulePreCleanup); err != nil {
|
||||||
|
logrus.Warnf("Ignore: Delete cluster PreHook failed: %v", err)
|
||||||
|
}
|
||||||
|
@@ -449,10 +459,16 @@ func (bcp *BinaryClusterDeployment) PostDeleteClusterHooks() {
|
||||||
|
if err := dependency.HookSchedule(bcp.config, bcp.config.Nodes, role, api.SchedulePostCleanup); err != nil {
|
||||||
|
logrus.Warnf("Ignore: Delete cluster PostHook failed: %v", err)
|
||||||
|
}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, bcp.config.Nodes, api.HookOpCleanup, api.ClusterPosthookType); err != nil {
|
||||||
|
+ logrus.Warnf("Ignore: Delete cluster posthook failed:%v", err)
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcp *BinaryClusterDeployment) PreNodeJoinHooks(node *api.HostConfig) error {
|
||||||
|
role := []uint16{api.Master, api.Worker, api.ETCD}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, []*api.HostConfig{node}, api.HookOpJoin, api.PreHookType); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
if err := dependency.HookSchedule(bcp.config, []*api.HostConfig{node}, role, api.SchedulePreJoin); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@@ -525,6 +541,9 @@ func (bcp *BinaryClusterDeployment) PostNodeJoinHooks(node *api.HostConfig) erro
|
||||||
|
if err := dependency.HookSchedule(bcp.config, []*api.HostConfig{node}, role, api.SchedulePostJoin); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, []*api.HostConfig{node}, api.HookOpJoin, api.PostHookType); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
|
||||||
|
// taint and label for master node
|
||||||
|
roles := node.Type
|
||||||
|
@@ -552,6 +571,9 @@ func (bcp *BinaryClusterDeployment) PostNodeJoinHooks(node *api.HostConfig) erro
|
||||||
|
|
||||||
|
func (bcp *BinaryClusterDeployment) PreNodeCleanupHooks(node *api.HostConfig) {
|
||||||
|
role := []uint16{api.Worker, api.Master, api.ETCD}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, []*api.HostConfig{node}, api.HookOpDelete, api.PreHookType); err != nil {
|
||||||
|
+ logrus.Warnf("Ignore: Delete Node Cmd Prehook failed: %v", err)
|
||||||
|
+ }
|
||||||
|
if err := dependency.HookSchedule(bcp.config, []*api.HostConfig{node}, role, api.SchedulePreCleanup); err != nil {
|
||||||
|
logrus.Warnf("Ignore: Delete Node PreHook failed: %v", err)
|
||||||
|
}
|
||||||
|
@@ -562,6 +584,9 @@ func (bcp *BinaryClusterDeployment) PostNodeCleanupHooks(node *api.HostConfig) {
|
||||||
|
if err := dependency.HookSchedule(bcp.config, []*api.HostConfig{node}, role, api.SchedulePostCleanup); err != nil {
|
||||||
|
logrus.Warnf("Ignore: Delete Node PostHook failed: %v", err)
|
||||||
|
}
|
||||||
|
+ if err := dependency.ExecuteCmdHooks(bcp.config, []*api.HostConfig{node}, api.HookOpDelete, api.PostHookType); err != nil {
|
||||||
|
+ logrus.Warnf("Ignore: Delete Node Cmd Posthook failed: %v", err)
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bcp *BinaryClusterDeployment) CleanupLastStep(nodeName string) error {
|
||||||
|
diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go
|
||||||
|
index ee02e24..c60d061 100644
|
||||||
|
--- a/pkg/constants/constants.go
|
||||||
|
+++ b/pkg/constants/constants.go
|
||||||
|
@@ -17,6 +17,7 @@ const (
|
||||||
|
DefaultPkgPath = "/pkg"
|
||||||
|
DefaultBinPath = "/bin"
|
||||||
|
DefaultFilePath = "/file"
|
||||||
|
+ DefaultHookPath = "/file/cmdhook"
|
||||||
|
DefaultDirPath = "/dir"
|
||||||
|
DefaultImagePath = "/image"
|
||||||
|
|
||||||
|
@@ -27,4 +28,8 @@ const (
|
||||||
|
|
||||||
|
// network plugin arguments key
|
||||||
|
NetworkPluginArgKeyYamlPath = "NetworkYamlPath"
|
||||||
|
+
|
||||||
|
+ MaxHookFileSize = int64(1 << 20)
|
||||||
|
+ // 750: rwxr-x---
|
||||||
|
+ HookFileMode = uint32(0750)
|
||||||
|
)
|
||||||
|
diff --git a/pkg/utils/dependency/cmdhooks.go b/pkg/utils/dependency/cmdhooks.go
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..e6fd9af
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/pkg/utils/dependency/cmdhooks.go
|
||||||
|
@@ -0,0 +1,115 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
|
||||||
|
+ * eggo licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: jikui
|
||||||
|
+ * Create: 2021-12-11
|
||||||
|
+ * Description: eggo cmd hooks implement
|
||||||
|
+ ******************************************************************************/
|
||||||
|
+
|
||||||
|
+package dependency
|
||||||
|
+
|
||||||
|
+import (
|
||||||
|
+ "fmt"
|
||||||
|
+ "path"
|
||||||
|
+
|
||||||
|
+ "github.com/sirupsen/logrus"
|
||||||
|
+ "isula.org/eggo/pkg/api"
|
||||||
|
+ "isula.org/eggo/pkg/constants"
|
||||||
|
+ "isula.org/eggo/pkg/utils"
|
||||||
|
+ "isula.org/eggo/pkg/utils/nodemanager"
|
||||||
|
+ "isula.org/eggo/pkg/utils/runner"
|
||||||
|
+ "isula.org/eggo/pkg/utils/task"
|
||||||
|
+)
|
||||||
|
+
|
||||||
|
+type CopyHooksTask struct {
|
||||||
|
+ hooks *api.ClusterHookConf
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func (ch *CopyHooksTask) Name() string {
|
||||||
|
+ return "CopyHooksTask"
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func (ch *CopyHooksTask) Run(r runner.Runner, hcg *api.HostConfig) error {
|
||||||
|
+ dstDir := path.Join(constants.DefaultPackagePath, constants.DefaultHookPath)
|
||||||
|
+
|
||||||
|
+ if _, err := r.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"test -d %s || mkdir -p %s\"", dstDir, dstDir)); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if err := r.Copy(ch.hooks.HookSrcDir, dstDir); err != nil {
|
||||||
|
+ return fmt.Errorf("copy from %s to %s for %s failed:%v", ch.hooks.HookSrcDir, dstDir, hcg.Address, err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func ExecuteCmdHooks(ccfg *api.ClusterConfig, nodes []*api.HostConfig, op api.HookOperator, ty api.HookType) error {
|
||||||
|
+ for _, hooks := range ccfg.HooksConf {
|
||||||
|
+ for _, node := range nodes {
|
||||||
|
+ if !utils.IsType(node.Type, hooks.Target) {
|
||||||
|
+ continue
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ shell := getCmdShell(hooks, hooks.Target, op, ty)
|
||||||
|
+ if shell == nil {
|
||||||
|
+ return nil
|
||||||
|
+ }
|
||||||
|
+ if err := doCopyHooks(hooks, node); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
+ if err := executeCmdHooks(ccfg, hooks, node, shell); err != nil {
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return nil
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func executeCmdHooks(ccfg *api.ClusterConfig, hooks *api.ClusterHookConf, hcf *api.HostConfig, shell []*api.PackageConfig) error {
|
||||||
|
+ hookConf := &api.HookRunConfig{
|
||||||
|
+ ClusterID: ccfg.Name,
|
||||||
|
+ ClusterApiEndpoint: ccfg.APIEndpoint.GetUrl(),
|
||||||
|
+ ClusterConfigDir: ccfg.ConfigDir,
|
||||||
|
+ HookType: hooks.Type,
|
||||||
|
+ Operator: hooks.Operator,
|
||||||
|
+ Node: hcf,
|
||||||
|
+ HookDir: path.Join(ccfg.PackageSrc.GetPkgDstPath(), constants.DefaultHookPath),
|
||||||
|
+ Hooks: shell,
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return ExecuteHooks(hookConf)
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func getCmdShell(hooks *api.ClusterHookConf, target uint16, op api.HookOperator, ty api.HookType) []*api.PackageConfig {
|
||||||
|
+ res := make([]*api.PackageConfig, len(hooks.HookFiles))
|
||||||
|
+
|
||||||
|
+ if hooks.Target != target || hooks.Operator != op || hooks.Type != ty {
|
||||||
|
+ return nil
|
||||||
|
+ }
|
||||||
|
+ for i, v := range hooks.HookFiles {
|
||||||
|
+ res[i] = &api.PackageConfig{
|
||||||
|
+ Name: v,
|
||||||
|
+ TimeOut: "120s",
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return res
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func doCopyHooks(hcc *api.ClusterHookConf, node *api.HostConfig) error {
|
||||||
|
+ copyHooksTask := task.NewTaskInstance(&CopyHooksTask{
|
||||||
|
+ hooks: hcc,
|
||||||
|
+ })
|
||||||
|
+
|
||||||
|
+ if err := nodemanager.RunTaskOnNodes(copyHooksTask, []string{node.Address}); err != nil {
|
||||||
|
+ logrus.Errorf("Copy hooks failed with:%v", err)
|
||||||
|
+ return err
|
||||||
|
+ }
|
||||||
|
+ return nil
|
||||||
|
+}
|
||||||
|
diff --git a/pkg/utils/dependency/cmdhooks_test.go b/pkg/utils/dependency/cmdhooks_test.go
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..106518a
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/pkg/utils/dependency/cmdhooks_test.go
|
||||||
|
@@ -0,0 +1,43 @@
|
||||||
|
+package dependency
|
||||||
|
+
|
||||||
|
+import (
|
||||||
|
+ "testing"
|
||||||
|
+
|
||||||
|
+ "isula.org/eggo/pkg/api"
|
||||||
|
+)
|
||||||
|
+
|
||||||
|
+func TestCopyHooks(t *testing.T) {
|
||||||
|
+ var mr MockRunner
|
||||||
|
+
|
||||||
|
+ hs := &api.ClusterHookConf{
|
||||||
|
+ Type: api.PreHookType,
|
||||||
|
+ Operator: api.HookOpDeploy,
|
||||||
|
+ Target: api.Master,
|
||||||
|
+ HookSrcDir: "/tmp",
|
||||||
|
+ HookFiles: []string{"test.sh", "test2.bash"},
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ node := &api.HostConfig{}
|
||||||
|
+
|
||||||
|
+ ct := &CopyHooksTask{hooks: hs}
|
||||||
|
+ if err := ct.Run(&mr, node); err != nil {
|
||||||
|
+ t.Fatalf("run test failed: %v", err)
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func TestExecuteCmdHooks(t *testing.T) {
|
||||||
|
+ hooks := &api.ClusterHookConf{
|
||||||
|
+ Target: api.Master,
|
||||||
|
+ Operator: api.HookOpDeploy,
|
||||||
|
+ Type: api.PreHookType,
|
||||||
|
+ }
|
||||||
|
+ host := &api.HostConfig{
|
||||||
|
+ Type: api.Master,
|
||||||
|
+ }
|
||||||
|
+ ccfg := &api.ClusterConfig{
|
||||||
|
+ HooksConf: []*api.ClusterHookConf{hooks},
|
||||||
|
+ }
|
||||||
|
+ if err := ExecuteCmdHooks(ccfg, []*api.HostConfig{host}, api.HookOpJoin, api.PostHookType); err != nil {
|
||||||
|
+ t.Fatalf("run test failed: %v", err)
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/pkg/utils/runner/runner.go b/pkg/utils/runner/runner.go
|
||||||
|
index 9a739ca..09c9e1d 100644
|
||||||
|
--- a/pkg/utils/runner/runner.go
|
||||||
|
+++ b/pkg/utils/runner/runner.go
|
||||||
|
@@ -227,7 +227,7 @@ func (ssh *SSHRunner) copyDir(srcDir, dstDir string) error {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tmpCpyDir := api.GetUserTempDir(ssh.Host.User)
|
||||||
|
- tmpPkiFile := filepath.Join(tmpCpyDir, "pkg.tar")
|
||||||
|
+ tmpPkiFile := filepath.Join(tmpCpyDir, "remote-pkg.tar")
|
||||||
|
// scp to user home directory
|
||||||
|
err = ssh.Copy(tmpPkgFile, tmpPkiFile)
|
||||||
|
if err != nil {
|
||||||
|
@@ -235,7 +235,7 @@ func (ssh *SSHRunner) copyDir(srcDir, dstDir string) error {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// untar tmp file
|
||||||
|
- _, err = ssh.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && mv %s . && tar -xf %s && rm -rf %s\"", dstDir, tmpPkiFile, "pki.tar", tmpPkiFile))
|
||||||
|
+ _, err = ssh.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && mv %s . && tar -xf %s && rm -rf %s\"", dstDir, tmpPkiFile, "remote-pkg.tar", "remote-pkg.tar"))
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("[%s] untar tmp tar failed: %v", ssh.Host.Name, err)
|
||||||
|
return err
|
||||||
|
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
|
||||||
|
index 8272439..059516c 100644
|
||||||
|
--- a/pkg/utils/utils.go
|
||||||
|
+++ b/pkg/utils/utils.go
|
||||||
|
@@ -16,10 +16,12 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
+ "fmt"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
+ "syscall"
|
||||||
|
|
||||||
|
"isula.org/eggo/pkg/api"
|
||||||
|
)
|
||||||
|
@@ -107,3 +109,16 @@ func IsDocker(engine string) bool {
|
||||||
|
func IsContainerd(engine string) bool {
|
||||||
|
return strings.ToLower(engine) == "containerd"
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+func GetUserIDAndGroupID(file string) (int, int, error) {
|
||||||
|
+ fileInfo, err := os.Stat(file)
|
||||||
|
+ if err != nil {
|
||||||
|
+ return 0, 0, err
|
||||||
|
+ }
|
||||||
|
+ statInfo, ok := fileInfo.Sys().(*syscall.Stat_t)
|
||||||
|
+ if !ok {
|
||||||
|
+ return 0, 0, fmt.Errorf("Assert failed when stat %s", file)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return int(statInfo.Uid), int(statInfo.Gid), nil
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.25.1
|
||||||
|
|
||||||
5130
0019-add-design-of-eggoadm.patch
Normal file
5130
0019-add-design-of-eggoadm.patch
Normal file
File diff suppressed because it is too large
Load Diff
115
0020-add-digitalSignature-for-certificates.patch
Normal file
115
0020-add-digitalSignature-for-certificates.patch
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
From 8e1e06e2e4794c85c19d4ee9a528b6b2d35d9624 Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
Date: Tue, 18 Jan 2022 16:56:42 +0800
|
||||||
|
Subject: [PATCH 20/24] add digitalSignature for certificates
|
||||||
|
|
||||||
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
---
|
||||||
|
pkg/utils/certs/approvecsr.go | 10 ++++++----
|
||||||
|
pkg/utils/certs/localcerts.go | 2 +-
|
||||||
|
pkg/utils/template/template.go | 2 +-
|
||||||
|
pkg/utils/template/template_test.go | 6 +++---
|
||||||
|
4 files changed, 11 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/pkg/utils/certs/approvecsr.go b/pkg/utils/certs/approvecsr.go
|
||||||
|
index 92af905..dfebbee 100644
|
||||||
|
--- a/pkg/utils/certs/approvecsr.go
|
||||||
|
+++ b/pkg/utils/certs/approvecsr.go
|
||||||
|
@@ -69,7 +69,7 @@ func (cv1 *CertificateV1) check(csr certificatesv1.CertificateSigningRequest, wo
|
||||||
|
|
||||||
|
// 3. check csr is requested for serving certificates
|
||||||
|
// usageRequired: "server auth"
|
||||||
|
- // usagesOptional: "digital signature", "key encipherment"
|
||||||
|
+ // usagesOptional: "digital signature", "key encipherment", "data encipherment"
|
||||||
|
required := false
|
||||||
|
for _, u := range csr.Spec.Usages {
|
||||||
|
if u == certificatesv1.UsageServerAuth {
|
||||||
|
@@ -77,7 +77,8 @@ func (cv1 *CertificateV1) check(csr certificatesv1.CertificateSigningRequest, wo
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
- if u != certificatesv1.UsageDigitalSignature && u != certificatesv1.UsageKeyEncipherment {
|
||||||
|
+ if u != certificatesv1.UsageDigitalSignature && u != certificatesv1.UsageKeyEncipherment &&
|
||||||
|
+ u != certificatesv1.UsageDataEncipherment {
|
||||||
|
logrus.Warnf("csr %s is not requested for serving certificates", csr.Name)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@@ -166,7 +167,7 @@ func (cv1beta1 *CertificateV1beta1) check(csr certificatesv1beta1.CertificateSig
|
||||||
|
|
||||||
|
// 3. check csr is requested for serving certificates
|
||||||
|
// usageRequired: "server auth"
|
||||||
|
- // usagesOptional: "digital signature", "key encipherment"
|
||||||
|
+ // usagesOptional: "digital signature", "key encipherment", "data encipherment"
|
||||||
|
required := false
|
||||||
|
for _, u := range csr.Spec.Usages {
|
||||||
|
if u == certificatesv1beta1.UsageServerAuth {
|
||||||
|
@@ -174,7 +175,8 @@ func (cv1beta1 *CertificateV1beta1) check(csr certificatesv1beta1.CertificateSig
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
- if u != certificatesv1beta1.UsageDigitalSignature && u != certificatesv1beta1.UsageKeyEncipherment {
|
||||||
|
+ if u != certificatesv1beta1.UsageDigitalSignature && u != certificatesv1beta1.UsageKeyEncipherment &&
|
||||||
|
+ u != certificatesv1beta1.UsageDataEncipherment {
|
||||||
|
logrus.Warnf("csr %s is not requested for serving certificates", csr.Name)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
diff --git a/pkg/utils/certs/localcerts.go b/pkg/utils/certs/localcerts.go
|
||||||
|
index c5fe2e5..d613ea9 100644
|
||||||
|
--- a/pkg/utils/certs/localcerts.go
|
||||||
|
+++ b/pkg/utils/certs/localcerts.go
|
||||||
|
@@ -148,7 +148,7 @@ func (l *LocalCertGenerator) CreateCertAndKey(caCertPath, caKeyPath string, conf
|
||||||
|
DNSNames: config.AltNames.DNSNames,
|
||||||
|
IPAddresses: ips,
|
||||||
|
SerialNumber: serial,
|
||||||
|
- KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
||||||
|
+ KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageDataEncipherment,
|
||||||
|
ExtKeyUsage: config.Usages,
|
||||||
|
NotBefore: caCert.NotBefore,
|
||||||
|
NotAfter: time.Now().Add(time.Hour * 24 * 36500).UTC(),
|
||||||
|
diff --git a/pkg/utils/template/template.go b/pkg/utils/template/template.go
|
||||||
|
index 3b3138a..b16f55a 100644
|
||||||
|
--- a/pkg/utils/template/template.go
|
||||||
|
+++ b/pkg/utils/template/template.go
|
||||||
|
@@ -77,7 +77,7 @@ IP.{{ Add $i 1 }} = {{ $v }}
|
||||||
|
[ v3_ext ]
|
||||||
|
authorityKeyIdentifier = keyid,issuer:always
|
||||||
|
basicConstraints = CA:FALSE
|
||||||
|
-keyUsage = keyEncipherment,dataEncipherment
|
||||||
|
+keyUsage = digitalSignature,keyEncipherment,dataEncipherment
|
||||||
|
extendedKeyUsage = {{ .ExtendedKeyUsage }}
|
||||||
|
{{- if .HaveAltNames }}
|
||||||
|
subjectAltName = @alt_names
|
||||||
|
diff --git a/pkg/utils/template/template_test.go b/pkg/utils/template/template_test.go
|
||||||
|
index ae46d48..30d6f2d 100644
|
||||||
|
--- a/pkg/utils/template/template_test.go
|
||||||
|
+++ b/pkg/utils/template/template_test.go
|
||||||
|
@@ -46,7 +46,7 @@ IP.3 = 127.0.0.1
|
||||||
|
[ v3_ext ]
|
||||||
|
authorityKeyIdentifier = keyid,issuer:always
|
||||||
|
basicConstraints = CA:FALSE
|
||||||
|
-keyUsage = keyEncipherment,dataEncipherment
|
||||||
|
+keyUsage = digitalSignature,keyEncipherment,dataEncipherment
|
||||||
|
extendedKeyUsage = serverAuth,clientAuth
|
||||||
|
subjectAltName = @alt_names
|
||||||
|
`
|
||||||
|
@@ -71,7 +71,7 @@ CN = kube-apiserver-kubelet-client
|
||||||
|
[ v3_ext ]
|
||||||
|
authorityKeyIdentifier=keyid,issuer:always
|
||||||
|
basicConstraints=CA:FALSE
|
||||||
|
-keyUsage=keyEncipherment,dataEncipherment
|
||||||
|
+keyUsage=digitalSignature,keyEncipherment,dataEncipherment
|
||||||
|
extendedKeyUsage=clientAuth
|
||||||
|
`
|
||||||
|
kubelet_conf := &CsrConfig{
|
||||||
|
@@ -92,7 +92,7 @@ CN = front-proxy-client
|
||||||
|
[ v3_ext ]
|
||||||
|
authorityKeyIdentifier=keyid,issuer:always
|
||||||
|
basicConstraints=CA:FALSE
|
||||||
|
-keyUsage=keyEncipherment,dataEncipherment
|
||||||
|
+keyUsage=digitalSignature,keyEncipherment,dataEncipherment
|
||||||
|
extendedKeyUsage=clientAuth
|
||||||
|
`
|
||||||
|
front_proxy_client_conf := &CsrConfig{
|
||||||
|
--
|
||||||
|
2.25.1
|
||||||
|
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
From cba65a460d748864feff49bd808c0f80c125ff4c Mon Sep 17 00:00:00 2001
|
||||||
|
From: DCCooper <1866858@gmail.com>
|
||||||
|
Date: Sat, 22 Jan 2022 16:50:30 +0800
|
||||||
|
Subject: [PATCH 21/24] gitignore: style(global): ignore IDE and gomod vendor
|
||||||
|
|
||||||
|
Signed-off-by: DCCooper <1866858@gmail.com>
|
||||||
|
---
|
||||||
|
.gitignore | 7 +++++++
|
||||||
|
1 file changed, 7 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/.gitignore b/.gitignore
|
||||||
|
index b11cba5..2819bbf 100644
|
||||||
|
--- a/.gitignore
|
||||||
|
+++ b/.gitignore
|
||||||
|
@@ -11,3 +11,10 @@
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
bin
|
||||||
|
+
|
||||||
|
+# IDE
|
||||||
|
+.vscode/
|
||||||
|
+.idea/
|
||||||
|
+
|
||||||
|
+# go mod vendor
|
||||||
|
+vendor
|
||||||
|
--
|
||||||
|
2.25.1
|
||||||
|
|
||||||
626
0022-add-golangci-check.patch
Normal file
626
0022-add-golangci-check.patch
Normal file
@ -0,0 +1,626 @@
|
|||||||
|
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
|
||||||
|
|
||||||
1489
0023-add-golang-static-code-check.patch
Normal file
1489
0023-add-golang-static-code-check.patch
Normal file
File diff suppressed because it is too large
Load Diff
35
0024-modify-dependency-install-command.patch
Normal file
35
0024-modify-dependency-install-command.patch
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
From c9dae67531cf99d97a3130b5b2e2fb04636370a3 Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
Date: Wed, 8 Jun 2022 15:42:00 +0800
|
||||||
|
Subject: [PATCH 24/24] modify dependency install command
|
||||||
|
|
||||||
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
---
|
||||||
|
pkg/utils/dependency/dependency.go | 4 ++--
|
||||||
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/pkg/utils/dependency/dependency.go b/pkg/utils/dependency/dependency.go
|
||||||
|
index ce4a7ca..3250579 100644
|
||||||
|
--- a/pkg/utils/dependency/dependency.go
|
||||||
|
+++ b/pkg/utils/dependency/dependency.go
|
||||||
|
@@ -163,7 +163,7 @@ func (dp *dependencyPkg) Install(r runner.Runner) error {
|
||||||
|
join += s.Name + "* "
|
||||||
|
}
|
||||||
|
|
||||||
|
- if _, err := r.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && %s %s",
|
||||||
|
+ if _, err := r.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && %s %s\"",
|
||||||
|
dp.srcPath, pManager.installCommand, join)); err != nil {
|
||||||
|
return fmt.Errorf("%s failed: %v", pManager.installCommand, err)
|
||||||
|
}
|
||||||
|
@@ -186,7 +186,7 @@ func (dp *dependencyPkg) Remove(r runner.Runner) error {
|
||||||
|
join += s.Name + "* "
|
||||||
|
}
|
||||||
|
|
||||||
|
- if _, err := r.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && %s %s",
|
||||||
|
+ if _, err := r.RunCommand(fmt.Sprintf("sudo -E /bin/sh -c \"cd %s && %s %s\"",
|
||||||
|
dp.srcPath, pManager.removeCommand, join)); err != nil {
|
||||||
|
return fmt.Errorf("%s remove failed: %v", pManager.removeCommand, err)
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.25.1
|
||||||
|
|
||||||
15
eggo.spec
15
eggo.spec
@ -1,6 +1,6 @@
|
|||||||
Name: eggo
|
Name: eggo
|
||||||
Version: 0.9.4
|
Version: 0.9.4
|
||||||
Release: 6
|
Release: 7
|
||||||
Summary: Eggo is a tool built to provide standard multi-ways for creating Kubernetes clusters.
|
Summary: Eggo is a tool built to provide standard multi-ways for creating Kubernetes clusters.
|
||||||
License: Mulan PSL V2
|
License: Mulan PSL V2
|
||||||
URL: https://gitee.com/openeuler/eggo
|
URL: https://gitee.com/openeuler/eggo
|
||||||
@ -23,6 +23,13 @@ Patch0014: 0014-refactor-dependency.patch
|
|||||||
Patch0015: 0015-delete-apiserver-kubelet-https-flag-and-add-lb-bind-.patch
|
Patch0015: 0015-delete-apiserver-kubelet-https-flag-and-add-lb-bind-.patch
|
||||||
Patch0016: 0016-add-vendor-LICENSE.patch
|
Patch0016: 0016-add-vendor-LICENSE.patch
|
||||||
Patch0017: 0017-fix-Makefile-build-error.patch
|
Patch0017: 0017-fix-Makefile-build-error.patch
|
||||||
|
Patch0018: 0018-implement-cmd-hooks.patch
|
||||||
|
Patch0019: 0019-add-design-of-eggoadm.patch
|
||||||
|
Patch0020: 0020-add-digitalSignature-for-certificates.patch
|
||||||
|
Patch0021: 0021-gitignore-style-global-ignore-IDE-and-gomod-vendor.patch
|
||||||
|
Patch0022: 0022-add-golangci-check.patch
|
||||||
|
Patch0023: 0023-add-golang-static-code-check.patch
|
||||||
|
Patch0024: 0024-modify-dependency-install-command.patch
|
||||||
|
|
||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
BuildRequires: git
|
BuildRequires: git
|
||||||
@ -64,6 +71,12 @@ rm -rf src
|
|||||||
%attr(551,root,root) %{_bindir}/eggo
|
%attr(551,root,root) %{_bindir}/eggo
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Feb 03 2023 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 0.9.4-7
|
||||||
|
- Type:bugfix
|
||||||
|
- CVE:NA
|
||||||
|
- SUG:NA
|
||||||
|
- DESC:update from openeuler
|
||||||
|
|
||||||
* Mon Nov 28 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 0.9.4-6
|
* Mon Nov 28 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 0.9.4-6
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- CVE:NA
|
- CVE:NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user