mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Check the private SSH key existence in the node e2e tests
This commit is contained in:
parent
e31aafc4fd
commit
db4a743b77
@ -103,9 +103,12 @@ func SSHNoSudo(host string, cmd ...string) (string, error) {
|
|||||||
|
|
||||||
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options
|
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options
|
||||||
func runSSHCommand(cmd string, args ...string) (string, error) {
|
func runSSHCommand(cmd string, args ...string) (string, error) {
|
||||||
if *sshKey != "" {
|
if key := getPrivateSSHKey(); len(key) != 0 {
|
||||||
args = append([]string{"-i", *sshKey}, args...)
|
if _, err := os.Stat(key); err != nil {
|
||||||
} else if key, found := sshDefaultKeyMap[*sshEnv]; found {
|
klog.Errorf("private SSH key (%s) not found. Check if the SSH key is configured properly:, err: %v", key, err)
|
||||||
|
return "", fmt.Errorf("private SSH key (%s) does not exist", key)
|
||||||
|
}
|
||||||
|
|
||||||
args = append([]string{"-i", key}, args...)
|
args = append([]string{"-i", key}, args...)
|
||||||
}
|
}
|
||||||
if env, found := sshOptionsMap[*sshEnv]; found {
|
if env, found := sshOptionsMap[*sshEnv]; found {
|
||||||
@ -122,3 +125,16 @@ func runSSHCommand(cmd string, args ...string) (string, error) {
|
|||||||
}
|
}
|
||||||
return string(output), nil
|
return string(output), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPrivateSSHKey returns the path to ssh private key
|
||||||
|
func getPrivateSSHKey() string {
|
||||||
|
if *sshKey != "" {
|
||||||
|
return *sshKey
|
||||||
|
}
|
||||||
|
|
||||||
|
if key, found := sshDefaultKeyMap[*sshEnv]; found {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user