mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Add support for stopping kubelet in node-e2e
This makes it possible to stop the kubelet, do some work, and then start it again.
This commit is contained in:
parent
2830827442
commit
8b6160a367
@ -373,18 +373,34 @@ func getCRIClient() (internalapi.RuntimeService, internalapi.ImageManagerService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Find a uniform way to deal with systemctl/initctl/service operations. #34494
|
// TODO: Find a uniform way to deal with systemctl/initctl/service operations. #34494
|
||||||
func restartKubelet() {
|
func findRunningKubletServiceName() string {
|
||||||
stdout, err := exec.Command("sudo", "systemctl", "list-units", "kubelet*", "--state=running").CombinedOutput()
|
stdout, err := exec.Command("sudo", "systemctl", "list-units", "kubelet*", "--state=running").CombinedOutput()
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
regex := regexp.MustCompile("(kubelet-\\w+)")
|
regex := regexp.MustCompile("(kubelet-\\w+)")
|
||||||
matches := regex.FindStringSubmatch(string(stdout))
|
matches := regex.FindStringSubmatch(string(stdout))
|
||||||
framework.ExpectNotEqual(len(matches), 0)
|
framework.ExpectNotEqual(len(matches), 0)
|
||||||
kube := matches[0]
|
kubeletServiceName := matches[0]
|
||||||
framework.Logf("Get running kubelet with systemctl: %v, %v", string(stdout), kube)
|
framework.Logf("Get running kubelet with systemctl: %v, %v", string(stdout), kubeletServiceName)
|
||||||
stdout, err = exec.Command("sudo", "systemctl", "restart", kube).CombinedOutput()
|
return kubeletServiceName
|
||||||
|
}
|
||||||
|
|
||||||
|
func restartKubelet() {
|
||||||
|
kubeletServiceName := findRunningKubletServiceName()
|
||||||
|
stdout, err := exec.Command("sudo", "systemctl", "restart", kubeletServiceName).CombinedOutput()
|
||||||
framework.ExpectNoError(err, "Failed to restart kubelet with systemctl: %v, %v", err, stdout)
|
framework.ExpectNoError(err, "Failed to restart kubelet with systemctl: %v, %v", err, stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stopKubelet will kill the running kubelet, and returns a func that will restart the process again
|
||||||
|
func stopKubelet() func() {
|
||||||
|
kubeletServiceName := findRunningKubletServiceName()
|
||||||
|
stdout, err := exec.Command("sudo", "systemctl", "kill", kubeletServiceName).CombinedOutput()
|
||||||
|
framework.ExpectNoError(err, "Failed to stop kubelet with systemctl: %v, %v", err, stdout)
|
||||||
|
return func() {
|
||||||
|
stdout, err := exec.Command("sudo", "systemctl", "start", kubeletServiceName).CombinedOutput()
|
||||||
|
framework.ExpectNoError(err, "Failed to restart kubelet with systemctl: %v, %v", err, stdout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func toCgroupFsName(cgroupName cm.CgroupName) string {
|
func toCgroupFsName(cgroupName cm.CgroupName) string {
|
||||||
if framework.TestContext.KubeletConfig.CgroupDriver == "systemd" {
|
if framework.TestContext.KubeletConfig.CgroupDriver == "systemd" {
|
||||||
return cgroupName.ToSystemd()
|
return cgroupName.ToSystemd()
|
||||||
|
Loading…
Reference in New Issue
Block a user