Skip to content

Commit

Permalink
fix(autok3s): fix ssh command input not work
Browse files Browse the repository at this point in the history
Signed-off-by: NewGr8Player <273221594@qq.com>
  • Loading branch information
NewGr8Player authored and rancher-sy-bot committed Oct 14, 2020
1 parent b667789 commit c720981
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func SSHCommand() *cobra.Command {

sp.GenerateClusterName()

if err := sp.SSHK3sNode(); err != nil {
if err := sp.SSHK3sNode(sSSH); err != nil {
logrus.Fatalln(err)
}
}
Expand Down
30 changes: 29 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,49 @@ func JoinK3sNode(merged, added *types.Cluster) error {
return nil
}

func SSHK3sNode(ip string, cluster *types.Cluster) error {
func SSHK3sNode(ip string, cluster *types.Cluster, ssh *types.SSH) error {
var node types.Node

for _, n := range cluster.Status.MasterNodes {
if n.PublicIPAddress[0] == ip {
node = n
break
}
}

for _, n := range cluster.Status.WorkerNodes {
if n.PublicIPAddress[0] == ip {
node = n
break
}
}

node.SSH.User = ssh.User
node.SSH.Port = ssh.Port
if ssh.Password != "" {
node.SSH.Password = ssh.Password
}
if ssh.SSHKey != "" {
node.SSH.SSHKey = ssh.SSHKey
}
if ssh.SSHKeyPath != "" {
node.SSH.SSHKeyPath = ssh.SSHKeyPath
}
if ssh.SSHCert != "" {
node.SSH.SSHCert = ssh.SSHCert
}
if ssh.SSHCertPath != "" {
node.SSH.SSHCertPath = ssh.SSHCertPath
}
if ssh.SSHKeyPassphrase != "" {
node.SSH.SSHKeyPassphrase = ssh.SSHKeyPassphrase
}
if ssh.SSHAgentAuth {
node.SSH.SSHAgentAuth = ssh.SSHAgentAuth
}
if node.PublicIPAddress == nil {
node.PublicIPAddress = []string{ip}
}
return terminal(&hosts.Host{Node: node})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (p *Alibaba) StopK3sCluster(f bool) error {
return nil
}

func (p *Alibaba) SSHK3sNode() error {
func (p *Alibaba) SSHK3sNode(ssh *types.SSH) error {
p.logger = common.NewLogger(common.Debug)
p.logger.Infof("[%s] executing ssh logic...\n", p.GetProviderName())

Expand Down Expand Up @@ -397,7 +397,7 @@ func (p *Alibaba) SSHK3sNode() error {
}

// ssh K3s node.
if err := cluster.SSHK3sNode(ip, c); err != nil {
if err := cluster.SSHK3sNode(ip, c, ssh); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (p *Native) JoinK3sNode(ssh *types.SSH) (err error) {
return nil
}

func (p *Native) SSHK3sNode() error {
func (p *Native) SSHK3sNode(ssh *types.SSH) error {
p.logger = common.NewLogger(common.Debug)
p.logger.Infof("[%s] executing ssh logic...\n", p.GetProviderName())

Expand All @@ -218,7 +218,7 @@ func (p *Native) SSHK3sNode() error {
return fmt.Errorf("[%s] choose incorrect ssh node", p.GetProviderName())
}
// ssh K3s node.
if err := cluster.SSHK3sNode(ip, c); err != nil {
if err := cluster.SSHK3sNode(ip, c, ssh); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Provider interface {
// K3s stop cluster interface.
StopK3sCluster(f bool) error
// K3s ssh node interface.
SSHK3sNode() error
SSHK3sNode(ssh *types.SSH) error
// K3s check cluster exist.
IsClusterExist() (bool, []string, error)
// Rollback when error occurs.
Expand Down

0 comments on commit c720981

Please sign in to comment.