Experiment: add AddNodesPipeline

Signed-off-by: 24sama <leo@kubesphere.io>
This commit is contained in:
24sama 2021-09-15 17:29:30 +08:00
parent 467469f8d3
commit c7dfcd3611
2 changed files with 87 additions and 4 deletions

View File

@ -16,8 +16,8 @@ limitations under the License.
package cmd
import (
"github.com/kubesphere/kubekey/pkg/cluster/add"
"github.com/kubesphere/kubekey/pkg/util"
"github.com/kubesphere/kubekey/pkg/pipelines"
"github.com/kubesphere/kubekey/pkg/pipelines/common"
"github.com/spf13/cobra"
)
@ -26,8 +26,15 @@ var addNodesCmd = &cobra.Command{
Use: "nodes",
Short: "Add nodes to the cluster according to the new nodes information from the specified configuration file",
RunE: func(cmd *cobra.Command, args []string) error {
logger := util.InitLogger(opt.Verbose)
return add.AddNodes(opt.ClusterCfgFile, "", "", logger, false, opt.Verbose, opt.SkipCheck, opt.SkipPullImages, opt.InCluster, opt.DownloadCmd, opt.ContainerManager)
arg := common.Argument{
FilePath: opt.ClusterCfgFile,
KsEnable: false,
Debug: opt.Verbose,
SkipCheck: opt.SkipCheck,
SkipPullImages: opt.SkipPullImages,
InCluster: opt.InCluster,
}
return pipelines.AddNodes(arg, opt.DownloadCmd)
},
}

View File

@ -0,0 +1,76 @@
package pipelines
import (
"fmt"
"github.com/kubesphere/kubekey/pkg/core/modules"
"github.com/kubesphere/kubekey/pkg/core/pipeline"
"github.com/kubesphere/kubekey/pkg/pipelines/binaries"
"github.com/kubesphere/kubekey/pkg/pipelines/bootstrap/confirm"
"github.com/kubesphere/kubekey/pkg/pipelines/bootstrap/os"
"github.com/kubesphere/kubekey/pkg/pipelines/bootstrap/precheck"
"github.com/kubesphere/kubekey/pkg/pipelines/common"
"github.com/kubesphere/kubekey/pkg/pipelines/container"
"github.com/kubesphere/kubekey/pkg/pipelines/etcd"
"github.com/kubesphere/kubekey/pkg/pipelines/images"
"github.com/kubesphere/kubekey/pkg/pipelines/kubernetes"
"github.com/kubesphere/kubekey/pkg/pipelines/loadbalancer"
)
func NewAddNodesPipeline(runtime *common.KubeRuntime) error {
isK3s := runtime.Cluster.Kubernetes.Type == "k3s"
m := []modules.Module{
&precheck.NodePreCheckModule{Skip: isK3s},
&confirm.InstallConfirmModule{Skip: isK3s},
&binaries.NodeBinariesModule{},
&os.ConfigureOSModule{},
&kubernetes.KubernetesStatusModule{},
&container.InstallContainerModule{Skip: isK3s},
&images.ImageModule{Skip: isK3s || runtime.Arg.SkipPullImages},
&etcd.ETCDPreCheckModule{},
&etcd.ETCDCertsModule{},
&etcd.InstallETCDBinaryModule{},
&etcd.ETCDModule{},
&etcd.BackupETCDModule{},
&kubernetes.InstallKubeBinariesModule{},
&kubernetes.JoinNodesModule{},
&loadbalancer.HaproxyModule{Skip: !runtime.Cluster.ControlPlaneEndpoint.IsInternalLBEnabled()},
}
p := pipeline.Pipeline{
Name: "AddNodesPipeline",
Modules: m,
Runtime: runtime,
}
if err := p.Start(); err != nil {
return err
}
return nil
}
func AddNodes(args common.Argument, downloadCmd string) error {
args.DownloadCommand = func(path, url string) string {
// this is an extension point for downloading tools, for example users can set the timeout, proxy or retry under
// some poor network environment. Or users even can choose another cli, it might be wget.
// perhaps we should have a build-in download function instead of totally rely on the external one
return fmt.Sprintf(downloadCmd, path, url)
}
var loaderType string
if args.FilePath != "" {
loaderType = common.File
} else {
loaderType = common.AllInOne
}
runtime, err := common.NewKubeRuntime(loaderType, args)
if err != nil {
return err
}
if err := NewAddNodesPipeline(runtime); err != nil {
return err
}
return nil
}