8000 [dhctl] Implement native SSH client by YuryLysov · Pull Request #13240 · deckhouse/deckhouse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[dhctl] Implement native SSH client #13240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function main() {
while true
do
# Emulate pkill -U $local_user_id
ps aux | grep "^$(id -nu $local_user_id)" | awk '{print $2}' | xargs kill -9
ps -u "$(id -nu $local_user_id)" --no-headers | awk '{print $1}' | xargs kill -9

if userdel -r "$(id -nu $local_user_id)"; then
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ for user in `cat /etc/passwd |grep "created by deckhouse" |egrep -o "^[^:]+"`; d
done
rm -rf /home/deckhouse

# remove d8-dhctl-converger

if [[ `getent passwd d8-dhctl-converger` ]]
then
cat <<'EOF2' >> /root/cleanup.sh
#!/bin/bash

userdel d8-dhctl-converger
(cat /root/old_crontab) | crontab -
rm -f /root/old_crontab
rm -f /root/cleanup.sh
EOF2
chmod +x /root/cleanup.sh
crontab -l 2>/dev/null > /root/old_crontab
(crontab -l 2>/dev/null; echo "@reboot /root/cleanup.sh") | crontab -
fi

shutdown -r -t 5
EOF
{{- end }}
2 changes: 2 additions & 0 deletions candi/bashible/preflight/check_reverse_tunnel_open.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
{{- $python_discovery := .Files.Get "deckhouse/candi/bashible/check_python.sh.tpl" }}
{{- tpl ( $python_discovery ) . | nindent 0 }}

check_python

cat - <<EOF | $python_binary
import ssl
try:
Expand Down
8 changes: 7 additions & 1 deletion candi/openapi/dhctl/ssh_configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ apiVersions:
description: |
General dhctl SSH config.
additionalProperties: false
required: [apiVersion, kind, sshUser, sshAgentPrivateKeys]
anyOf:
- required: [apiVersion, kind, sshUser, sshAgentPrivateKeys]
- required: [apiVersion, kind, sshUser, sudoPassword]
x-examples:
- apiVersion: dhctl.deckhouse.io/v1
kind: SSHConfig
Expand Down Expand Up @@ -48,6 +50,10 @@ apiVersions:
type: integer
sshBastionUser:
type: string
sshBastionPassword:
type: string
description: |
A password for the bastion user.
sudoPassword:
description: |
A sudo password for the user.
Expand Down
43 changes: 36 additions & 7 deletions dhctl/cmd/dhctl/commands/bootstrap/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"github.com/deckhouse/deckhouse/dhctl/pkg/app"
"github.com/deckhouse/deckhouse/dhctl/pkg/config"
"github.com/deckhouse/deckhouse/dhctl/pkg/operations/bootstrap"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/clissh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/gossh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/ssh"
)

Expand All @@ -36,9 +39,13 @@ func DefineBootstrapInstallDeckhouseCommand(cmd *kingpin.CmdClause) *kingpin.Cmd
app.DefineDeckhouseInstallFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
var sshClient *ssh.Client
var sshClient node.SSHClient
if len(app.SSHHosts) != 0 {
sshClient = ssh.NewClientFromFlags()
if app.SSHLegacyMode {
sshClient = clissh.NewClientFromFlags()
} else {
sshClient = gossh.NewClientFromFlags()
}
}

