diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index 699371e68f5..61ad09c16c4 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -2756,7 +2756,7 @@ func getCondition(job *batch.Job, condition batch.JobConditionType, status v1.Co // reaching the active deadline, at which point it is marked as Failed. func TestPastDeadlineJobFinished(t *testing.T) { _, ctx := ktesting.NewTestContext(t) - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() fakeClock := clocktesting.NewFakeClock(time.Now().Truncate(time.Second)) manager, sharedInformerFactory := newControllerFromClientWithClock(ctx, t, clientset, controller.NoResyncPeriodFunc, fakeClock) manager.podStoreSynced = alwaysReady @@ -6044,7 +6044,7 @@ func TestGetPodsForJob(t *testing.T) { if tc.jobDeleted { job.DeletionTimestamp = &metav1.Time{} } - clientSet := fake.NewSimpleClientset(job, otherJob) + clientSet := fake.NewClientset(job, otherJob) jm, informer := newControllerFromClient(ctx, t, clientSet, controller.NoResyncPeriodFunc) jm.podStoreSynced = alwaysReady jm.jobStoreSynced = alwaysReady @@ -6416,7 +6416,7 @@ func TestSyncJobExpectations(t *testing.T) { func TestWatchJobs(t *testing.T) { _, ctx := ktesting.NewTestContext(t) - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() fakeWatch := watch.NewFake() clientset.PrependWatchReactor("jobs", core.DefaultWatchReactor(fakeWatch, nil)) manager, sharedInformerFactory := newControllerFromClient(ctx, t, clientset, controller.NoResyncPeriodFunc) @@ -6446,9 +6446,8 @@ func TestWatchJobs(t *testing.T) { } // Start only the job watcher and the workqueue, send a watch event, // and make sure it hits the sync method. - stopCh := make(chan struct{}) - defer close(stopCh) - sharedInformerFactory.Start(stopCh) + sharedInformerFactory.Start(ctx.Done()) + sharedInformerFactory.WaitForCacheSync(ctx.Done()) go manager.Run(ctx, 1) // We're sending new job to see if it reaches syncHandler. @@ -6462,7 +6461,7 @@ func TestWatchJobs(t *testing.T) { func TestWatchPods(t *testing.T) { _, ctx := ktesting.NewTestContext(t) testJob := newJob(2, 2, 6, batch.NonIndexedCompletion) - clientset := fake.NewSimpleClientset(testJob) + clientset := fake.NewClientset(testJob) fakeWatch := watch.NewFake() clientset.PrependWatchReactor("pods", core.DefaultWatchReactor(fakeWatch, nil)) manager, sharedInformerFactory := newControllerFromClient(ctx, t, clientset, controller.NoResyncPeriodFunc) @@ -6493,9 +6492,7 @@ func TestWatchPods(t *testing.T) { } // Start only the pod watcher and the workqueue, send a watch event, // and make sure it hits the sync method for the right job. - stopCh := make(chan struct{}) - defer close(stopCh) - go sharedInformerFactory.Core().V1().Pods().Informer().Run(stopCh) + go sharedInformerFactory.Core().V1().Pods().Informer().Run(ctx.Done()) go manager.Run(ctx, 1) pods := newPodList(1, v1.PodRunning, testJob) @@ -6509,7 +6506,7 @@ func TestWatchPods(t *testing.T) { func TestWatchOrphanPods(t *testing.T) { _, ctx := ktesting.NewTestContext(t) - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() sharedInformers := informers.NewSharedInformerFactory(clientset, controller.NoResyncPeriodFunc()) manager, err := NewController(ctx, sharedInformers.Core().V1().Pods(), sharedInformers.Batch().V1().Jobs(), clientset) if err != nil { @@ -6518,11 +6515,9 @@ func TestWatchOrphanPods(t *testing.T) { manager.podStoreSynced = alwaysReady manager.jobStoreSynced = alwaysReady - stopCh := make(chan struct{}) - defer close(stopCh) podInformer := sharedInformers.Core().V1().Pods().Informer() - go podInformer.Run(stopCh) - cache.WaitForCacheSync(stopCh, podInformer.HasSynced) + go podInformer.Run(ctx.Done()) + cache.WaitForCacheSync(ctx.Done(), podInformer.HasSynced) go manager.Run(ctx, 1) // Create job but don't add it to the store. @@ -6582,7 +6577,7 @@ func TestWatchOrphanPods(t *testing.T) { func TestSyncOrphanPod(t *testing.T) { _, ctx := ktesting.NewTestContext(t) - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() sharedInformers := informers.NewSharedInformerFactory(clientset, controller.NoResyncPeriodFunc()) manager, err := NewController(ctx, sharedInformers.Core().V1().Pods(), sharedInformers.Batch().V1().Jobs(), clientset) if err != nil { @@ -6591,11 +6586,9 @@ func TestSyncOrphanPod(t *testing.T) { manager.podStoreSynced = alwaysReady manager.jobStoreSynced = alwaysReady - stopCh := make(chan struct{}) - defer close(stopCh) podInformer := sharedInformers.Core().V1().Pods().Informer() - go podInformer.Run(stopCh) - cache.WaitForCacheSync(stopCh, podInformer.HasSynced) + go podInformer.Run(ctx.Done()) + cache.WaitForCacheSync(ctx.Done(), podInformer.HasSynced) go manager.Run(ctx, 1) cases := map[string]struct { @@ -7462,7 +7455,7 @@ func TestEnsureJobConditions(t *testing.T) { func TestFinalizersRemovedExpectations(t *testing.T) { _, ctx := ktesting.NewTestContext(t) - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() sharedInformers := informers.NewSharedInformerFactory(clientset, controller.NoResyncPeriodFunc()) manager, err := NewController(ctx, sharedInformers.Core().V1().Pods(), sharedInformers.Batch().V1().Jobs(), clientset) if err != nil { @@ -7506,10 +7499,8 @@ func TestFinalizersRemovedExpectations(t *testing.T) { t.Errorf("Different expectations for removed finalizers after syncJob (-want,+got):\n%s", diff) } - stopCh := make(chan struct{}) - defer close(stopCh) - go sharedInformers.Core().V1().Pods().Informer().Run(stopCh) - cache.WaitForCacheSync(stopCh, podInformer.HasSynced) + go sharedInformers.Core().V1().Pods().Informer().Run(ctx.Done()) + cache.WaitForCacheSync(ctx.Done(), podInformer.HasSynced) // Make sure the first syncJob sets the expectations, even after the caches synced. gotExpectedUIDs = manager.finalizerExpectations.getExpectedUIDs(jobKey) @@ -7568,7 +7559,7 @@ func TestFinalizerCleanup(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() - clientset := fake.NewSimpleClientset() + clientset := fake.NewClientset() sharedInformers := informers.NewSharedInformerFactory(clientset, controller.NoResyncPeriodFunc()) manager, err := NewController(ctx, sharedInformers.Core().V1().Pods(), sharedInformers.Batch().V1().Jobs(), clientset) if err != nil {