mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Clean shutdown of daemonset integration tests
This commit is contained in:
parent
5fc1c39bd4
commit
2583942eb7
@ -39,6 +39,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/events"
|
"k8s.io/client-go/tools/events"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
|
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
|
||||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
"k8s.io/kubernetes/pkg/controller/daemon"
|
"k8s.io/kubernetes/pkg/controller/daemon"
|
||||||
@ -50,30 +51,30 @@ import (
|
|||||||
|
|
||||||
var zero = int64(0)
|
var zero = int64(0)
|
||||||
|
|
||||||
func setup(t *testing.T) (framework.CloseFunc, *daemon.DaemonSetsController, informers.SharedInformerFactory, clientset.Interface) {
|
func setup(t *testing.T) (kubeapiservertesting.TearDownFunc, *daemon.DaemonSetsController, informers.SharedInformerFactory, clientset.Interface) {
|
||||||
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
|
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||||
_, server, closeFn := framework.RunAnAPIServer(controlPlaneConfig)
|
server := kubeapiservertesting.StartTestServerOrDie(t, nil, []string{"--disable-admission-plugins=ServiceAccount,TaintNodesByCondition"}, framework.SharedEtcd())
|
||||||
|
|
||||||
config := restclient.Config{Host: server.URL}
|
config := restclient.CopyConfig(server.ClientConfig)
|
||||||
clientSet, err := clientset.NewForConfig(&config)
|
clientSet, err := clientset.NewForConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error in creating clientset: %v", err)
|
t.Fatalf("Error in creating clientset: %v", err)
|
||||||
}
|
}
|
||||||
resyncPeriod := 12 * time.Hour
|
resyncPeriod := 12 * time.Hour
|
||||||
informers := informers.NewSharedInformerFactory(clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "daemonset-informers")), resyncPeriod)
|
informers := informers.NewSharedInformerFactory(clientset.NewForConfigOrDie(restclient.AddUserAgent(config, "daemonset-informers")), resyncPeriod)
|
||||||
dc, err := daemon.NewDaemonSetsController(
|
dc, err := daemon.NewDaemonSetsController(
|
||||||
informers.Apps().V1().DaemonSets(),
|
informers.Apps().V1().DaemonSets(),
|
||||||
informers.Apps().V1().ControllerRevisions(),
|
informers.Apps().V1().ControllerRevisions(),
|
||||||
informers.Core().V1().Pods(),
|
informers.Core().V1().Pods(),
|
||||||
informers.Core().V1().Nodes(),
|
informers.Core().V1().Nodes(),
|
||||||
clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "daemonset-controller")),
|
clientset.NewForConfigOrDie(restclient.AddUserAgent(config, "daemonset-controller")),
|
||||||
flowcontrol.NewBackOff(5*time.Second, 15*time.Minute),
|
flowcontrol.NewBackOff(5*time.Second, 15*time.Minute),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating DaemonSets controller: %v", err)
|
t.Fatalf("error creating DaemonSets controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return closeFn, dc, informers, clientSet
|
return server.TearDownFn, dc, informers, clientSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupScheduler(
|
func setupScheduler(
|
||||||
@ -255,7 +256,7 @@ func validateDaemonSetPodsAndMarkReady(
|
|||||||
numberPods int,
|
numberPods int,
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
) {
|
) {
|
||||||
if err := wait.Poll(10*time.Second, 60*time.Second, func() (bool, error) {
|
if err := wait.Poll(time.Second, 60*time.Second, func() (bool, error) {
|
||||||
objects := podInformer.GetIndexer().List()
|
objects := podInformer.GetIndexer().List()
|
||||||
if len(objects) != numberPods {
|
if len(objects) != numberPods {
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -384,7 +385,7 @@ func validateDaemonSetStatus(
|
|||||||
dsName string,
|
dsName string,
|
||||||
expectedNumberReady int32,
|
expectedNumberReady int32,
|
||||||
t *testing.T) {
|
t *testing.T) {
|
||||||
if err := wait.Poll(5*time.Second, 60*time.Second, func() (bool, error) {
|
if err := wait.Poll(time.Second, 60*time.Second, func() (bool, error) {
|
||||||
ds, err := dsClient.Get(context.TODO(), dsName, metav1.GetOptions{})
|
ds, err := dsClient.Get(context.TODO(), dsName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -422,8 +423,8 @@ func TestOneNodeDaemonLaunchesPod(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("one-node-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "one-node-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -461,8 +462,8 @@ func TestSimpleDaemonSetLaunchesPods(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("simple-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "simple-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -497,8 +498,8 @@ func TestDaemonSetWithNodeSelectorLaunchesPods(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("simple-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "simple-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -566,8 +567,8 @@ func TestNotReadyNodeDaemonDoesLaunchPod(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("simple-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "simple-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -613,8 +614,8 @@ func TestInsufficientCapacityNode(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("insufficient-capacity", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "insufficient-capacity", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -677,8 +678,8 @@ func TestInsufficientCapacityNode(t *testing.T) {
|
|||||||
func TestLaunchWithHashCollision(t *testing.T) {
|
func TestLaunchWithHashCollision(t *testing.T) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("one-node-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "one-node-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podInformer := informers.Core().V1().Pods().Informer()
|
podInformer := informers.Core().V1().Pods().Informer()
|
||||||
@ -788,8 +789,8 @@ func TestLaunchWithHashCollision(t *testing.T) {
|
|||||||
func TestDSCUpdatesPodLabelAfterDedupCurHistories(t *testing.T) {
|
func TestDSCUpdatesPodLabelAfterDedupCurHistories(t *testing.T) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("one-node-daemonset-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "one-node-daemonset-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podInformer := informers.Core().V1().Pods().Informer()
|
podInformer := informers.Core().V1().Pods().Informer()
|
||||||
@ -916,8 +917,8 @@ func TestTaintedNode(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("tainted-node", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "tainted-node", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
@ -981,8 +982,8 @@ func TestUnschedulableNodeDaemonDoesLaunchPod(t *testing.T) {
|
|||||||
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
forEachStrategy(t, func(t *testing.T, strategy *apps.DaemonSetUpdateStrategy) {
|
||||||
closeFn, dc, informers, clientset := setup(t)
|
closeFn, dc, informers, clientset := setup(t)
|
||||||
defer closeFn()
|
defer closeFn()
|
||||||
ns := framework.CreateTestingNamespace("daemonset-unschedulable-test", t)
|
ns := framework.CreateNamespaceOrDie(clientset, "daemonset-unschedulable-test", t)
|
||||||
defer framework.DeleteTestingNamespace(ns, t)
|
defer framework.DeleteNamespaceOrDie(clientset, ns, t)
|
||||||
|
|
||||||
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
dsClient := clientset.AppsV1().DaemonSets(ns.Name)
|
||||||
podClient := clientset.CoreV1().Pods(ns.Name)
|
podClient := clientset.CoreV1().Pods(ns.Name)
|
||||||
|
Loading…
Reference in New Issue
Block a user