bootstraper := bootstrap.NewClusterBootstrapper(&bootstrap.Params{
Expand All @@ -57,7 +64,14 @@ func DefineBootstrapExecuteBashibleCommand(cmd *kingpin.CmdClause) *kingpin.CmdC
app.DefineBashibleBundleFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewClientFromFlagsWithHosts()
var sshClient node.SSHClient
var err error
if app.SSHLegacyMode {
sshClient, err = clissh.NewClientFromFlagsWithHosts()
} else {
sshClient, err = gossh.NewClientFromFlagsWithHosts()
}

if err != nil {
return fmt.Errorf("unable to create ssh-client: %w", err)
}
Expand All @@ -79,9 +93,13 @@ func DefineCreateResourcesCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
app.DefineKubeFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
var sshClient *ssh.Client
var sshClient node.SSHClient
if len(app.SSHHosts) != 0 {
sshClient = ssh.NewClientFromFlags()
if app.SSHLegacyMode {
sshClient = clissh.NewClientFromFlags()
} else {
sshClient = gossh.NewClientFromFlags()
}
}

bootstraper := bootstrap.NewClusterBootstrapper(&bootstrap.Params{
Expand All @@ -102,7 +120,12 @@ func DefineBootstrapAbortCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
app.DefineAbortFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient := ssh.NewClientFromFlags()
var sshClient node.SSHClient
if app.SSHLegacyMode {
sshClient = clissh.NewClientFromFlags()
} else {
sshClient = gossh.NewClientFromFlags()
}
bootstraper := bootstrap.NewClusterBootstrapper(&bootstrap.Params{
NodeInterface: ssh.NewNodeInterfaceWrapper(sshClient),
})
Expand Down Expand Up @@ -131,7 +154,13 @@ func DefineExecPostBootstrapScript(cmd *kingpin.CmdClause) *kingpin.CmdClause {
app.DefinePostBootstrapScriptFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewClientFromFlagsWithHosts()
var sshClient node.SSHClient
var err error
if app.SSHLegacyMode {
sshClient, err = clissh.NewClientFromFlagsWithHosts()
} else {
sshClient, err = gossh.NewClientFromFlagsWithHosts()
}
if err != nil {
return fmt.Errorf("unable to create ssh-client: %w", err)
}
Expand Down
37 changes: 35 additions & 2 deletions dhctl/cmd/dhctl/commands/control-plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import (
"github.com/deckhouse/deckhouse/dhctl/pkg/log"
"github.com/deckhouse/deckhouse/dhctl/pkg/operations/converge/infrastructure/hook"
"github.com/deckhouse/deckhouse/dhctl/pkg/operations/converge/infrastructure/hook/controlplane"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/clissh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/gossh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/ssh"
"github.com/deckhouse/deckhouse/dhctl/pkg/terminal"
)

func DefineTestControlPlaneManagerReadyCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
Expand All @@ -37,7 +41,22 @@ func DefineTestControlPlaneManagerReadyCommand(cmd *kingpin.CmdClause) *kingpin.
app.DefineControlPlaneFlags(cmd, false)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient
var err error

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}

if err != nil {
return err
}
Expand Down Expand Up @@ -76,7 +95,21 @@ func DefineTestControlPlaneNodeReadyCommand(cmd *kingpin.CmdClause) *kingpin.Cmd
app.DefineControlPlaneFlags(cmd, true)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient
var err error

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}
if err != nil {
return err
}
Expand Down
42 changes: 39 additions & 3 deletions dhctl/cmd/dhctl/commands/converge.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ package commands

import (
"context"
"reflect"

kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/deckhouse/deckhouse/dhctl/pkg/app"
"github.com/deckhouse/deckhouse/dhctl/pkg/config"
"github.com/deckhouse/deckhouse/dhctl/pkg/infrastructure"
"github.com/deckhouse/deckhouse/dhctl/pkg/operations/converge"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/ssh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/clissh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/gossh"
"github.com/deckhouse/deckhouse/dhctl/pkg/terminal"
)

func DefineConvergeCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
Expand All @@ -32,7 +36,21 @@ func DefineConvergeCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
app.DefineKubeFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient
var err error

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -88,11 +106,29 @@ func DefineConvergeMigrationCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
app.DefineCheckHasTerraformStateBeforeMigrateToTofu(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient
var err error

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}
if err != nil {
return err
}

if reflect.ValueOf(sshClient).IsNil() {
sshClient = nil
}

converger := converge.NewConverger(&converge.Params{
SSHClient: sshClient,
ChangesSettings: infrastructure.ChangeActionSettings{
Expand Down
35 changes: 33 additions & 2 deletions dhctl/cmd/dhctl/commands/deckhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import (
"github.com/deckhouse/deckhouse/dhctl/pkg/kubernetes/actions/deckhouse"
"github.com/deckhouse/deckhouse/dhctl/pkg/kubernetes/client"
"github.com/deckhouse/deckhouse/dhctl/pkg/log"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/clissh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/gossh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/ssh"
"github.com/deckhouse/deckhouse/dhctl/pkg/terminal"
)

func DefineDeckhouseRemoveDeployment(cmd *kingpin.CmdClause) *kingpin.CmdClause {
Expand All @@ -35,7 +39,21 @@ func DefineDeckhouseRemoveDeployment(cmd *kingpin.CmdClause) *kingpin.CmdClause
app.DefineKubeFlags(cmd)

cmd.Action(func(c *kingpin.ParseContext) error {
sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient
var err error

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}

err = log.Process("default", "Remove Deckhouse️", func() error {
kubeCl := client.NewKubernetesClient().
Expand Down Expand Up @@ -81,7 +99,20 @@ func DefineDeckhouseCreateDeployment(cmd *kingpin.CmdClause) *kingpin.CmdClause
return err
}

sshClient, err := ssh.NewInitClientFromFlags(true)
var sshClient node.SSHClient

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient, err = clissh.NewInitClientFromFlags(true)
} else {
sshClient, err = gossh.NewInitClientFromFlags(true)
}
if err != nil {
return err
}
Expand Down
20 changes: 17 additions & 3 deletions dhctl/cmd/dhctl/commands/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"github.com/deckhouse/deckhouse/dhctl/pkg/log"
"github.com/deckhouse/deckhouse/dhctl/pkg/operations/destroy"
"github.com/deckhouse/deckhouse/dhctl/pkg/state/cache"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/clissh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/gossh"
"github.com/deckhouse/deckhouse/dhctl/pkg/system/node/ssh"
"github.com/deckhouse/deckhouse/dhctl/pkg/terminal"
"github.com/deckhouse/deckhouse/dhctl/pkg/util/input"
Expand Down Expand Up @@ -58,11 +61,22 @@ func DefineDestroyCommand(cmd *kingpin.CmdClause) *kingpin.CmdClause {
}
}

sshClient, err := ssh.NewClientFromFlags().Start()
if err != nil {
var sshClient node.SSHClient

if err := terminal.AskBecomePassword(); err != nil {
return err
}
if err := terminal.AskBecomePassword(); err != nil {
if err := terminal.AskBastionPassword(); err != nil {
return err
}

if app.SSHLegacyMode {
sshClient = clissh.NewClientFromFlags()
} else {
sshClient = gossh.NewClientFromFlags()
}
err := sshClient.Start()
if err != nil {
return err
}

Expand Down
Loading
Loading
0