From 266080e18d8eede6d5aaef045a230f6ce8e4caf8 Mon Sep 17 00:00:00 2001 From: John Schnake Date: Mon, 17 Sep 2018 14:51:28 -0500 Subject: [PATCH] Make SSH path handling consistent across providers during e2e There were providers which would: - allow overrides of the file base name but not the path - allow oeverrides of the file path - not allow any overrides at all This change makes it such that each of the supported providers can override the SSH key location using an env var. The env var itself may vary based on the provider though. If given an absolute path to the key, it is used. If given a relative path it will be made relative to ~/.ssh Fixes: #68747 --- test/e2e/framework/util.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 08b2f21827f..b71ed47ff1b 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -3530,44 +3530,43 @@ func DeletePodOrFail(c clientset.Interface, ns, name string) { // GetSigner returns an ssh.Signer for the provider ("gce", etc.) that can be // used to SSH to their nodes. func GetSigner(provider string) (ssh.Signer, error) { - // Get the directory in which SSH keys are located. - keydir := filepath.Join(os.Getenv("HOME"), ".ssh") - // Select the key itself to use. When implementing more providers here, // please also add them to any SSH tests that are disabled because of signer // support. keyfile := "" - key := "" switch provider { case "gce", "gke", "kubemark": - keyfile = "google_compute_engine" - case "aws": - // If there is an env. variable override, use that. - aws_keyfile := os.Getenv("AWS_SSH_KEY") - if len(aws_keyfile) != 0 { - return sshutil.MakePrivateKeySignerFromFile(aws_keyfile) + keyfile = os.Getenv("GCE_SSH_KEY") + if keyfile == "" { + keyfile = "google_compute_engine" + } + case "aws": + keyfile = os.Getenv("AWS_SSH_KEY") + if keyfile == "" { + keyfile = "kube_aws_rsa" } - // Otherwise revert to home dir - keyfile = "kube_aws_rsa" case "local", "vsphere": - keyfile = os.Getenv("LOCAL_SSH_KEY") // maybe? - if len(keyfile) == 0 { + keyfile = os.Getenv("LOCAL_SSH_KEY") + if keyfile == "" { keyfile = "id_rsa" } case "skeleton": keyfile = os.Getenv("KUBE_SSH_KEY") - if len(keyfile) == 0 { + if keyfile == "" { keyfile = "id_rsa" } default: return nil, fmt.Errorf("GetSigner(...) not implemented for %s", provider) } - if len(key) == 0 { - key = filepath.Join(keydir, keyfile) + // Respect absolute paths for keys given by user, fallback to assuming + // relative paths are in ~/.ssh + if !filepath.IsAbs(keyfile) { + keydir := filepath.Join(os.Getenv("HOME"), ".ssh") + keyfile = filepath.Join(keydir, keyfile) } - return sshutil.MakePrivateKeySignerFromFile(key) + return sshutil.MakePrivateKeySignerFromFile(keyfile) } // CheckPodsRunningReady returns whether all pods whose names are listed in