Merge pull request #1237 from 24sama/patch-1

add auto-generate local ssh key in "localRuntime"
This commit is contained in:
KubeSphere CI Bot 2022-04-23 21:29:42 +08:00 committed by GitHub
commit e2622aca1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -84,27 +84,20 @@ 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)
logger.Log.Errorf("%s: sudo is required.", 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)
logger.Log.Errorf("%s: conntrack is required.", 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)
logger.Log.Errorf("%s: socat is required.", host.Name)
stopFlag = true
}
}
if stopFlag {
os.Exit(1)
}
}
fmt.Println("")
@ -113,6 +106,10 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error {
fmt.Println("https://github.com/kubesphere/kubekey#requirements-and-recommendations")
fmt.Println("")
if stopFlag {
os.Exit(1)
}
confirmOK := false
for !confirmOK {
fmt.Printf("Continue this installation? [yes/no]: ")

View File

@ -20,7 +20,9 @@ import (
"fmt"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/core/util"
"github.com/pkg/errors"
"os"
"os/exec"
"os/user"
"runtime"
)
@ -39,6 +41,13 @@ func NewLocalRuntime(debug, ingoreErr bool) (LocalRuntime, error) {
return localRuntime, fmt.Errorf("current user is %s. Please use root", u.Username)
}
if output, err := exec.Command("/bin/sh", "-c", "if [ ! -f \"$HOME/.ssh/id_rsa\" ]; then ssh-keygen -t rsa -P \"\" -f $HOME/.ssh/id_rsa && ls $HOME/.ssh;fi;").CombinedOutput(); err != nil {
return localRuntime, errors.New(fmt.Sprintf("Failed to generate public key: %v\n%s", err, string(output)))
}
if output, err := exec.Command("/bin/sh", "-c", "echo \"\n$(cat $HOME/.ssh/id_rsa.pub)\" >> $HOME/.ssh/authorized_keys && awk ' !x[$0]++{print > \"'$HOME'/.ssh/authorized_keys\"}' $HOME/.ssh/authorized_keys").CombinedOutput(); err != nil {
return localRuntime, errors.New(fmt.Sprintf("Failed to copy public key to authorized_keys: %v\n%s", err, string(output)))
}
name, err := os.Hostname()
if err != nil {
return localRuntime, err