1490 lines
51 KiB
Diff
1490 lines
51 KiB
Diff
From 61a4eb8d90ac24ad09b82b2d1578c99ed6a2d5b7 Mon Sep 17 00:00:00 2001
|
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
|
Date: Tue, 29 Mar 2022 21:34:38 +0800
|
|
Subject: [PATCH 23/24] add golang static code check
|
|
|
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
|
---
|
|
.golangci.yaml | 54 +++++++++++++++----
|
|
cmd/checker.go | 5 +-
|
|
cmd/checker_test.go | 4 +-
|
|
cmd/configs.go | 33 ++++++------
|
|
cmd/configs_test.go | 1 +
|
|
cmd/delete.go | 2 +-
|
|
cmd/eggo.go | 4 +-
|
|
cmd/filetools.go | 6 ++-
|
|
cmd/list.go | 1 +
|
|
cmd/opts.go | 4 +-
|
|
pkg/api/tools.go | 7 +--
|
|
pkg/api/types.go | 10 ++--
|
|
.../binary/addons/runner_addons.go | 4 +-
|
|
.../binary/bootstrap/bootstrap.go | 5 +-
|
|
.../binary/bootstrap/bootstrap_test.go | 9 ++--
|
|
.../binary/cleanupcluster/cleanupetcd.go | 1 +
|
|
.../binary/commontools/copycacerts.go | 1 +
|
|
.../binary/commontools/runshell.go | 1 +
|
|
.../binary/commontools/systemdservices.go | 5 +-
|
|
.../binary/controlplane/controlplane.go | 9 ++--
|
|
.../binary/controlplane/controlplane_test.go | 1 +
|
|
.../binary/coredns/binarycoredns.go | 11 ++--
|
|
.../binary/coredns/podcoredns.go | 6 ++-
|
|
.../binary/etcdcluster/etcdcluster.go | 10 ++--
|
|
.../binary/etcdcluster/etcdcluster_test.go | 1 +
|
|
.../binary/etcdcluster/etcdjoin.go | 4 +-
|
|
.../binary/etcdcluster/etcdreconfig.go | 5 +-
|
|
.../binary/infrastructure/firewall.go | 1 +
|
|
.../infrastructure/infrastructure_test.go | 1 +
|
|
.../binary/loadbalance/loadbalance.go | 1 +
|
|
.../binary/network/network.go | 5 +-
|
|
pkg/clusterdeployment/clusterdeploy.go | 36 ++++++++-----
|
|
pkg/clusterdeployment/runtime/runtime.go | 1 +
|
|
pkg/constants/constants.go | 14 ++++-
|
|
pkg/utils/certs/approvecsr.go | 10 ++--
|
|
pkg/utils/certs/certs.go | 1 +
|
|
pkg/utils/certs/localcerts.go | 9 +++-
|
|
pkg/utils/certs/tools.go | 6 ++-
|
|
pkg/utils/dependency/cmdhooks.go | 3 +-
|
|
pkg/utils/dependency/dependency.go | 1 +
|
|
pkg/utils/dependency/dependency_test.go | 1 +
|
|
pkg/utils/dependency/install.go | 9 ++--
|
|
pkg/utils/endpoint/endpoint.go | 13 +++--
|
|
pkg/utils/infra/infra.go | 2 +-
|
|
pkg/utils/kubectl/kubectl.go | 10 ++--
|
|
pkg/utils/kubectl/taint.go | 5 +-
|
|
pkg/utils/nodemanager/node.go | 14 +++--
|
|
pkg/utils/nodemanager/nodemanager.go | 5 +-
|
|
pkg/utils/nodemanager/nodemanager_test.go | 1 +
|
|
pkg/utils/runner/runner.go | 1 +
|
|
50 files changed, 244 insertions(+), 110 deletions(-)
|
|
|
|
diff --git a/.golangci.yaml b/.golangci.yaml
|
|
index ea8515f..e3051db 100644
|
|
--- a/.golangci.yaml
|
|
+++ b/.golangci.yaml
|
|
@@ -1,18 +1,54 @@
|
|
-linters-settings:
|
|
- golint:
|
|
- min-confidence: 0
|
|
- misspell:
|
|
- locale: US
|
|
+run:
|
|
+ deadline: 10m
|
|
+ issues-exit-code: 1
|
|
+ tests: true
|
|
+
|
|
+ skip-dirs:
|
|
+ - vendor
|
|
+
|
|
+ skip-files:
|
|
+ - ".*\\.pb\\.go$"
|
|
+ - ".*\\.dbx\\.go$"
|
|
+
|
|
+
|
|
linters:
|
|
disable-all: true
|
|
enable:
|
|
- - typecheck
|
|
+ - gomnd
|
|
+ - govet
|
|
- goimports
|
|
+ - revive
|
|
+ - gofmt
|
|
+ - gosimple
|
|
+ - typecheck
|
|
- misspell
|
|
- - govet
|
|
- ineffassign
|
|
- - gosimple
|
|
- deadcode
|
|
- structcheck
|
|
- unused
|
|
- - errcheck
|
|
\ No newline at end of file
|
|
+ - errcheck
|
|
+
|
|
+linters-settings:
|
|
+ gomnd:
|
|
+ settings:
|
|
+ mnd:
|
|
+ checks: argument, case, condition, operation, return, assign
|
|
+ ignored-numbers: 2
|
|
+ govet:
|
|
+ check-shadowing: true
|
|
+ use-installed-packages: false
|
|
+ goimports:
|
|
+ local-prefixes: isula.org/eggo
|
|
+ revive:
|
|
+ min-confidence: 0.8
|
|
+ rules:
|
|
+ - name: exported
|
|
+ disabled: true
|
|
+ gofmt:
|
|
+ simplify: true
|
|
+ misspell:
|
|
+ locale: US
|
|
+ errcheck:
|
|
+ check-type-assertions: false
|
|
+ check-blank: false
|
|
+ ignore: fmt:.*,io/ioutil:^Read.*
|
|
diff --git a/cmd/checker.go b/cmd/checker.go
|
|
index 2f99a0c..54136a2 100644
|
|
--- a/cmd/checker.go
|
|
+++ b/cmd/checker.go
|
|
@@ -26,12 +26,13 @@ import (
|
|
"strings"
|
|
"time"
|
|
|
|
+ "k8s.io/apimachinery/pkg/util/validation"
|
|
+
|
|
"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"
|
|
- "k8s.io/apimachinery/pkg/util/validation"
|
|
)
|
|
|
|
type ClusterConfigResponsibility struct {
|
|
@@ -414,7 +415,7 @@ func checkHookFile(fileName string) error {
|
|
if !file.Mode().IsRegular() {
|
|
return fmt.Errorf("%s is not regular file", file.Name())
|
|
}
|
|
- if file.Mode().Perm() != os.FileMode(constants.HookFileMode) {
|
|
+ if file.Mode().Perm() != constants.HookFileMode {
|
|
return fmt.Errorf("file mode of %s is incorrect", file.Name())
|
|
}
|
|
if file.Size() > constants.MaxHookFileSize || file.Size() == 0 {
|
|
diff --git a/cmd/checker_test.go b/cmd/checker_test.go
|
|
index 57babf9..1abf20d 100644
|
|
--- a/cmd/checker_test.go
|
|
+++ b/cmd/checker_test.go
|
|
@@ -53,8 +53,8 @@ func TestRunChecker(t *testing.T) {
|
|
}
|
|
|
|
for _, fn := range conf.InstallConfig.PackageSrc.SrcPath {
|
|
- if err := os.MkdirAll(fn, 0755); err != nil {
|
|
- t.Fatalf("mkdir failed: %v", err)
|
|
+ if terr := os.MkdirAll(fn, 0755); terr != nil {
|
|
+ t.Fatalf("mkdir failed: %v", terr)
|
|
}
|
|
defer os.RemoveAll(fn)
|
|
}
|
|
diff --git a/cmd/configs.go b/cmd/configs.go
|
|
index 4d7a4b9..0a35b57 100644
|
|
--- a/cmd/configs.go
|
|
+++ b/cmd/configs.go
|
|
@@ -25,9 +25,9 @@ import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
+ "github.com/sirupsen/logrus"
|
|
"gopkg.in/yaml.v1"
|
|
|
|
- "github.com/sirupsen/logrus"
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/coredns"
|
|
"isula.org/eggo/pkg/constants"
|
|
@@ -40,6 +40,9 @@ const (
|
|
WorkerRole string = "worker"
|
|
ETCDRole string = "etcd"
|
|
LoadBalanceRole string = "loadbalance"
|
|
+
|
|
+ parseBase = 10
|
|
+ parseBitSize = 32
|
|
)
|
|
|
|
var (
|
|
@@ -81,7 +84,7 @@ func init() {
|
|
return
|
|
}
|
|
|
|
- if err := os.Mkdir(utils.GetEggoDir(), 0700); err != nil {
|
|
+ if err := os.Mkdir(utils.GetEggoDir(), constants.EggoDirMode); err != nil {
|
|
logrus.Errorf("mkdir eggo directory %v failed", utils.GetEggoDir())
|
|
}
|
|
}
|
|
@@ -109,11 +112,11 @@ func saveDeployConfig(cc *DeployConfig, filePath string) error {
|
|
return fmt.Errorf("invalid config file path %v", filePath)
|
|
}
|
|
|
|
- if err = os.MkdirAll(filepath.Dir(cleanPath), 0750); err != nil {
|
|
+ if err = os.MkdirAll(filepath.Dir(cleanPath), constants.EggoHomeDirMode); err != nil {
|
|
return fmt.Errorf("create dir %v to save deploy config failed: %v", filepath.Dir(cleanPath), err)
|
|
}
|
|
|
|
- if err = ioutil.WriteFile(filePath, d, 0640); err != nil {
|
|
+ if err = ioutil.WriteFile(filePath, d, constants.DeployConfigFileMode); err != nil {
|
|
return fmt.Errorf("write user deploy config file failed: %v", err)
|
|
}
|
|
|
|
@@ -162,14 +165,14 @@ func getDefaultClusterdeploymentConfig() *api.ClusterConfig {
|
|
PluginArgs: make(map[string]string),
|
|
},
|
|
ControlPlane: api.ControlPlaneConfig{
|
|
- ApiConf: &api.ApiServer{
|
|
+ APIConf: &api.APIServer{
|
|
Timeout: "120s",
|
|
},
|
|
},
|
|
WorkerConfig: api.WorkerConfig{
|
|
KubeletConf: &api.Kubelet{
|
|
- DnsVip: "10.32.0.10",
|
|
- DnsDomain: "cluster.local",
|
|
+ DNSVip: "10.32.0.10",
|
|
+ DNSDomain: "cluster.local",
|
|
PauseImage: "k8s.gcr.io/pause:3.2",
|
|
NetworkPlugin: "cni",
|
|
CniBinDir: "/usr/libexec/cni,/opt/cni/bin",
|
|
@@ -283,7 +286,7 @@ func fillPackageConfig(ccfg *api.ClusterConfig, icfg *InstallConfig) {
|
|
}
|
|
|
|
if coredns.IsTypeBinary(ccfg.ServiceCluster.DNS.CorednsType) {
|
|
- ccfg.RoleInfra[api.Master].Softwares = appendSoftware(ccfg.RoleInfra[api.Master].Softwares, ToEggoPackageConfig(icfg.Dns), infra.DnsPackages)
|
|
+ ccfg.RoleInfra[api.Master].Softwares = appendSoftware(ccfg.RoleInfra[api.Master].Softwares, ToEggoPackageConfig(icfg.Dns), infra.DNSPackages)
|
|
}
|
|
|
|
if len(icfg.Addition) == 0 {
|
|
@@ -527,7 +530,7 @@ func fillAPIEndPoint(APIEndpoint *api.APIEndpoint, conf *DeployConfig) {
|
|
return
|
|
}
|
|
|
|
- iport, err := strconv.ParseInt(port, 10, 32)
|
|
+ iport, err := strconv.ParseInt(port, parseBase, parseBitSize)
|
|
if err != nil {
|
|
logrus.Errorf("invalid port %s: %v", port, err)
|
|
return
|
|
@@ -576,9 +579,9 @@ func toClusterdeploymentConfig(conf *DeployConfig, hooks []*api.ClusterHookConf)
|
|
setIfStrConfigNotEmpty(&ccfg.Network.PodCIDR, conf.NetWork.PodCIDR)
|
|
setIfStrConfigNotEmpty(&ccfg.Network.Plugin, conf.NetWork.Plugin)
|
|
setStrStrMap(ccfg.Network.PluginArgs, conf.NetWork.PluginArgs)
|
|
- setStrArray(&ccfg.ControlPlane.ApiConf.CertSans.DNSNames, conf.ApiServerCertSans.DNSNames)
|
|
- setStrArray(&ccfg.ControlPlane.ApiConf.CertSans.IPs, conf.ApiServerCertSans.IPs)
|
|
- setIfStrConfigNotEmpty(&ccfg.ControlPlane.ApiConf.Timeout, conf.ApiServerTimeout)
|
|
+ setStrArray(&ccfg.ControlPlane.APIConf.CertSans.DNSNames, conf.ApiServerCertSans.DNSNames)
|
|
+ setStrArray(&ccfg.ControlPlane.APIConf.CertSans.IPs, conf.ApiServerCertSans.IPs)
|
|
+ setIfStrConfigNotEmpty(&ccfg.ControlPlane.APIConf.Timeout, conf.ApiServerTimeout)
|
|
ccfg.EtcdCluster.External = conf.EtcdExternal
|
|
for _, node := range ccfg.Nodes {
|
|
if (node.Type & api.ETCD) != 0 {
|
|
@@ -586,8 +589,8 @@ func toClusterdeploymentConfig(conf *DeployConfig, hooks []*api.ClusterHookConf)
|
|
}
|
|
}
|
|
setIfStrConfigNotEmpty(&ccfg.EtcdCluster.Token, conf.EtcdToken)
|
|
- setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.DnsVip, conf.DnsVip)
|
|
- setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.DnsDomain, conf.DnsDomain)
|
|
+ setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.DNSVip, conf.DnsVip)
|
|
+ setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.DNSDomain, conf.DnsDomain)
|
|
setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.PauseImage, conf.PauseImage)
|
|
setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.NetworkPlugin, conf.NetworkPlugin)
|
|
setIfStrConfigNotEmpty(&ccfg.WorkerConfig.KubeletConf.CniBinDir, conf.CniBinDir)
|
|
@@ -938,7 +941,7 @@ func createDeployConfigTemplate(file string) error {
|
|
return fmt.Errorf("marshal template config failed: %v", err)
|
|
}
|
|
|
|
- if err := ioutil.WriteFile(file, d, 0640); err != nil {
|
|
+ if err := ioutil.WriteFile(file, d, constants.DeployConfigFileMode); err != nil {
|
|
return fmt.Errorf("write template config file failed: %v", err)
|
|
}
|
|
|
|
diff --git a/cmd/configs_test.go b/cmd/configs_test.go
|
|
index 04afc51..3b72481 100644
|
|
--- a/cmd/configs_test.go
|
|
+++ b/cmd/configs_test.go
|
|
@@ -23,6 +23,7 @@ import (
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v1"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
)
|
|
|
|
diff --git a/cmd/delete.go b/cmd/delete.go
|
|
index 05a1dee..2e537aa 100644
|
|
--- a/cmd/delete.go
|
|
+++ b/cmd/delete.go
|
|
@@ -89,7 +89,7 @@ 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 {
|
|
+ if err = checkCmdHooksParameter(opts.prehook, opts.posthook); err != nil {
|
|
return err
|
|
}
|
|
// check saved deploy config
|
|
diff --git a/cmd/eggo.go b/cmd/eggo.go
|
|
index 36a3f9e..77c8a0f 100644
|
|
--- a/cmd/eggo.go
|
|
+++ b/cmd/eggo.go
|
|
@@ -68,7 +68,9 @@ func preCheck() {
|
|
sb.WriteString("Maybe cause to failure!!!\n")
|
|
sb.WriteString("Shutdown current operator!!!\n")
|
|
fmt.Println(sb.String())
|
|
- time.Sleep(time.Second * 10)
|
|
+
|
|
+ const preCheckSecond = 10
|
|
+ time.Sleep(time.Second * preCheckSecond)
|
|
}
|
|
}
|
|
|
|
diff --git a/cmd/filetools.go b/cmd/filetools.go
|
|
index dff2a01..9b67b71 100644
|
|
--- a/cmd/filetools.go
|
|
+++ b/cmd/filetools.go
|
|
@@ -21,6 +21,8 @@ import (
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
+
|
|
+ "isula.org/eggo/pkg/constants"
|
|
)
|
|
|
|
func checkProcessRunning(pid int) bool {
|
|
@@ -53,11 +55,11 @@ func NewProcessPlaceHolder(path string) (*ProcessPlaceHolder, error) {
|
|
if err := checkProcessInFile(path); err != nil && !os.IsNotExist(err) {
|
|
return nil, err
|
|
}
|
|
- if err := os.MkdirAll(filepath.Dir(path), os.FileMode(0750)); err != nil {
|
|
+ if err := os.MkdirAll(filepath.Dir(path), constants.EggoHomeDirMode); err != nil {
|
|
return nil, err
|
|
}
|
|
pid := strconv.Itoa(os.Getpid())
|
|
- if err := ioutil.WriteFile(path, []byte(pid), 0640); err != nil {
|
|
+ if err := ioutil.WriteFile(path, []byte(pid), constants.ProcessFileMode); err != nil {
|
|
return nil, err
|
|
}
|
|
return &ProcessPlaceHolder{path}, nil
|
|
diff --git a/cmd/list.go b/cmd/list.go
|
|
index 27729ba..60e43bf 100644
|
|
--- a/cmd/list.go
|
|
+++ b/cmd/list.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
)
|
|
|
|
diff --git a/cmd/opts.go b/cmd/opts.go
|
|
index d0235fe..c2ffed4 100644
|
|
--- a/cmd/opts.go
|
|
+++ b/cmd/opts.go
|
|
@@ -20,6 +20,8 @@ import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
+
|
|
+ "isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils"
|
|
)
|
|
|
|
@@ -56,7 +58,7 @@ func init() {
|
|
return
|
|
}
|
|
|
|
- if err := os.Mkdir(utils.GetEggoDir(), 0700); err != nil {
|
|
+ if err := os.Mkdir(utils.GetEggoDir(), constants.EggoDirMode); err != nil {
|
|
logrus.Errorf("mkdir eggo directory %v failed", utils.GetEggoDir())
|
|
}
|
|
}
|
|
diff --git a/pkg/api/tools.go b/pkg/api/tools.go
|
|
index 4c65dc2..77ee1bc 100644
|
|
--- a/pkg/api/tools.go
|
|
+++ b/pkg/api/tools.go
|
|
@@ -6,8 +6,9 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
- "isula.org/eggo/pkg/constants"
|
|
"k8s.io/apimachinery/pkg/util/json"
|
|
+
|
|
+ "isula.org/eggo/pkg/constants"
|
|
)
|
|
|
|
var (
|
|
@@ -55,7 +56,7 @@ func (p PackageSrcConfig) GetPkgDstPath() string {
|
|
return p.DstPath
|
|
}
|
|
|
|
-func (ep APIEndpoint) GetUrl() string {
|
|
+func (ep APIEndpoint) GetURL() string {
|
|
return fmt.Sprintf("%s/%v", ep.AdvertiseAddress, ep.BindPort)
|
|
}
|
|
|
|
@@ -141,7 +142,7 @@ func WithEtcdExtrArgs(eargs map[string]string) ClusterConfigOption {
|
|
|
|
func WithAPIServerExtrArgs(eargs map[string]string) ClusterConfigOption {
|
|
return func(conf *ClusterConfig) *ClusterConfig {
|
|
- conf.ControlPlane.ApiConf.ExtraArgs = eargs
|
|
+ conf.ControlPlane.APIConf.ExtraArgs = eargs
|
|
return conf
|
|
}
|
|
}
|
|
diff --git a/pkg/api/types.go b/pkg/api/types.go
|
|
index 5cb7121..972ec82 100644
|
|
--- a/pkg/api/types.go
|
|
+++ b/pkg/api/types.go
|
|
@@ -55,7 +55,7 @@ const (
|
|
|
|
type HookRunConfig struct {
|
|
ClusterID string
|
|
- ClusterApiEndpoint string
|
|
+ ClusterAPIEndpoint string
|
|
ClusterConfigDir string
|
|
|
|
HookType HookType
|
|
@@ -115,7 +115,7 @@ type Sans struct {
|
|
DNSNames []string `json:"dns-names"`
|
|
IPs []string `json:"ips"`
|
|
}
|
|
-type ApiServer struct {
|
|
+type APIServer struct {
|
|
CertSans Sans `json:"cert-sans,omitempty"`
|
|
Timeout string `json:"timeout,omitempty"`
|
|
ExtraArgs map[string]string `json:"extra-args,omitempty"`
|
|
@@ -136,8 +136,8 @@ type WorkerConfig struct {
|
|
}
|
|
|
|
type Kubelet struct {
|
|
- DnsVip string `json:"dns-vip,omitempty"`
|
|
- DnsDomain string `json:"dns-domain"`
|
|
+ DNSVip string `json:"dns-vip,omitempty"`
|
|
+ DNSDomain string `json:"dns-domain"`
|
|
PauseImage string `json:"pause-image"`
|
|
NetworkPlugin string `json:"network-plugin"`
|
|
CniBinDir string `json:"cni-bin-dir"`
|
|
@@ -163,7 +163,7 @@ type APIEndpoint struct {
|
|
BindPort int32 `json:"bind-port,omitempty"`
|
|
}
|
|
type ControlPlaneConfig struct {
|
|
- ApiConf *ApiServer `json:"apiconf,omitempty"`
|
|
+ APIConf *APIServer `json:"apiconf,omitempty"`
|
|
ManagerConf *ControlManager `json:"managerconf,omitempty"`
|
|
SchedulerConf *Scheduler `json:"schedulerconf,omitempty"`
|
|
}
|
|
diff --git a/pkg/clusterdeployment/binary/addons/runner_addons.go b/pkg/clusterdeployment/binary/addons/runner_addons.go
|
|
index e5bc0ad..27347fd 100644
|
|
--- a/pkg/clusterdeployment/binary/addons/runner_addons.go
|
|
+++ b/pkg/clusterdeployment/binary/addons/runner_addons.go
|
|
@@ -6,6 +6,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils/dependency"
|
|
@@ -77,7 +78,8 @@ func setupAddons(cluster *api.ClusterConfig) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
- err = nodemanager.WaitNodesFinish([]string{useMaster}, 5*time.Minute)
|
|
+
|
|
+ err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
diff --git a/pkg/clusterdeployment/binary/bootstrap/bootstrap.go b/pkg/clusterdeployment/binary/bootstrap/bootstrap.go
|
|
index 46870d7..e7b0c63 100644
|
|
--- a/pkg/clusterdeployment/binary/bootstrap/bootstrap.go
|
|
+++ b/pkg/clusterdeployment/binary/bootstrap/bootstrap.go
|
|
@@ -24,6 +24,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/controlplane"
|
|
@@ -245,8 +246,8 @@ serverTLSBootstrap: true
|
|
`
|
|
|
|
datastore := make(map[string]interface{})
|
|
- datastore["DnsVip"] = ccfg.WorkerConfig.KubeletConf.DnsVip
|
|
- datastore["DnsDomain"] = ccfg.WorkerConfig.KubeletConf.DnsDomain
|
|
+ datastore["DnsVip"] = ccfg.WorkerConfig.KubeletConf.DNSVip
|
|
+ datastore["DnsDomain"] = ccfg.WorkerConfig.KubeletConf.DNSDomain
|
|
datastore["EnableServer"] = ccfg.WorkerConfig.KubeletConf.EnableServer
|
|
|
|
config, err := template.TemplateRender(kubeletConfig, datastore)
|
|
diff --git a/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go b/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
|
|
index 7b3c1ff..522af37 100644
|
|
--- a/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
|
|
+++ b/pkg/clusterdeployment/binary/bootstrap/bootstrap_test.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
@@ -71,8 +72,8 @@ func TestJoinMaster(t *testing.T) {
|
|
},
|
|
WorkerConfig: api.WorkerConfig{
|
|
KubeletConf: &api.Kubelet{
|
|
- DnsVip: "10.32.0.10",
|
|
- DnsDomain: "cluster.local",
|
|
+ DNSVip: "10.32.0.10",
|
|
+ DNSDomain: "cluster.local",
|
|
CniBinDir: "/opt/cni/bin",
|
|
},
|
|
ContainerEngineConf: &api.ContainerEngine{
|
|
@@ -146,8 +147,8 @@ func TestJoinWorker(t *testing.T) {
|
|
},
|
|
WorkerConfig: api.WorkerConfig{
|
|
KubeletConf: &api.Kubelet{
|
|
- DnsVip: "10.32.0.10",
|
|
- DnsDomain: "cluster.local",
|
|
+ DNSVip: "10.32.0.10",
|
|
+ DNSDomain: "cluster.local",
|
|
CniBinDir: "/opt/cni/bin",
|
|
},
|
|
ContainerEngineConf: &api.ContainerEngine{
|
|
diff --git a/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go b/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
|
|
index 59005a7..07922b0 100644
|
|
--- a/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
|
|
+++ b/pkg/clusterdeployment/binary/cleanupcluster/cleanupetcd.go
|
|
@@ -21,6 +21,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/etcdcluster"
|
|
"isula.org/eggo/pkg/utils"
|
|
diff --git a/pkg/clusterdeployment/binary/commontools/copycacerts.go b/pkg/clusterdeployment/binary/commontools/copycacerts.go
|
|
index d9f992d..0ef2815 100644
|
|
--- a/pkg/clusterdeployment/binary/commontools/copycacerts.go
|
|
+++ b/pkg/clusterdeployment/binary/commontools/copycacerts.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"path/filepath"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
)
|
|
diff --git a/pkg/clusterdeployment/binary/commontools/runshell.go b/pkg/clusterdeployment/binary/commontools/runshell.go
|
|
index 266c488..92122ef 100644
|
|
--- a/pkg/clusterdeployment/binary/commontools/runshell.go
|
|
+++ b/pkg/clusterdeployment/binary/commontools/runshell.go
|
|
@@ -16,6 +16,7 @@ package commontools
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
)
|
|
diff --git a/pkg/clusterdeployment/binary/commontools/systemdservices.go b/pkg/clusterdeployment/binary/commontools/systemdservices.go
|
|
index 3b32e22..00ed557 100644
|
|
--- a/pkg/clusterdeployment/binary/commontools/systemdservices.go
|
|
+++ b/pkg/clusterdeployment/binary/commontools/systemdservices.go
|
|
@@ -19,6 +19,7 @@ import (
|
|
"fmt"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
@@ -60,8 +61,8 @@ func SetupAPIServerService(r runner.Runner, ccfg *api.ClusterConfig, hcf *api.Ho
|
|
"--requestheader-username-headers": "X-Remote-User",
|
|
"--encryption-provider-config": "/etc/kubernetes/encryption-config.yaml",
|
|
}
|
|
- if ccfg.ControlPlane.ApiConf != nil {
|
|
- for k, v := range ccfg.ControlPlane.ApiConf.ExtraArgs {
|
|
+ if ccfg.ControlPlane.APIConf != nil {
|
|
+ for k, v := range ccfg.ControlPlane.APIConf.ExtraArgs {
|
|
defaultArgs[k] = v
|
|
}
|
|
}
|
|
diff --git a/pkg/clusterdeployment/binary/controlplane/controlplane.go b/pkg/clusterdeployment/binary/controlplane/controlplane.go
|
|
index 1f93e5e..31bdcef 100644
|
|
--- a/pkg/clusterdeployment/binary/controlplane/controlplane.go
|
|
+++ b/pkg/clusterdeployment/binary/controlplane/controlplane.go
|
|
@@ -26,6 +26,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
"isula.org/eggo/pkg/constants"
|
|
@@ -193,9 +194,9 @@ func generateApiServerCertificate(savePath string, cg certs.CertGenerator, ccfg
|
|
if ccfg.ServiceCluster.Gateway != "" {
|
|
ips = append(ips, ccfg.ServiceCluster.Gateway)
|
|
}
|
|
- if ccfg.ControlPlane.ApiConf != nil {
|
|
- ips = append(ips, ccfg.ControlPlane.ApiConf.CertSans.IPs...)
|
|
- dnsnames = append(dnsnames, ccfg.ControlPlane.ApiConf.CertSans.DNSNames...)
|
|
+ if ccfg.ControlPlane.APIConf != nil {
|
|
+ ips = append(ips, ccfg.ControlPlane.APIConf.CertSans.IPs...)
|
|
+ dnsnames = append(dnsnames, ccfg.ControlPlane.APIConf.CertSans.DNSNames...)
|
|
}
|
|
if ccfg.LoadBalancer.IP != "" {
|
|
ips = append(ips, ccfg.LoadBalancer.IP)
|
|
@@ -435,7 +436,7 @@ resources:
|
|
}
|
|
|
|
fname := filepath.Join(savePath, constants.EncryptionConfigName)
|
|
- return ioutil.WriteFile(fname, []byte(encryStr), 0600)
|
|
+ return ioutil.WriteFile(fname, []byte(encryStr), constants.EncryptionConfigFileMode)
|
|
}
|
|
|
|
func generateCertsAndKubeConfigs(r runner.Runner, ccfg *api.ClusterConfig, hcf *api.HostConfig) (err error) {
|
|
diff --git a/pkg/clusterdeployment/binary/controlplane/controlplane_test.go b/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
|
|
index c4e6ab7..0a73c71 100644
|
|
--- a/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
|
|
+++ b/pkg/clusterdeployment/binary/controlplane/controlplane_test.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
diff --git a/pkg/clusterdeployment/binary/coredns/binarycoredns.go b/pkg/clusterdeployment/binary/coredns/binarycoredns.go
|
|
index 411dba2..aa3fada 100644
|
|
--- a/pkg/clusterdeployment/binary/coredns/binarycoredns.go
|
|
+++ b/pkg/clusterdeployment/binary/coredns/binarycoredns.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
"isula.org/eggo/pkg/constants"
|
|
@@ -292,7 +293,7 @@ func (bc *BinaryCoredns) Setup(cluster *api.ClusterConfig) error {
|
|
return err
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinish(masterIPs, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish(masterIPs, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Errorf("coredns setup failed: %v", err)
|
|
return err
|
|
}
|
|
@@ -375,7 +376,7 @@ func (bc *BinaryCoredns) Cleanup(cluster *api.ClusterConfig) error {
|
|
return nil
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinish(masterIPs, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish(masterIPs, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("wait to coredns cleanup failed: %v", err)
|
|
return nil
|
|
}
|
|
@@ -414,7 +415,7 @@ func (bc *BinaryCoredns) JoinNode(nodeAddr string, cluster *api.ClusterConfig) e
|
|
return err
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinish([]string{nodeAddr}, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish([]string{nodeAddr}, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Errorf("wait to coredns service running failed: %v", err)
|
|
return err
|
|
}
|
|
@@ -431,7 +432,7 @@ func (bc *BinaryCoredns) JoinNode(nodeAddr string, cluster *api.ClusterConfig) e
|
|
return err
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Errorf("wait to join new coredns node failed: %v", err)
|
|
return err
|
|
}
|
|
@@ -453,7 +454,7 @@ func (bc *BinaryCoredns) CleanNode(nodeAddr string, cluster *api.ClusterConfig)
|
|
return nil
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinish([]string{nodeAddr}, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish([]string{nodeAddr}, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("wait to coredns cleanup failed: %v", err)
|
|
return nil
|
|
}
|
|
diff --git a/pkg/clusterdeployment/binary/coredns/podcoredns.go b/pkg/clusterdeployment/binary/coredns/podcoredns.go
|
|
index 28ae908..8b509bc 100644
|
|
--- a/pkg/clusterdeployment/binary/coredns/podcoredns.go
|
|
+++ b/pkg/clusterdeployment/binary/coredns/podcoredns.go
|
|
@@ -22,7 +22,9 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils/kubectl"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
@@ -137,7 +139,7 @@ func (pc *PodCoredns) Setup(cluster *api.ClusterConfig) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
- err = nodemanager.WaitNodesFinish([]string{useMaster}, 5*time.Minute)
|
|
+ err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
@@ -162,7 +164,7 @@ func (pc *PodCoredns) Cleanup(cluster *api.ClusterConfig) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
- err = nodemanager.WaitNodesFinish([]string{useMaster}, 5*time.Minute)
|
|
+ err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
diff --git a/pkg/clusterdeployment/binary/etcdcluster/etcdcluster.go b/pkg/clusterdeployment/binary/etcdcluster/etcdcluster.go
|
|
index 5444e77..d7d2f41 100644
|
|
--- a/pkg/clusterdeployment/binary/etcdcluster/etcdcluster.go
|
|
+++ b/pkg/clusterdeployment/binary/etcdcluster/etcdcluster.go
|
|
@@ -23,8 +23,10 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
@@ -155,7 +157,9 @@ func (t *EtcdPostDeployEtcdsTask) Run(r runner.Runner, hostConfig *api.HostConfi
|
|
return nil
|
|
}
|
|
retry--
|
|
- time.Sleep(3 * time.Second)
|
|
+
|
|
+ const etcdRetrySecond = 3
|
|
+ time.Sleep(time.Second * etcdRetrySecond)
|
|
}
|
|
|
|
return fmt.Errorf("etcd %v healthcheck failed: %v", hostConfig.Name, err)
|
|
@@ -244,7 +248,7 @@ func Init(conf *api.ClusterConfig) error {
|
|
return fmt.Errorf("run task on nodes failed: %v", err)
|
|
}
|
|
|
|
- if err := nodemanager.WaitNodesFinish(nodes, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinish(nodes, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return fmt.Errorf("wait for deploy etcds task finish failed: %v", err)
|
|
}
|
|
|
|
@@ -258,7 +262,7 @@ func Init(conf *api.ClusterConfig) error {
|
|
return fmt.Errorf("run task on nodes failed: %v", err)
|
|
}
|
|
|
|
- if err := nodemanager.WaitNodesFinish(nodes, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinish(nodes, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return fmt.Errorf("wait for post deploy etcds task finish failed: %v", err)
|
|
}
|
|
|
|
diff --git a/pkg/clusterdeployment/binary/etcdcluster/etcdcluster_test.go b/pkg/clusterdeployment/binary/etcdcluster/etcdcluster_test.go
|
|
index f19394a..74ced0f 100644
|
|
--- a/pkg/clusterdeployment/binary/etcdcluster/etcdcluster_test.go
|
|
+++ b/pkg/clusterdeployment/binary/etcdcluster/etcdcluster_test.go
|
|
@@ -24,6 +24,7 @@ import (
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
diff --git a/pkg/clusterdeployment/binary/etcdcluster/etcdjoin.go b/pkg/clusterdeployment/binary/etcdcluster/etcdjoin.go
|
|
index 97be436..f86499f 100644
|
|
--- a/pkg/clusterdeployment/binary/etcdcluster/etcdjoin.go
|
|
+++ b/pkg/clusterdeployment/binary/etcdcluster/etcdjoin.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"time"
|
|
|
|
"isula.org/eggo/pkg/api"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
"isula.org/eggo/pkg/utils/task"
|
|
)
|
|
@@ -48,7 +49,8 @@ func AddMember(conf *api.ClusterConfig, hostconfig *api.HostConfig) error {
|
|
return fmt.Errorf("run task on nodes failed: %v", err)
|
|
}
|
|
|
|
- if err := nodemanager.WaitNodesFinish([]string{hostconfig.Address}, 5*time.Minute); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinish([]string{hostconfig.Address},
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return fmt.Errorf("wait for post deploy etcds task finish failed: %v", err)
|
|
}
|
|
|
|
diff --git a/pkg/clusterdeployment/binary/etcdcluster/etcdreconfig.go b/pkg/clusterdeployment/binary/etcdcluster/etcdreconfig.go
|
|
index 9757997..df2cf5c 100644
|
|
--- a/pkg/clusterdeployment/binary/etcdcluster/etcdreconfig.go
|
|
+++ b/pkg/clusterdeployment/binary/etcdcluster/etcdreconfig.go
|
|
@@ -21,6 +21,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
@@ -229,7 +230,9 @@ func addEtcd(r runner.Runner, certDir string, name string, ip string) (string, e
|
|
return output, nil
|
|
}
|
|
retry--
|
|
- time.Sleep(3 * time.Second)
|
|
+
|
|
+ const etcdRetrySecond = 3
|
|
+ time.Sleep(time.Second * etcdRetrySecond)
|
|
}
|
|
logrus.Errorf("add etcd %v failed: %v\noutput: %v", name, err, output)
|
|
return "", err
|
|
diff --git a/pkg/clusterdeployment/binary/infrastructure/firewall.go b/pkg/clusterdeployment/binary/infrastructure/firewall.go
|
|
index 81bf7c5..4660cab 100644
|
|
--- a/pkg/clusterdeployment/binary/infrastructure/firewall.go
|
|
+++ b/pkg/clusterdeployment/binary/infrastructure/firewall.go
|
|
@@ -21,6 +21,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
diff --git a/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go b/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
|
|
index c9e0946..4ffa7a9 100644
|
|
--- a/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
|
|
+++ b/pkg/clusterdeployment/binary/infrastructure/infrastructure_test.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/dependency"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
diff --git a/pkg/clusterdeployment/binary/loadbalance/loadbalance.go b/pkg/clusterdeployment/binary/loadbalance/loadbalance.go
|
|
index 34c25bd..f059372 100644
|
|
--- a/pkg/clusterdeployment/binary/loadbalance/loadbalance.go
|
|
+++ b/pkg/clusterdeployment/binary/loadbalance/loadbalance.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
"isula.org/eggo/pkg/utils"
|
|
diff --git a/pkg/clusterdeployment/binary/network/network.go b/pkg/clusterdeployment/binary/network/network.go
|
|
index 0c35a9c..c88f28a 100644
|
|
--- a/pkg/clusterdeployment/binary/network/network.go
|
|
+++ b/pkg/clusterdeployment/binary/network/network.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils/kubectl"
|
|
@@ -79,7 +80,7 @@ func SetupNetwork(cluster *api.ClusterConfig) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
- err = nodemanager.WaitNodesFinish([]string{useMaster}, 5*time.Minute)
|
|
+ err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
@@ -133,7 +134,7 @@ func CleanupNetwork(cluster *api.ClusterConfig) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
- err = nodemanager.WaitNodesFinish([]string{useMaster}, 5*time.Minute)
|
|
+ err = nodemanager.WaitNodesFinish([]string{useMaster}, time.Minute*constants.DefaultTaskWaitMinutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
diff --git a/pkg/clusterdeployment/clusterdeploy.go b/pkg/clusterdeployment/clusterdeploy.go
|
|
index fde1fde..1ecf46f 100644
|
|
--- a/pkg/clusterdeployment/clusterdeploy.go
|
|
+++ b/pkg/clusterdeployment/clusterdeploy.go
|
|
@@ -22,9 +22,11 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
_ "isula.org/eggo/pkg/clusterdeployment/binary"
|
|
"isula.org/eggo/pkg/clusterdeployment/manager"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils"
|
|
"isula.org/eggo/pkg/utils/certs"
|
|
"isula.org/eggo/pkg/utils/nodemanager"
|
|
@@ -98,7 +100,8 @@ func doJoinNodeOfCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig
|
|
joinedNodeIDs = append(joinedNodeIDs, node.Address)
|
|
}
|
|
// wait all nodes ready
|
|
- if err := nodemanager.WaitNodesFinishWithProgress(joinedNodeIDs, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinishWithProgress(joinedNodeIDs,
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
tFailedNodes, successNodes := nodemanager.CheckNodesStatus(joinedNodeIDs)
|
|
// update joined and failed nodes
|
|
failedNodes = append(failedNodes, tFailedNodes...)
|
|
@@ -149,7 +152,8 @@ func doCreateCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, cs
|
|
|
|
// Step3: setup etcd cluster
|
|
// wait infrastructure task success on nodes of etcd cluster
|
|
- if err = nodemanager.WaitNodesFinishWithProgress(etcdNodes, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinishWithProgress(etcdNodes,
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return nil, err
|
|
}
|
|
if err = handler.EtcdClusterSetup(); err != nil {
|
|
@@ -166,7 +170,8 @@ func doCreateCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, cs
|
|
return nil, err
|
|
}
|
|
// wait controlplane setup task success
|
|
- if err = nodemanager.WaitNodesFinish([]string{controlPlaneNode.Address}, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish([]string{controlPlaneNode.Address},
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return nil, err
|
|
}
|
|
if utils.IsType(controlPlaneNode.Type, api.Worker) {
|
|
@@ -195,7 +200,8 @@ func doCreateCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, cs
|
|
return nil, err
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinishWithProgress(append(joinedNodeIDs, controlPlaneNode.Address), time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinishWithProgress(append(joinedNodeIDs, controlPlaneNode.Address),
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
@@ -229,7 +235,8 @@ func rollbackFailedNoeds(handler api.ClusterDeploymentAPI, nodes []*api.HostConf
|
|
rollIDs = append(rollIDs, n.Address)
|
|
}
|
|
|
|
- if err := nodemanager.WaitNodesFinishWithProgress(rollIDs, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinishWithProgress(rollIDs,
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("rollback failed: %v", err)
|
|
}
|
|
}
|
|
@@ -255,7 +262,7 @@ func CreateCluster(cc *api.ClusterConfig, deployEnableRollback bool) (api.Cluste
|
|
defer handler.Finish()
|
|
|
|
// prepare eggo config directory
|
|
- if err := os.MkdirAll(api.GetClusterHomePath(cc.Name), 0750); err != nil {
|
|
+ if err = os.MkdirAll(api.GetClusterHomePath(cc.Name), constants.EggoHomeDirMode); err != nil {
|
|
return cstatus, err
|
|
}
|
|
|
|
@@ -302,7 +309,8 @@ func doJoinNode(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, hostcon
|
|
}
|
|
|
|
// wait infrastructure task success on node
|
|
- if err := nodemanager.WaitNodesFinish([]string{hostconfig.Address}, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinish([]string{hostconfig.Address},
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return err
|
|
}
|
|
|
|
@@ -325,7 +333,8 @@ func doJoinNode(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, hostcon
|
|
}
|
|
|
|
// wait node ready
|
|
- if err := nodemanager.WaitNodesFinishWithProgress([]string{hostconfig.Address}, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinishWithProgress([]string{hostconfig.Address},
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
return err
|
|
}
|
|
|
|
@@ -471,7 +480,8 @@ func doDeleteNode(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig, h *ap
|
|
return err
|
|
}
|
|
|
|
- if err := nodemanager.WaitNodesFinishWithProgress([]string{h.Address}, time.Minute*5); err != nil {
|
|
+ if err := nodemanager.WaitNodesFinishWithProgress([]string{h.Address},
|
|
+ time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("wait cleanup finish failed: %v", err)
|
|
}
|
|
|
|
@@ -511,7 +521,7 @@ func DeleteNodes(cc *api.ClusterConfig, hostconfigs []*api.HostConfig) error {
|
|
for _, h := range nodes {
|
|
go func(hostconfig *api.HostConfig) {
|
|
defer wg.Done()
|
|
- if err := doDeleteNode(handler, cc, hostconfig); err != nil {
|
|
+ if terr := doDeleteNode(handler, cc, hostconfig); terr != nil {
|
|
logrus.Errorf("[cluster] delete '%s' from cluster failed", hostconfig.Name)
|
|
return
|
|
}
|
|
@@ -522,7 +532,7 @@ func DeleteNodes(cc *api.ClusterConfig, hostconfigs []*api.HostConfig) error {
|
|
|
|
// delete node with etcds
|
|
for _, h := range etcds {
|
|
- if err := doDeleteNode(handler, cc, h); err != nil {
|
|
+ if err = doDeleteNode(handler, cc, h); err != nil {
|
|
logrus.Errorf("[cluster] delete '%s' with etcd from cluster failed", h.Name)
|
|
return err
|
|
}
|
|
@@ -543,7 +553,7 @@ func doRemoveCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig) {
|
|
}
|
|
|
|
allNodes := utils.GetAllIPs(cc.Nodes)
|
|
- if err = nodemanager.WaitNodesFinish(allNodes, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinish(allNodes, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("[cluster] wait cleanup addons failed: %v", err)
|
|
}
|
|
|
|
@@ -603,7 +613,7 @@ func doRemoveCluster(handler api.ClusterDeploymentAPI, cc *api.ClusterConfig) {
|
|
}
|
|
}
|
|
|
|
- if err = nodemanager.WaitNodesFinishWithProgress(allNodes, time.Minute*5); err != nil {
|
|
+ if err = nodemanager.WaitNodesFinishWithProgress(allNodes, time.Minute*constants.DefaultTaskWaitMinutes); err != nil {
|
|
logrus.Warnf("[cluster] wait all cleanup finish failed: %v", err)
|
|
}
|
|
}
|
|
diff --git a/pkg/clusterdeployment/runtime/runtime.go b/pkg/clusterdeployment/runtime/runtime.go
|
|
index e996dae..f8cc424 100644
|
|
--- a/pkg/clusterdeployment/runtime/runtime.go
|
|
+++ b/pkg/clusterdeployment/runtime/runtime.go
|
|
@@ -6,6 +6,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/clusterdeployment/binary/commontools"
|
|
"isula.org/eggo/pkg/utils/dependency"
|
|
diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go
|
|
index c60d061..0ab75cc 100644
|
|
--- a/pkg/constants/constants.go
|
|
+++ b/pkg/constants/constants.go
|
|
@@ -1,5 +1,7 @@
|
|
package constants
|
|
|
|
+import "os"
|
|
+
|
|
const (
|
|
// certificates relate constants
|
|
DefaultK8SRootDir = "/etc/kubernetes"
|
|
@@ -30,6 +32,14 @@ const (
|
|
NetworkPluginArgKeyYamlPath = "NetworkYamlPath"
|
|
|
|
MaxHookFileSize = int64(1 << 20)
|
|
- // 750: rwxr-x---
|
|
- HookFileMode = uint32(0750)
|
|
+
|
|
+ HookFileMode os.FileMode = 0750
|
|
+ EggoHomeDirMode os.FileMode = 0750
|
|
+ EggoDirMode os.FileMode = 0700
|
|
+ DeployConfigFileMode os.FileMode = 0640
|
|
+ ProcessFileMode os.FileMode = 0640
|
|
+ EncryptionConfigFileMode os.FileMode = 0600
|
|
+
|
|
+ // default task wait time in minute
|
|
+ DefaultTaskWaitMinutes = 5
|
|
)
|
|
diff --git a/pkg/utils/certs/approvecsr.go b/pkg/utils/certs/approvecsr.go
|
|
index dfebbee..d4f81a4 100644
|
|
--- a/pkg/utils/certs/approvecsr.go
|
|
+++ b/pkg/utils/certs/approvecsr.go
|
|
@@ -24,15 +24,16 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
- "isula.org/eggo/pkg/api"
|
|
- "isula.org/eggo/pkg/constants"
|
|
- "isula.org/eggo/pkg/utils/kubectl"
|
|
certificatesv1 "k8s.io/api/certificates/v1"
|
|
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
|
|
corev1 "k8s.io/api/core/v1"
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/util/cert"
|
|
+
|
|
+ "isula.org/eggo/pkg/api"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
+ "isula.org/eggo/pkg/utils/kubectl"
|
|
)
|
|
|
|
type ServingCSR interface {
|
|
@@ -309,7 +310,8 @@ func ApproveCsr(cluster string, workers []*api.HostConfig) error {
|
|
}
|
|
|
|
// maybe the serving csr hasn't received
|
|
- time.Sleep(time.Duration(10) * time.Second)
|
|
+ const approvedIntervalSeconds = 3
|
|
+ time.Sleep(time.Second * approvedIntervalSeconds)
|
|
}
|
|
|
|
if !approved {
|
|
diff --git a/pkg/utils/certs/certs.go b/pkg/utils/certs/certs.go
|
|
index e57cfe8..0772679 100644
|
|
--- a/pkg/utils/certs/certs.go
|
|
+++ b/pkg/utils/certs/certs.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/template"
|
|
)
|
|
diff --git a/pkg/utils/certs/localcerts.go b/pkg/utils/certs/localcerts.go
|
|
index d613ea9..c6b2fc1 100644
|
|
--- a/pkg/utils/certs/localcerts.go
|
|
+++ b/pkg/utils/certs/localcerts.go
|
|
@@ -14,11 +14,16 @@ import (
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
- "isula.org/eggo/pkg/utils/runner"
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
|
certutil "k8s.io/client-go/util/cert"
|
|
keyutil "k8s.io/client-go/util/keyutil"
|
|
+
|
|
+ "isula.org/eggo/pkg/utils/runner"
|
|
+)
|
|
+
|
|
+const (
|
|
+ certExpiryHour = 24 * 36500
|
|
)
|
|
|
|
type LocalCertGenerator struct {
|
|
@@ -151,7 +156,7 @@ func (l *LocalCertGenerator) CreateCertAndKey(caCertPath, caKeyPath string, conf
|
|
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageDataEncipherment,
|
|
ExtKeyUsage: config.Usages,
|
|
NotBefore: caCert.NotBefore,
|
|
- NotAfter: time.Now().Add(time.Hour * 24 * 36500).UTC(),
|
|
+ NotAfter: time.Now().Add(time.Hour * certExpiryHour).UTC(),
|
|
}
|
|
|
|
certBytes, err := x509.CreateCertificate(rand.Reader, &certConf, caCert, signer.Public(), caKey)
|
|
diff --git a/pkg/utils/certs/tools.go b/pkg/utils/certs/tools.go
|
|
index 24cbc04..d18b7fd 100644
|
|
--- a/pkg/utils/certs/tools.go
|
|
+++ b/pkg/utils/certs/tools.go
|
|
@@ -16,6 +16,10 @@ import (
|
|
keyutil "k8s.io/client-go/util/keyutil"
|
|
)
|
|
|
|
+const (
|
|
+ keyBits = 4096
|
|
+)
|
|
+
|
|
func GetCertName(name string) string {
|
|
return fmt.Sprintf("%s.crt", name)
|
|
}
|
|
@@ -29,7 +33,7 @@ func GetKeySigner(alg x509.PublicKeyAlgorithm) (crypto.Signer, error) {
|
|
return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
}
|
|
|
|
- return rsa.GenerateKey(rand.Reader, 4096)
|
|
+ return rsa.GenerateKey(rand.Reader, keyBits)
|
|
}
|
|
|
|
func ParseIPsFromString(ipStrs []string) ([]net.IP, error) {
|
|
diff --git a/pkg/utils/dependency/cmdhooks.go b/pkg/utils/dependency/cmdhooks.go
|
|
index e6fd9af..b1f93ad 100644
|
|
--- a/pkg/utils/dependency/cmdhooks.go
|
|
+++ b/pkg/utils/dependency/cmdhooks.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"path"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils"
|
|
@@ -75,7 +76,7 @@ func ExecuteCmdHooks(ccfg *api.ClusterConfig, nodes []*api.HostConfig, op api.Ho
|
|
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(),
|
|
+ ClusterAPIEndpoint: ccfg.APIEndpoint.GetURL(),
|
|
ClusterConfigDir: ccfg.ConfigDir,
|
|
HookType: hooks.Type,
|
|
Operator: hooks.Operator,
|
|
diff --git a/pkg/utils/dependency/dependency.go b/pkg/utils/dependency/dependency.go
|
|
index 9b464dd..ce4a7ca 100644
|
|
--- a/pkg/utils/dependency/dependency.go
|
|
+++ b/pkg/utils/dependency/dependency.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/template"
|
|
diff --git a/pkg/utils/dependency/dependency_test.go b/pkg/utils/dependency/dependency_test.go
|
|
index 58ea756..c50a6fc 100644
|
|
--- a/pkg/utils/dependency/dependency_test.go
|
|
+++ b/pkg/utils/dependency/dependency_test.go
|
|
@@ -4,6 +4,7 @@ import (
|
|
"testing"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
)
|
|
|
|
diff --git a/pkg/utils/dependency/install.go b/pkg/utils/dependency/install.go
|
|
index 35c3521..62437b7 100644
|
|
--- a/pkg/utils/dependency/install.go
|
|
+++ b/pkg/utils/dependency/install.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils"
|
|
@@ -176,9 +177,11 @@ func ExecuteHooks(hookConf *api.HookRunConfig) error {
|
|
srcPath: hookConf.HookDir,
|
|
shell: hookConf.Hooks,
|
|
}
|
|
- envs := make([]string, 9)
|
|
+
|
|
+ const envsSize = 9
|
|
+ envs := make([]string, envsSize)
|
|
envs[0] = fmt.Sprintf("EGGO_CLUSTER_ID=%s", hookConf.ClusterID)
|
|
- envs[1] = fmt.Sprintf("EGGO_CLUSTER_API_ENDPOINT=%s", hookConf.ClusterApiEndpoint)
|
|
+ envs[1] = fmt.Sprintf("EGGO_CLUSTER_API_ENDPOINT=%s", hookConf.ClusterAPIEndpoint)
|
|
envs[2] = fmt.Sprintf("EGGO_CLUSTER_CONFIG_DIR=%s", hookConf.ClusterConfigDir)
|
|
envs[3] = fmt.Sprintf("EGGO_NODE_IP=%s", hookConf.Node.Address)
|
|
envs[4] = fmt.Sprintf("EGGO_NODE_NAME=%s", hookConf.Node.Name)
|
|
@@ -220,7 +223,7 @@ func executeShell(ccfg *api.ClusterConfig, role uint16, hcf *api.HostConfig, sch
|
|
|
|
hookConf := &api.HookRunConfig{
|
|
ClusterID: ccfg.Name,
|
|
- ClusterApiEndpoint: ccfg.APIEndpoint.GetUrl(),
|
|
+ ClusterAPIEndpoint: ccfg.APIEndpoint.GetURL(),
|
|
ClusterConfigDir: ccfg.ConfigDir,
|
|
HookType: htype,
|
|
Operator: oper,
|
|
diff --git a/pkg/utils/endpoint/endpoint.go b/pkg/utils/endpoint/endpoint.go
|
|
index a2b82d3..17c4dcc 100644
|
|
--- a/pkg/utils/endpoint/endpoint.go
|
|
+++ b/pkg/utils/endpoint/endpoint.go
|
|
@@ -27,13 +27,16 @@ import (
|
|
)
|
|
|
|
const (
|
|
- DefaultEndpointPort = 6443
|
|
+ defaultEndpointPort = 6443
|
|
+
|
|
+ parseBase = 10
|
|
+ parsebitSize = 16
|
|
)
|
|
|
|
func GetEndpoint(advertiseAddr string, bindPort int) (string, error) {
|
|
if !ValidPort(bindPort) {
|
|
- bindPort = DefaultEndpointPort
|
|
- logrus.Warnf("ignore invalid bindport: %d, use default: %d", bindPort, DefaultEndpointPort)
|
|
+ bindPort = defaultEndpointPort
|
|
+ logrus.Warnf("ignore invalid bindport: %d, use default: %d", bindPort, defaultEndpointPort)
|
|
}
|
|
|
|
if ip := net.ParseIP(advertiseAddr); ip == nil {
|
|
@@ -52,7 +55,7 @@ func ValidPort(port int) bool {
|
|
}
|
|
|
|
func ParsePort(port string) (int, error) {
|
|
- tport, err := strconv.ParseUint(port, 10, 16)
|
|
+ tport, err := strconv.ParseUint(port, parseBase, parsebitSize)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
@@ -77,7 +80,7 @@ func GetAPIServerEndpoint(ccfg *api.ClusterConfig) (string, error) {
|
|
return "", fmt.Errorf("invalid host")
|
|
}
|
|
if sport == "" {
|
|
- sport = strconv.Itoa(DefaultEndpointPort)
|
|
+ sport = strconv.Itoa(defaultEndpointPort)
|
|
}
|
|
|
|
port, err := ParsePort(sport)
|
|
diff --git a/pkg/utils/infra/infra.go b/pkg/utils/infra/infra.go
|
|
index 2b36e2a..0addf5d 100644
|
|
--- a/pkg/utils/infra/infra.go
|
|
+++ b/pkg/utils/infra/infra.go
|
|
@@ -110,7 +110,7 @@ var (
|
|
}
|
|
|
|
// coredns
|
|
- DnsPackages = []*api.PackageConfig{
|
|
+ DNSPackages = []*api.PackageConfig{
|
|
{
|
|
Name: "coredns",
|
|
Type: "repo",
|
|
diff --git a/pkg/utils/kubectl/kubectl.go b/pkg/utils/kubectl/kubectl.go
|
|
index b299a2a..057815a 100644
|
|
--- a/pkg/utils/kubectl/kubectl.go
|
|
+++ b/pkg/utils/kubectl/kubectl.go
|
|
@@ -22,13 +22,14 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
+ "k8s.io/client-go/kubernetes"
|
|
+ "k8s.io/client-go/tools/clientcmd"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/constants"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/template"
|
|
- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
- "k8s.io/client-go/kubernetes"
|
|
- "k8s.io/client-go/tools/clientcmd"
|
|
)
|
|
|
|
var ops map[string]string
|
|
@@ -109,7 +110,8 @@ func WaitNodeRegister(name string, cluster string) error {
|
|
return err
|
|
}
|
|
|
|
- finish := time.After(time.Second * 120)
|
|
+ const timeout = 120
|
|
+ finish := time.After(time.Second * timeout)
|
|
for {
|
|
select {
|
|
case t := <-finish:
|
|
diff --git a/pkg/utils/kubectl/taint.go b/pkg/utils/kubectl/taint.go
|
|
index a6af75b..fc9521e 100644
|
|
--- a/pkg/utils/kubectl/taint.go
|
|
+++ b/pkg/utils/kubectl/taint.go
|
|
@@ -6,12 +6,13 @@ import (
|
|
"path/filepath"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
- "isula.org/eggo/pkg/api"
|
|
- "isula.org/eggo/pkg/constants"
|
|
k8scorev1 "k8s.io/api/core/v1"
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
|
+
|
|
+ "isula.org/eggo/pkg/api"
|
|
+ "isula.org/eggo/pkg/constants"
|
|
)
|
|
|
|
type Taint struct {
|
|
diff --git a/pkg/utils/nodemanager/node.go b/pkg/utils/nodemanager/node.go
|
|
index 08af098..5474719 100644
|
|
--- a/pkg/utils/nodemanager/node.go
|
|
+++ b/pkg/utils/nodemanager/node.go
|
|
@@ -22,18 +22,26 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/task"
|
|
)
|
|
|
|
const (
|
|
+ // status
|
|
WorkingStatus = iota
|
|
FinishStatus
|
|
IgnoreStatus
|
|
ErrorStatus
|
|
)
|
|
|
|
+const (
|
|
+ nodeQueueCapability = 16
|
|
+ runTaskTimeOutSecond = 300
|
|
+ waitTaskMillisecond = 200
|
|
+)
|
|
+
|
|
type NodeStatus struct {
|
|
Status int
|
|
Message string
|
|
@@ -115,7 +123,7 @@ func (n *Node) WaitNodeTasksFinish(timeout time.Duration) error {
|
|
msg := s.Message
|
|
n.lock.RUnlock()
|
|
if !s.TasksFinished() {
|
|
- time.Sleep(time.Millisecond * 200)
|
|
+ time.Sleep(time.Millisecond * waitTaskMillisecond)
|
|
continue
|
|
}
|
|
if s.HasError() {
|
|
@@ -177,7 +185,7 @@ func doRunTask(n *Node, t task.Task) {
|
|
go func(ec chan error) {
|
|
select {
|
|
// TODO: maybe we need get timeout from task
|
|
- case <-time.After(time.Second * 300):
|
|
+ case <-time.After(time.Second * runTaskTimeOutSecond):
|
|
ec <- fmt.Errorf("timeout to run task")
|
|
case ec <- t.Run(n.r, n.host):
|
|
}
|
|
@@ -212,7 +220,7 @@ func NewNode(hcf *api.HostConfig, r runner.Runner) (*Node, error) {
|
|
host: hcf,
|
|
r: r,
|
|
stop: make(chan bool),
|
|
- queue: make(chan task.Task, 16),
|
|
+ queue: make(chan task.Task, nodeQueueCapability),
|
|
}
|
|
|
|
go func(n *Node) {
|
|
diff --git a/pkg/utils/nodemanager/nodemanager.go b/pkg/utils/nodemanager/nodemanager.go
|
|
index 5fff50e..b3a80e7 100644
|
|
--- a/pkg/utils/nodemanager/nodemanager.go
|
|
+++ b/pkg/utils/nodemanager/nodemanager.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/task"
|
|
@@ -148,6 +149,8 @@ func RunTaskOnAll(t task.Task) error {
|
|
}
|
|
|
|
func RunTasksOnNode(tasks []task.Task, node string) error {
|
|
+ const pushTaskInterval = 6
|
|
+
|
|
manager.lock.Lock()
|
|
defer manager.lock.Unlock()
|
|
|
|
@@ -158,7 +161,7 @@ func RunTasksOnNode(tasks []task.Task, node string) error {
|
|
if n.PushTask(t) {
|
|
break
|
|
}
|
|
- time.Sleep(time.Second * 6)
|
|
+ time.Sleep(time.Second * pushTaskInterval)
|
|
}
|
|
if i == 5 {
|
|
logrus.Errorf("node: %s work with too much tasks, will retry it", node)
|
|
diff --git a/pkg/utils/nodemanager/nodemanager_test.go b/pkg/utils/nodemanager/nodemanager_test.go
|
|
index 52ad91c..cbd46db 100644
|
|
--- a/pkg/utils/nodemanager/nodemanager_test.go
|
|
+++ b/pkg/utils/nodemanager/nodemanager_test.go
|
|
@@ -22,6 +22,7 @@ import (
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
"isula.org/eggo/pkg/utils/runner"
|
|
"isula.org/eggo/pkg/utils/task"
|
|
diff --git a/pkg/utils/runner/runner.go b/pkg/utils/runner/runner.go
|
|
index 09c9e1d..7b54730 100644
|
|
--- a/pkg/utils/runner/runner.go
|
|
+++ b/pkg/utils/runner/runner.go
|
|
@@ -29,6 +29,7 @@ import (
|
|
kkv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
|
|
"github.com/kubesphere/kubekey/pkg/util/ssh"
|
|
"github.com/sirupsen/logrus"
|
|
+
|
|
"isula.org/eggo/pkg/api"
|
|
)
|
|
|
|
--
|
|
2.25.1
|
|
|