Skip to content

Commit 2306621

Browse files
author
Kenichi Omichi
committed
Move RestartKubelet() into e2e/storage/vsphere
Since 4e7c2f6 the function has been called from storage vsphere e2e test only. This moves the function into the test file for - Reducing test/e2e/framework/util.go which is one of huge files - Remove invalid dependency on e2e test framework - Remove unnecessary TODO
1 parent 283b958 commit 2306621

File tree

2 files changed

+36
-48
lines changed

2 files changed

+36
-48
lines changed

test/e2e/framework/util.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,53 +1179,6 @@ func AllNodesReady(c clientset.Interface, timeout time.Duration) error {
11791179
return nil
11801180
}
11811181

1182-
// RestartKubelet restarts kubelet on the given host.
1183-
func RestartKubelet(host string) error {
1184-
// TODO: Make it work for all providers and distros.
1185-
supportedProviders := []string{"gce", "aws", "vsphere"}
1186-
if !ProviderIs(supportedProviders...) {
1187-
return fmt.Errorf("unsupported provider for RestartKubelet: %s, supported providers are: %v", TestContext.Provider, supportedProviders)
1188-
}
1189-
if ProviderIs("gce") && !NodeOSDistroIs("debian", "gci") {
1190-
return fmt.Errorf("unsupported node OS distro: %s", TestContext.NodeOSDistro)
1191-
}
1192-
var cmd string
1193-
1194-
if ProviderIs("gce") && NodeOSDistroIs("debian") {
1195-
cmd = "sudo /etc/init.d/kubelet restart"
1196-
} else if ProviderIs("vsphere") {
1197-
var sudoPresent bool
1198-
sshResult, err := e2essh.SSH("sudo --version", host, TestContext.Provider)
1199-
if err != nil {
1200-
return fmt.Errorf("Unable to ssh to host %s with error %v", host, err)
1201-
}
1202-
if !strings.Contains(sshResult.Stderr, "command not found") {
1203-
sudoPresent = true
1204-
}
1205-
sshResult, err = e2essh.SSH("systemctl --version", host, TestContext.Provider)
1206-
if err != nil {
1207-
return fmt.Errorf("Failed to execute command 'systemctl' on host %s with error %v", host, err)
1208-
}
1209-
if !strings.Contains(sshResult.Stderr, "command not found") {
1210-
cmd = "systemctl restart kubelet"
1211-
} else {
1212-
cmd = "service kubelet restart"
1213-
}
1214-
if sudoPresent {
1215-
cmd = fmt.Sprintf("sudo %s", cmd)
1216-
}
1217-
} else {
1218-
cmd = "sudo systemctl restart kubelet"
1219-
}
1220-
Logf("Restarting kubelet via ssh on host %s with command %s", host, cmd)
1221-
result, err := e2essh.SSH(cmd, host, TestContext.Provider)
1222-
if err != nil || result.Code != 0 {
1223-
e2essh.LogResult(result)
1224-
return fmt.Errorf("couldn't restart kubelet: %v", err)
1225-
}
1226-
return nil
1227-
}
1228-
12291182
// RestartApiserver restarts the kube-apiserver.
12301183
func RestartApiserver(namespace string, cs clientset.Interface) error {
12311184
// TODO: Make it work for all providers.

test/e2e/storage/vsphere/vsphere_volume_master_restart.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"strconv"
23+
"strings"
2324
"time"
2425

2526
"github.com/onsi/ginkgo"
@@ -53,6 +54,40 @@ func waitForKubeletUp(host string) error {
5354
return fmt.Errorf("waiting for kubelet timed out")
5455
}
5556

57+
// restartKubelet restarts kubelet on the given host.
58+
func restartKubelet(host string) error {
59+
var cmd string
60+
61+
var sudoPresent bool
62+
sshResult, err := e2essh.SSH("sudo --version", host, framework.TestContext.Provider)
63+
if err != nil {
64+
return fmt.Errorf("Unable to ssh to host %s with error %v", host, err)
65+
}
66+
if !strings.Contains(sshResult.Stderr, "command not found") {
67+
sudoPresent = true
68+
}
69+
sshResult, err = e2essh.SSH("systemctl --version", host, framework.TestContext.Provider)
70+
if err != nil {
71+
return fmt.Errorf("Failed to execute command 'systemctl' on host %s with error %v", host, err)
72+
}
73+
if !strings.Contains(sshResult.Stderr, "command not found") {
74+
cmd = "systemctl restart kubelet"
75+
} else {
76+
cmd = "service kubelet restart"
77+
}
78+
if sudoPresent {
79+
cmd = fmt.Sprintf("sudo %s", cmd)
80+
}
81+
82+
framework.Logf("Restarting kubelet via ssh on host %s with command %s", host, cmd)
83+
result, err := e2essh.SSH(cmd, host, framework.TestContext.Provider)
84+
if err != nil || result.Code != 0 {
85+
e2essh.LogResult(result)
86+
return fmt.Errorf("couldn't restart kubelet: %v", err)
87+
}
88+
return nil
89+
}
90+
5691
/*
5792
Test to verify volume remains attached after kubelet restart on master node
5893
For the number of schedulable nodes,
@@ -134,7 +169,7 @@ var _ = utils.SIGDescribe("Volume Attach Verify [Feature:vsphere][Serial][Disrup
134169

135170
ginkgo.By("Restarting kubelet on master node")
136171
masterAddress := framework.GetMasterHost() + ":22"
137-
err := framework.RestartKubelet(masterAddress)
172+
err := restartKubelet(masterAddress)
138173
framework.ExpectNoError(err, "Unable to restart kubelet on master node")
139174

140175
ginkgo.By("Verifying the kubelet on master node is up")

0 commit comments

Comments
 (0)