Skip to content

Commit 48fdb95

Browse files
author
Kenichi Omichi
committed
Add common SSHPort on e2essh
There were several sshPort values in e2e test packages because we've migrated code from e2e framework by copying and pastting. This adds common SSHPort on e2essh package to reduce such duplicated code.
1 parent facda9a commit 48fdb95

File tree

5 files changed

+12
-21
lines changed

5 files changed

+12
-21
lines changed

test/e2e/framework/kubesystem/kubesystem.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ import (
2626
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
2727
)
2828

29-
const (
30-
// ssh port
31-
sshPort = "22"
32-
)
33-
3429
// RestartControllerManager restarts the kube-controller-manager.
3530
func RestartControllerManager() error {
3631
// TODO: Make it work for all providers and distros.
@@ -42,7 +37,7 @@ func RestartControllerManager() error {
4237
}
4338
cmd := "pidof kube-controller-manager | xargs sudo kill"
4439
framework.Logf("Restarting controller-manager via ssh, running: %v", cmd)
45-
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
40+
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), e2essh.SSHPort), framework.TestContext.Provider)
4641
if err != nil || result.Code != 0 {
4742
e2essh.LogResult(result)
4843
return fmt.Errorf("couldn't restart controller-manager: %v", err)
@@ -54,7 +49,7 @@ func RestartControllerManager() error {
5449
func WaitForControllerManagerUp() error {
5550
cmd := "curl http://localhost:" + strconv.Itoa(framework.InsecureKubeControllerManagerPort) + "/healthz"
5651
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
57-
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
52+
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), e2essh.SSHPort), framework.TestContext.Provider)
5853
if err != nil || result.Code != 0 {
5954
e2essh.LogResult(result)
6055
}

test/e2e/framework/ssh/ssh.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import (
4040
)
4141

4242
const (
43-
// ssh port
44-
sshPort = "22"
43+
// SSHPort is tcp port number of SSH
44+
SSHPort = "22"
4545

4646
// pollNodeInterval is how often to Poll pods.
4747
pollNodeInterval = 2 * time.Second
@@ -136,7 +136,7 @@ func NodeSSHHosts(c clientset.Interface) ([]string, error) {
136136

137137
sshHosts := make([]string, 0, len(hosts))
138138
for _, h := range hosts {
139-
sshHosts = append(sshHosts, net.JoinHostPort(h, sshPort))
139+
sshHosts = append(sshHosts, net.JoinHostPort(h, SSHPort))
140140
}
141141
return sshHosts, nil
142142
}
@@ -155,7 +155,7 @@ type Result struct {
155155
// eg: the name returned by framework.GetMasterHost(). This is also not guaranteed to work across
156156
// cloud providers since it involves ssh.
157157
func NodeExec(nodeName, cmd, provider string) (Result, error) {
158-
return SSH(cmd, net.JoinHostPort(nodeName, sshPort), provider)
158+
return SSH(cmd, net.JoinHostPort(nodeName, SSHPort), provider)
159159
}
160160

161161
// SSH synchronously SSHs to a node running on provider and runs cmd. If there
@@ -330,7 +330,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*Result, er
330330
host := ""
331331
for _, a := range node.Status.Addresses {
332332
if a.Type == v1.NodeExternalIP && a.Address != "" {
333-
host = net.JoinHostPort(a.Address, sshPort)
333+
host = net.JoinHostPort(a.Address, SSHPort)
334334
break
335335
}
336336
}
@@ -339,7 +339,7 @@ func IssueSSHCommandWithResult(cmd, provider string, node *v1.Node) (*Result, er
339339
// No external IPs were found, let's try to use internal as plan B
340340
for _, a := range node.Status.Addresses {
341341
if a.Type == v1.NodeInternalIP && a.Address != "" {
342-
host = net.JoinHostPort(a.Address, sshPort)
342+
host = net.JoinHostPort(a.Address, SSHPort)
343343
break
344344
}
345345
}

test/e2e/network/service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ const (
8787
// AffinityConfirmCount is the number of needed continuous requests to confirm that
8888
// affinity is enabled.
8989
AffinityConfirmCount = 15
90-
91-
// ssh port
92-
sshPort = "22"
9390
)
9491

9592
var (
@@ -3587,7 +3584,7 @@ func sshRestartMaster() error {
35873584
command = "sudo /etc/init.d/kube-apiserver restart"
35883585
}
35893586
framework.Logf("Restarting master via ssh, running: %v", command)
3590-
result, err := e2essh.SSH(command, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
3587+
result, err := e2essh.SSH(command, net.JoinHostPort(framework.GetMasterHost(), e2essh.SSHPort), framework.TestContext.Provider)
35913588
if err != nil || result.Code != 0 {
35923589
e2essh.LogResult(result)
35933590
return fmt.Errorf("couldn't restart apiserver: %v", err)

test/e2e/storage/flexvolume.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
)
3939

4040
const (
41-
sshPort = "22"
4241
driverDir = "test/e2e/testing-manifests/flexvolume/"
4342
defaultVolumePluginDir = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
4443
// TODO: change this and config-test.sh when default flex volume install path is changed for GCI
@@ -84,7 +83,7 @@ func installFlex(c clientset.Interface, node *v1.Node, vendor, driver, filePath
8483
} else {
8584
masterHostWithPort := framework.GetMasterHost()
8685
hostName := getHostFromHostPort(masterHostWithPort)
87-
host = net.JoinHostPort(hostName, sshPort)
86+
host = net.JoinHostPort(hostName, e2essh.SSHPort)
8887
}
8988

9089
framework.ExpectNoError(err)
@@ -113,7 +112,7 @@ func uninstallFlex(c clientset.Interface, node *v1.Node, vendor, driver string)
113112
} else {
114113
masterHostWithPort := framework.GetMasterHost()
115114
hostName := getHostFromHostPort(masterHostWithPort)
116-
host = net.JoinHostPort(hostName, sshPort)
115+
host = net.JoinHostPort(hostName, e2essh.SSHPort)
117116
}
118117

119118
if host == "" {

test/e2e/storage/nfs_persistent_volume-disruptive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func checkForControllerManagerHealthy(duration time.Duration) error {
5252
var PID string
5353
cmd := "pidof kube-controller-manager"
5454
for start := time.Now(); time.Since(start) < duration; time.Sleep(5 * time.Second) {
55-
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
55+
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), e2essh.SSHPort), framework.TestContext.Provider)
5656
if err != nil {
5757
// We don't necessarily know that it crashed, pipe could just be broken
5858
e2essh.LogResult(result)

0 commit comments

Comments
 (0)