diff --git a/pkg/bootstrap/confirm/tasks.go b/pkg/bootstrap/confirm/tasks.go index 6b41d62c..4cb3bb96 100644 --- a/pkg/bootstrap/confirm/tasks.go +++ b/pkg/bootstrap/confirm/tasks.go @@ -19,6 +19,10 @@ package confirm import ( "bufio" "fmt" + "os" + "regexp" + "strings" + "github.com/kubesphere/kubekey/pkg/common" "github.com/kubesphere/kubekey/pkg/core/action" "github.com/kubesphere/kubekey/pkg/core/connector" @@ -28,9 +32,6 @@ import ( "github.com/modood/table" "github.com/pkg/errors" versionutil "k8s.io/apimachinery/pkg/util/version" - "os" - "regexp" - "strings" ) // PreCheckResults defines the items to be checked. @@ -82,11 +83,23 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error { if i.KubeConf.Arg.Artifact == "" { for _, host := range results { + if host.Sudo == "" { + fmt.Printf("%s: sudo is required. \n", host.Name) + logger.Log.Errorf("%s: sudo is required. \n", host.Name) + stopFlag = true + } + if host.Conntrack == "" { fmt.Printf("%s: conntrack is required. \n", host.Name) logger.Log.Errorf("%s: conntrack is required. \n", host.Name) stopFlag = true } + + if host.Socat == "" { + fmt.Printf("%s: socat is required. \n", host.Name) + logger.Log.Errorf("%s: socat is required. \n", host.Name) + stopFlag = true + } } if stopFlag { diff --git a/pkg/bootstrap/precheck/tasks.go b/pkg/bootstrap/precheck/tasks.go index c314054e..ea47b652 100644 --- a/pkg/bootstrap/precheck/tasks.go +++ b/pkg/bootstrap/precheck/tasks.go @@ -18,15 +18,16 @@ package precheck import ( "fmt" + "os/exec" + "regexp" + "strings" + "github.com/kubesphere/kubekey/pkg/common" "github.com/kubesphere/kubekey/pkg/core/connector" "github.com/kubesphere/kubekey/pkg/version/kubernetes" "github.com/kubesphere/kubekey/pkg/version/kubesphere" "github.com/pkg/errors" versionutil "k8s.io/apimachinery/pkg/util/version" - "os/exec" - "regexp" - "strings" ) type NodePreCheck struct { @@ -50,7 +51,14 @@ func (n *NodePreCheck) Execute(runtime connector.Runtime) error { cmd = fmt.Sprintf("which %s", software) } - res, err := runtime.GetRunner().SudoCmd(cmd, false) + switch software { + case sudo: + // sudo skip sudo prefix + default: + cmd = connector.SudoPrefix(cmd) + } + + res, err := runtime.GetRunner().Cmd(cmd, false) switch software { case showmount: software = nfs @@ -62,10 +70,13 @@ func (n *NodePreCheck) Execute(runtime connector.Runtime) error { if err != nil || strings.Contains(res, "not found") { results[software] = "" } else { - if strings.HasPrefix(cmd, "which") { - res = "y" + // software in path + if strings.Contains(res, "bin/") { + results[software] = "y" + } else { + // get software version, e.g. docker, containerd, etc. + results[software] = res } - results[software] = res } }