Merge pull request #103815 from saschagrunert/ssh-port

Fix SIG Node SSH e2e test
This commit is contained in:
Kubernetes Prow Robot 2021-07-21 08:28:07 -07:00 committed by GitHub
commit 185d2e076f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -49,6 +49,9 @@ const (
// singleCallTimeout is how long to try single API calls (like 'get' or 'list'). Used to prevent // singleCallTimeout is how long to try single API calls (like 'get' or 'list'). Used to prevent
// transient failures from failing tests. // transient failures from failing tests.
singleCallTimeout = 5 * time.Minute singleCallTimeout = 5 * time.Minute
// sshBastionEnvKey is the environment variable key for running SSH commands via bastion.
sshBastionEnvKey = "KUBE_SSH_BASTION"
) )
// GetSigner returns an ssh.Signer for the provider ("gce", etc.) that can be // GetSigner returns an ssh.Signer for the provider ("gce", etc.) that can be
@ -160,9 +163,13 @@ func NodeSSHHosts(c clientset.Interface) ([]string, error) {
// canConnect returns true if a network connection is possible to the SSHPort. // canConnect returns true if a network connection is possible to the SSHPort.
func canConnect(host string) bool { func canConnect(host string) bool {
if _, ok := os.LookupEnv(sshBastionEnvKey); ok {
return true
}
hostPort := net.JoinHostPort(host, SSHPort) hostPort := net.JoinHostPort(host, SSHPort)
conn, err := net.DialTimeout("tcp", hostPort, 3*time.Second) conn, err := net.DialTimeout("tcp", hostPort, 3*time.Second)
if err != nil { if err != nil {
e2elog.Logf("cannot dial %s: %v", hostPort, err)
return false return false
} }
conn.Close() conn.Close()
@ -205,7 +212,7 @@ func SSH(cmd, host, provider string) (Result, error) {
result.User = os.Getenv("USER") result.User = os.Getenv("USER")
} }
if bastion := os.Getenv("KUBE_SSH_BASTION"); len(bastion) > 0 { if bastion := os.Getenv(sshBastionEnvKey); len(bastion) > 0 {
stdout, stderr, code, err := runSSHCommandViaBastion(cmd, result.User, bastion, host, signer) stdout, stderr, code, err := runSSHCommandViaBastion(cmd, result.User, bastion, host, signer)
result.Stdout = stdout result.Stdout = stdout
result.Stderr = stderr result.Stderr = stderr

View File

@ -49,6 +49,7 @@ var _ = SIGDescribe("SSH", func() {
if err != nil { if err != nil {
framework.Failf("Error getting node hostnames: %v", err) framework.Failf("Error getting node hostnames: %v", err)
} }
ginkgo.By(fmt.Sprintf("Found %d SSH'able hosts", len(hosts)))
testCases := []struct { testCases := []struct {
cmd string cmd string
@ -79,6 +80,8 @@ var _ = SIGDescribe("SSH", func() {
ginkgo.By(fmt.Sprintf("SSH'ing to %d nodes and running %s", len(testhosts), testCase.cmd)) ginkgo.By(fmt.Sprintf("SSH'ing to %d nodes and running %s", len(testhosts), testCase.cmd))
for _, host := range testhosts { for _, host := range testhosts {
ginkgo.By(fmt.Sprintf("SSH'ing host %s", host))
result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider) result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider)
stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr) stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr)
if err != testCase.expectedError { if err != testCase.expectedError {