mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Clear shutdown in replicationcontroller integration test
This commit is contained in:
parent
c043535250
commit
ca68691feb
@ -133,12 +133,12 @@ func rmSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *replication.
|
||||
}
|
||||
|
||||
// Run RC controller and informers
|
||||
func runControllerAndInformers(t *testing.T, rm *replication.ReplicationManager, informers informers.SharedInformerFactory, podNum int) chan struct{} {
|
||||
stopCh := make(chan struct{})
|
||||
informers.Start(stopCh)
|
||||
func runControllerAndInformers(t *testing.T, rm *replication.ReplicationManager, informers informers.SharedInformerFactory, podNum int) func() {
|
||||
ctx, cancelFn := context.WithCancel(context.Background())
|
||||
informers.Start(ctx.Done())
|
||||
waitToObservePods(t, informers.Core().V1().Pods().Informer(), podNum)
|
||||
go rm.Run(context.TODO(), 5)
|
||||
return stopCh
|
||||
go rm.Run(ctx, 5)
|
||||
return cancelFn
|
||||
}
|
||||
|
||||
// wait for the podInformer to observe the pods. Call this function before
|
||||
@ -431,8 +431,8 @@ func TestAdoption(t *testing.T) {
|
||||
t.Fatalf("Failed to create Pod: %v", err)
|
||||
}
|
||||
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 1)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 1)
|
||||
defer stopControllers()
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
updatedPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@ -458,8 +458,8 @@ func TestSpecReplicasChange(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-spec-replicas-change", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 2)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -501,8 +501,8 @@ func TestLogarithmicScaleDown(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-spec-replicas-change", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 2)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -538,8 +538,8 @@ func TestDeletingAndFailedPods(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-deleting-and-failed-pods", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 2)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -603,8 +603,8 @@ func TestOverlappingRCs(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-overlapping-rcs", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
// Create 2 RCs with identical selectors
|
||||
for i := 0; i < 2; i++ {
|
||||
@ -638,8 +638,8 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-pod-orphaning-and-adoption-when-labels-change", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 1)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -715,8 +715,8 @@ func TestGeneralPodAdoption(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-general-pod-adoption", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 1)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -747,8 +747,8 @@ func TestReadyAndAvailableReplicas(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-ready-and-available-replicas", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 3)
|
||||
rc.Spec.MinReadySeconds = 3600
|
||||
@ -799,8 +799,8 @@ func TestRCScaleSubresource(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-rc-scale-subresource", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
rc := newRC("rc", ns.Name, 1)
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, []*v1.Pod{})
|
||||
@ -829,8 +829,8 @@ func TestExtraPodsAdoptionAndDeletion(t *testing.T) {
|
||||
}
|
||||
rcs, _ := createRCsPods(t, c, []*v1.ReplicationController{rc}, podList)
|
||||
rc = rcs[0]
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 3)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 3)
|
||||
defer stopControllers()
|
||||
waitRCStable(t, c, rc)
|
||||
|
||||
// Verify the extra pod is deleted eventually by determining whether number of
|
||||
@ -850,8 +850,8 @@ func TestFullyLabeledReplicas(t *testing.T) {
|
||||
defer closeFn()
|
||||
ns := framework.CreateTestingNamespace("test-fully-labeled-replicas", s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer close(stopCh)
|
||||
stopControllers := runControllerAndInformers(t, rm, informers, 0)
|
||||
defer stopControllers()
|
||||
|
||||
extraLabelMap := map[string]string{"foo": "bar", "extraKey": "extraValue"}
|
||||
rc := newRC("rc", ns.Name, 2)
|
||||
|
Loading…
Reference in New Issue
Block a user