mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #89563 from oomichi/RestartControllerManager
Separate RestartControllerManager() as e2ekubesystem
This commit is contained in:
commit
ed00f42848
@ -115,6 +115,7 @@ filegroup(
|
|||||||
"//test/e2e/framework/job:all-srcs",
|
"//test/e2e/framework/job:all-srcs",
|
||||||
"//test/e2e/framework/kubectl:all-srcs",
|
"//test/e2e/framework/kubectl:all-srcs",
|
||||||
"//test/e2e/framework/kubelet:all-srcs",
|
"//test/e2e/framework/kubelet:all-srcs",
|
||||||
|
"//test/e2e/framework/kubesystem:all-srcs",
|
||||||
"//test/e2e/framework/log:all-srcs",
|
"//test/e2e/framework/log:all-srcs",
|
||||||
"//test/e2e/framework/metrics:all-srcs",
|
"//test/e2e/framework/metrics:all-srcs",
|
||||||
"//test/e2e/framework/network:all-srcs",
|
"//test/e2e/framework/network:all-srcs",
|
||||||
|
26
test/e2e/framework/kubesystem/BUILD
Normal file
26
test/e2e/framework/kubesystem/BUILD
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["kubesystem.go"],
|
||||||
|
importpath = "k8s.io/kubernetes/test/e2e/framework/kubesystem",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//test/e2e/framework:go_default_library",
|
||||||
|
"//test/e2e/framework/ssh:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
66
test/e2e/framework/kubesystem/kubesystem.go
Normal file
66
test/e2e/framework/kubesystem/kubesystem.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kubesystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ssh port
|
||||||
|
sshPort = "22"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RestartControllerManager restarts the kube-controller-manager.
|
||||||
|
func RestartControllerManager() error {
|
||||||
|
// TODO: Make it work for all providers and distros.
|
||||||
|
if !framework.ProviderIs("gce", "aws") {
|
||||||
|
return fmt.Errorf("unsupported provider for RestartControllerManager: %s", framework.TestContext.Provider)
|
||||||
|
}
|
||||||
|
if framework.ProviderIs("gce") && !framework.MasterOSDistroIs("gci") {
|
||||||
|
return fmt.Errorf("unsupported master OS distro: %s", framework.TestContext.MasterOSDistro)
|
||||||
|
}
|
||||||
|
cmd := "pidof kube-controller-manager | xargs sudo kill"
|
||||||
|
framework.Logf("Restarting controller-manager via ssh, running: %v", cmd)
|
||||||
|
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
|
||||||
|
if err != nil || result.Code != 0 {
|
||||||
|
e2essh.LogResult(result)
|
||||||
|
return fmt.Errorf("couldn't restart controller-manager: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitForControllerManagerUp waits for the kube-controller-manager to be up.
|
||||||
|
func WaitForControllerManagerUp() error {
|
||||||
|
cmd := "curl http://localhost:" + strconv.Itoa(framework.InsecureKubeControllerManagerPort) + "/healthz"
|
||||||
|
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
|
||||||
|
result, err := e2essh.SSH(cmd, net.JoinHostPort(framework.GetMasterHost(), sshPort), framework.TestContext.Provider)
|
||||||
|
if err != nil || result.Code != 0 {
|
||||||
|
e2essh.LogResult(result)
|
||||||
|
}
|
||||||
|
if result.Stdout == "ok" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("waiting for controller-manager timed out")
|
||||||
|
}
|
@ -72,7 +72,6 @@ import (
|
|||||||
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
|
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
|
||||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -143,9 +142,6 @@ const (
|
|||||||
|
|
||||||
// TODO(justinsb): Avoid hardcoding this.
|
// TODO(justinsb): Avoid hardcoding this.
|
||||||
awsMasterIP = "172.20.0.9"
|
awsMasterIP = "172.20.0.9"
|
||||||
|
|
||||||
// ssh port
|
|
||||||
sshPort = "22"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -1114,40 +1110,6 @@ func AllNodesReady(c clientset.Interface, timeout time.Duration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestartControllerManager restarts the kube-controller-manager.
|
|
||||||
func RestartControllerManager() error {
|
|
||||||
// TODO: Make it work for all providers and distros.
|
|
||||||
if !ProviderIs("gce", "aws") {
|
|
||||||
return fmt.Errorf("unsupported provider for RestartControllerManager: %s", TestContext.Provider)
|
|
||||||
}
|
|
||||||
if ProviderIs("gce") && !MasterOSDistroIs("gci") {
|
|
||||||
return fmt.Errorf("unsupported master OS distro: %s", TestContext.MasterOSDistro)
|
|
||||||
}
|
|
||||||
cmd := "pidof kube-controller-manager | xargs sudo kill"
|
|
||||||
Logf("Restarting controller-manager via ssh, running: %v", cmd)
|
|
||||||
result, err := e2essh.SSH(cmd, net.JoinHostPort(GetMasterHost(), sshPort), TestContext.Provider)
|
|
||||||
if err != nil || result.Code != 0 {
|
|
||||||
e2essh.LogResult(result)
|
|
||||||
return fmt.Errorf("couldn't restart controller-manager: %v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitForControllerManagerUp waits for the kube-controller-manager to be up.
|
|
||||||
func WaitForControllerManagerUp() error {
|
|
||||||
cmd := "curl http://localhost:" + strconv.Itoa(InsecureKubeControllerManagerPort) + "/healthz"
|
|
||||||
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
|
|
||||||
result, err := e2essh.SSH(cmd, net.JoinHostPort(GetMasterHost(), sshPort), TestContext.Provider)
|
|
||||||
if err != nil || result.Code != 0 {
|
|
||||||
e2essh.LogResult(result)
|
|
||||||
}
|
|
||||||
if result.Stdout == "ok" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Errorf("waiting for controller-manager timed out")
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookForStringInLog looks for the given string in the log of a specific pod container
|
// LookForStringInLog looks for the given string in the log of a specific pod container
|
||||||
func LookForStringInLog(ns, podName, container, expectedString string, timeout time.Duration) (result string, err error) {
|
func LookForStringInLog(ns, podName, container, expectedString string, timeout time.Duration) (result string, err error) {
|
||||||
return lookForString(expectedString, timeout, func() string {
|
return lookForString(expectedString, timeout, func() string {
|
||||||
|
@ -70,6 +70,7 @@ go_library(
|
|||||||
"//test/e2e/framework/deployment:go_default_library",
|
"//test/e2e/framework/deployment:go_default_library",
|
||||||
"//test/e2e/framework/endpoints:go_default_library",
|
"//test/e2e/framework/endpoints:go_default_library",
|
||||||
"//test/e2e/framework/ingress:go_default_library",
|
"//test/e2e/framework/ingress:go_default_library",
|
||||||
|
"//test/e2e/framework/kubesystem:go_default_library",
|
||||||
"//test/e2e/framework/network:go_default_library",
|
"//test/e2e/framework/network:go_default_library",
|
||||||
"//test/e2e/framework/node:go_default_library",
|
"//test/e2e/framework/node:go_default_library",
|
||||||
"//test/e2e/framework/pod:go_default_library",
|
"//test/e2e/framework/pod:go_default_library",
|
||||||
|
@ -47,6 +47,7 @@ import (
|
|||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
|
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
|
||||||
e2eendpoints "k8s.io/kubernetes/test/e2e/framework/endpoints"
|
e2eendpoints "k8s.io/kubernetes/test/e2e/framework/endpoints"
|
||||||
|
e2ekubesystem "k8s.io/kubernetes/test/e2e/framework/kubesystem"
|
||||||
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
|
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
|
||||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
@ -2345,11 +2346,11 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("restart kube-controller-manager")
|
ginkgo.By("restart kube-controller-manager")
|
||||||
if err := framework.RestartControllerManager(); err != nil {
|
if err := e2ekubesystem.RestartControllerManager(); err != nil {
|
||||||
framework.Failf("framework.RestartControllerManager() = %v; want nil", err)
|
framework.Failf("e2ekubesystem.RestartControllerManager() = %v; want nil", err)
|
||||||
}
|
}
|
||||||
if err := framework.WaitForControllerManagerUp(); err != nil {
|
if err := e2ekubesystem.WaitForControllerManagerUp(); err != nil {
|
||||||
framework.Failf("framework.WaitForControllerManagerUp() = %v; want nil", err)
|
framework.Failf("e2ekubesystem.WaitForControllerManagerUp() = %v; want nil", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("health check should be reconciled")
|
ginkgo.By("health check should be reconciled")
|
||||||
|
@ -67,6 +67,7 @@ go_library(
|
|||||||
"//test/e2e/framework/auth:go_default_library",
|
"//test/e2e/framework/auth:go_default_library",
|
||||||
"//test/e2e/framework/deployment:go_default_library",
|
"//test/e2e/framework/deployment:go_default_library",
|
||||||
"//test/e2e/framework/kubectl:go_default_library",
|
"//test/e2e/framework/kubectl:go_default_library",
|
||||||
|
"//test/e2e/framework/kubesystem:go_default_library",
|
||||||
"//test/e2e/framework/metrics:go_default_library",
|
"//test/e2e/framework/metrics:go_default_library",
|
||||||
"//test/e2e/framework/node:go_default_library",
|
"//test/e2e/framework/node:go_default_library",
|
||||||
"//test/e2e/framework/pod:go_default_library",
|
"//test/e2e/framework/pod:go_default_library",
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2ekubesystem "k8s.io/kubernetes/test/e2e/framework/kubesystem"
|
||||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
|
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
|
||||||
@ -214,9 +215,9 @@ var _ = utils.SIGDescribe("NFSPersistentVolumes[Disruptive][Flaky]", func() {
|
|||||||
pvc2 = nil
|
pvc2 = nil
|
||||||
|
|
||||||
ginkgo.By("Restarting the kube-controller-manager")
|
ginkgo.By("Restarting the kube-controller-manager")
|
||||||
err = framework.RestartControllerManager()
|
err = e2ekubesystem.RestartControllerManager()
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
err = framework.WaitForControllerManagerUp()
|
err = e2ekubesystem.WaitForControllerManagerUp()
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
framework.Logf("kube-controller-manager restarted")
|
framework.Logf("kube-controller-manager restarted")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user