From 0362c678593aa518df16f6907095197453508e92 Mon Sep 17 00:00:00 2001 From: kannon92 Date: Sun, 8 Jan 2023 20:35:34 +0000 Subject: [PATCH] Fix SyncPastDeadlineJobFinished for enabling finalizer path --- pkg/controller/job/job_controller_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index b52e36c1201..1c86c906809 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -1866,6 +1866,9 @@ func TestSyncPastDeadlineJobFinished(t *testing.T) { start := metav1.NewTime(fakeClock.Now().Add(-time.Second)) job.Status.StartTime = &start } + job.Annotations = map[string]string{ + batch.JobTrackingFinalizer: "", + } _, err := clientset.BatchV1().Jobs(job.GetNamespace()).Create(ctx, job, metav1.CreateOptions{}) if err != nil { @@ -1875,6 +1878,10 @@ func TestSyncPastDeadlineJobFinished(t *testing.T) { if err := sharedInformerFactory.Batch().V1().Jobs().Informer().GetIndexer().Add(job); err != nil { t.Fatalf("Failed to insert job in index: %v", err) } + // This is needed because the fake clientset doesn't report created pods + // to the informer, leading to unsatisfied expectations in syncJob that prevent the controller from setting the final condition. + podIndexer := sharedInformerFactory.Core().V1().Pods().Informer().GetIndexer() + setPodsStatuses(podIndexer, job, 0, 1, 0, 0, 0) var j *batch.Job err = wait.PollImmediate(200*time.Microsecond, 3*time.Second, func() (done bool, err error) {