From 174e54406ea4111af184fd39a37e4880fdfab6d6 Mon Sep 17 00:00:00 2001 From: 24sama Date: Fri, 10 Sep 2021 15:04:36 +0800 Subject: [PATCH] Experiment: change /bin/sh to /bin/bash Signed-off-by: 24sama --- cmd/cluster.go | 17 +++++++++++++++-- pkg/pipelines/kubernetes/tasks.go | 17 ++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cmd/cluster.go b/cmd/cluster.go index 956213a2..9ccdff40 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -19,6 +19,7 @@ import ( "fmt" "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1" "github.com/kubesphere/kubekey/pkg/pipelines" + "github.com/kubesphere/kubekey/pkg/pipelines/common" "github.com/kubesphere/kubekey/version" "github.com/spf13/cobra" "time" @@ -49,8 +50,20 @@ var clusterCmd = &cobra.Command{ } else { ksVersion = "" } - return pipelines.CreateCluster(opt.ClusterCfgFile, opt.Kubernetes, ksVersion, opt.Kubesphere, opt.Verbose, - opt.SkipCheck, opt.SkipPullImages, opt.InCluster, opt.LocalStorage, opt.DownloadCmd) + + arg := common.Argument{ + FilePath: opt.ClusterCfgFile, + KubernetesVersion: opt.Kubernetes, + KsEnable: opt.Kubesphere, + KsVersion: ksVersion, + SkipCheck: opt.SkipCheck, + SkipPullImages: opt.SkipPullImages, + InCluster: opt.InCluster, + DeployLocalStorage: opt.LocalStorage, + Debug: opt.Verbose, + } + + return pipelines.CreateCluster(arg, opt.DownloadCmd) }, } diff --git a/pkg/pipelines/kubernetes/tasks.go b/pkg/pipelines/kubernetes/tasks.go index 297ca856..4f2aaccb 100644 --- a/pkg/pipelines/kubernetes/tasks.go +++ b/pkg/pipelines/kubernetes/tasks.go @@ -265,12 +265,11 @@ type KubeadmInit struct { } func (k *KubeadmInit) Execute(runtime connector.Runtime) error { - if _, err := runtime.GetRunner().Cmd("sudo env PATH=$PATH /bin/sh -c \""+ - "/usr/local/bin/kubeadm init "+ + if _, err := runtime.GetRunner().SudoCmd("/usr/local/bin/kubeadm init "+ "--config=/etc/kubernetes/kubeadm-config.yaml "+ - "--ignore-preflight-errors=FileExisting-crictl\"", true); err != nil { + "--ignore-preflight-errors=FileExisting-crictl", true); err != nil { // kubeadm reset and then retry - _, _ = runtime.GetRunner().Cmd("sudo env PATH=$PATH /bin/sh -c \"/usr/local/bin/kubeadm reset -f\"", true) + _, _ = runtime.GetRunner().SudoCmd("/usr/local/bin/kubeadm reset -f", true) return errors.Wrap(errors.WithStack(err), "init kubernetes cluster failed") } return nil @@ -378,10 +377,10 @@ func (a *AddMasterNode) Execute(runtime connector.Runtime) error { host := runtime.RemoteHost() if v, ok := a.RootCache.Get(ClusterStatus); ok { cluster := v.(*KubernetesStatus) - if _, err := runtime.GetRunner().Cmd(fmt.Sprintf( - "sudo env PATH=$PATH /bin/sh -c \"%s\"", fmt.Sprintf("%s --apiserver-advertise-address %s", cluster.JoinMasterCmd, host.GetInternalAddress())), + if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf( + fmt.Sprintf("%s --apiserver-advertise-address %s", cluster.JoinMasterCmd, host.GetInternalAddress())), true); err != nil { - _, _ = runtime.GetRunner().Cmd("sudo env PATH=$PATH /bin/sh -c \"/usr/local/bin/kubeadm reset -f\"", true) + _, _ = runtime.GetRunner().SudoCmd("/usr/local/bin/kubeadm reset -f", true) return errors.Wrap(errors.WithStack(err), "join master failed") } } @@ -395,8 +394,8 @@ type AddWorkerNode struct { func (a *AddWorkerNode) Execute(runtime connector.Runtime) error { if v, ok := a.RootCache.Get(ClusterStatus); ok { cluster := v.(*KubernetesStatus) - if _, err := runtime.GetRunner().Cmd(fmt.Sprintf("sudo env PATH=$PATH /bin/sh -c \"%s\"", cluster.JoinWorkerCmd), true); err != nil { - _, _ = runtime.GetRunner().Cmd("sudo env PATH=$PATH /bin/sh -c \"/usr/local/bin/kubeadm reset -f\"", true) + if _, err := runtime.GetRunner().SudoCmd(cluster.JoinWorkerCmd, true); err != nil { + _, _ = runtime.GetRunner().SudoCmd("/usr/local/bin/kubeadm reset -f", true) return errors.Wrap(errors.WithStack(err), "join master failed") } }