Skip to content
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

respect native-ssh param properly #8290

Merged
merged 6 commits into from
May 28, 2020
Merged
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
9 changes: 1 addition & 8 deletions cmd/minikube/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cmd
import (
"os"

"github.com/docker/machine/libmachine/ssh"
"github.com/spf13/cobra"

"k8s.io/minikube/pkg/minikube/config"
Expand Down Expand Up @@ -58,13 +57,7 @@ var sshCmd = &cobra.Command{
}
}

if nativeSSHClient {
ssh.SetDefaultClient(ssh.Native)
} else {
ssh.SetDefaultClient(ssh.External)
}

err = machine.CreateSSHShell(co.API, *co.Config, *n, args)
err = machine.CreateSSHShell(co.API, *co.Config, *n, args, nativeSSHClient)
if err != nil {
// This is typically due to a non-zero exit code, so no need for flourish.
out.ErrLn("ssh: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
cc.MinikubeISO = url
}

if viper.GetBool(nativeSSH) {
ssh.SetDefaultClient(ssh.Native)
} else {
ssh.SetDefaultClient(ssh.External)
}

var existingAddons map[string]bool
if viper.GetBool(installAddons) {
existingAddons = map[string]bool{}
Expand All @@ -265,6 +259,12 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
return node.Starter{}, err
}

if viper.GetBool(nativeSSH) {
ssh.SetDefaultClient(ssh.Native)
} else {
ssh.SetDefaultClient(ssh.External)
}

return node.Starter{
Runner: mRunner,
PreExists: preExists,
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/machine/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func TestCreateSSHShell(t *testing.T) {
cc.Name = viper.GetString("profile")

cliArgs := []string{"exit"}
if err := CreateSSHShell(api, cc, config.Node{Name: "minikube"}, cliArgs); err != nil {
if err := CreateSSHShell(api, cc, config.Node{Name: "minikube"}, cliArgs, true); err != nil {
t.Fatalf("Error running ssh command: %v", err)
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/minikube/machine/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package machine

import (
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
)

// CreateSSHShell creates a new SSH shell / client
func CreateSSHShell(api libmachine.API, cc config.ClusterConfig, n config.Node, args []string) error {
func CreateSSHShell(api libmachine.API, cc config.ClusterConfig, n config.Node, args []string, native bool) error {
machineName := driver.MachineName(cc, n)
host, err := LoadHost(api, machineName)
if err != nil {
Expand All @@ -42,6 +43,13 @@ func CreateSSHShell(api libmachine.API, cc config.ClusterConfig, n config.Node,
}

client, err := host.CreateSSHClient()

if native {
ssh.SetDefaultClient(ssh.Native)
} else {
ssh.SetDefaultClient(ssh.External)
}

if err != nil {
return errors.Wrap(err, "Creating ssh client")
}
Expand Down
10 changes: 6 additions & 4 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
mctx, cancel := context.WithTimeout(ctx, Minutes(1))
defer cancel()

want := "hello\n"
want := "hello"

rr, err := Run(t, exec.CommandContext(mctx, Target(), "-p", profile, "ssh", "echo hello"))
if mctx.Err() == context.DeadlineExceeded {
Expand All @@ -846,15 +846,16 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
if err != nil {
t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err)
}
if rr.Stdout.String() != want {
// trailing whitespace differs between native and external SSH clients, so let's trim it and call it a day
if strings.TrimSpace(rr.Stdout.String()) != want {
t.Errorf("expected minikube ssh command output to be -%q- but got *%q*. args %q", want, rr.Stdout.String(), rr.Command())
}

// testing hostname as well because testing something like "minikube ssh echo" could be confusing
// because it is not clear if echo was run inside minikube on the powershell
// so better to test something inside minikube, that is meaningful per profile
// in this case /etc/hostname is same as the profile name
want = profile + "\n"
want = profile
rr, err = Run(t, exec.CommandContext(mctx, Target(), "-p", profile, "ssh", "cat /etc/hostname"))
if mctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
Expand All @@ -863,7 +864,8 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
if err != nil {
t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err)
}
if rr.Stdout.String() != want {
// trailing whitespace differs between native and external SSH clients, so let's trim it and call it a day
if strings.TrimSpace(rr.Stdout.String()) != want {
t.Errorf("expected minikube ssh command output to be -%q- but got *%q*. args %q", want, rr.Stdout.String(), rr.Command())
}
}
Expand Down