From 7224064b235a84220a0705cba4327a2630ced223 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 27 May 2020 15:19:32 -0700 Subject: [PATCH 1/5] respect native-ssh param properly --- cmd/minikube/cmd/ssh.go | 9 +-------- pkg/minikube/machine/ssh.go | 10 +++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/minikube/cmd/ssh.go b/cmd/minikube/cmd/ssh.go index d365cae360f7..d9ecb5f05690 100644 --- a/cmd/minikube/cmd/ssh.go +++ b/cmd/minikube/cmd/ssh.go @@ -19,7 +19,6 @@ package cmd import ( "os" - "github.com/docker/machine/libmachine/ssh" "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/config" @@ -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) diff --git a/pkg/minikube/machine/ssh.go b/pkg/minikube/machine/ssh.go index 955b2e1a235a..0f991e2f2ce2 100644 --- a/pkg/minikube/machine/ssh.go +++ b/pkg/minikube/machine/ssh.go @@ -18,6 +18,7 @@ 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" @@ -25,7 +26,7 @@ import ( ) // 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 { @@ -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") } From 6f03adc8acbb6ee702bc3edf058b7a55c623d1f6 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 27 May 2020 15:32:56 -0700 Subject: [PATCH 2/5] fix in start.go --- cmd/minikube/cmd/start.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index aef199c8dc44..d32aeb5a44f7 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -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{} @@ -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, From 96f34ea06310fe7e1a76e762f9f837a9fb6e8f85 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 27 May 2020 15:54:07 -0700 Subject: [PATCH 3/5] fix tests --- pkg/minikube/machine/cluster_test.go | 2 +- test/integration/functional_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/minikube/machine/cluster_test.go b/pkg/minikube/machine/cluster_test.go index 6171098932b6..80e5e7389ee4 100644 --- a/pkg/minikube/machine/cluster_test.go +++ b/pkg/minikube/machine/cluster_test.go @@ -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) } diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 60b30113772f..a22cb6f0afa7 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -816,12 +816,12 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { if NoneDriver() { t.Skipf("skipping: ssh unsupported by none") } - want := "hello\n" + want := "hello" rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("echo hello"))) if err != nil { t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err) } - if rr.Stdout.String() != want { + 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()) } } From ee764c8df49b32dc8916b6476ab016c98cc0bb8c Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 27 May 2020 16:54:03 -0700 Subject: [PATCH 4/5] add comment --- test/integration/functional_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index a22cb6f0afa7..9a2685025ea7 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -821,6 +821,7 @@ 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) } + // 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()) } From 12c1d7e249969d51ad97fc2fed19476306846d62 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Wed, 27 May 2020 16:56:54 -0700 Subject: [PATCH 5/5] actually trim --- test/integration/functional_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 3a3f3fe9f497..3c7371cc9622 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -847,7 +847,7 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err) } // trailing whitespace differs between native and external SSH clients, so let's trim it and call it a day - if rr.Stdout.String() != want { + 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()) }