@@ -486,6 +486,12 @@ func (jm *Controller) updateJob(logger klog.Logger, old, cur interface{}) {
486
486
if err != nil {
487
487
return
488
488
}
489
+ // The job shouldn't be marked as finished until all pod finalizers are removed, so
490
+ // this is a backup operation.
491
+ if util .IsJobFinished (curJob ) {
492
+ jm .enqueueLabelSelector (curJob )
493
+ return
494
+ }
489
495
490
496
if curJob .Generation == oldJob .Generation {
491
497
// Delay the Job sync when no generation change to batch Job status updates,
@@ -530,6 +536,10 @@ func (jm *Controller) deleteJob(logger klog.Logger, obj interface{}) {
530
536
return
531
537
}
532
538
}
539
+ jm .enqueueLabelSelector (jobObj )
540
+ }
541
+
542
+ func (jm * Controller ) enqueueLabelSelector (jobObj * batch.Job ) {
533
543
selector , err := metav1 .LabelSelectorAsSelector (jobObj .Spec .Selector )
534
544
if err != nil {
535
545
utilruntime .HandleError (fmt .Errorf ("job %s/%s has invalid label selector: %w" , jobObj .Namespace , jobObj .Name , err ))
@@ -826,9 +836,6 @@ func (jm *Controller) syncJob(ctx context.Context, key string) (rErr error) {
826
836
827
837
// if job was finished previously, we don't want to redo the termination
828
838
if util .IsJobFinished (& job ) {
829
- // The job shouldn't be marked as finished until all pod finalizers are removed.
830
- // Cleaning pod finalizers one more time just in case.
831
- jm .cleanupPodFinalizers (& job )
832
839
err := jm .podBackoffStore .removeBackoffRecord (key )
833
840
if err != nil {
834
841
// re-syncing here as the record has to be removed for finished/deleted jobs
@@ -2072,21 +2079,6 @@ func onlyReplaceFailedPods(job *batch.Job) bool {
2072
2079
return job .Spec .PodFailurePolicy != nil
2073
2080
}
2074
2081
2075
- func (jm * Controller ) cleanupPodFinalizers (job * batch.Job ) {
2076
- // Listing pods shouldn't really fail, as we are just querying the informer cache.
2077
- selector , err := metav1 .LabelSelectorAsSelector (job .Spec .Selector )
2078
- if err != nil {
2079
- utilruntime .HandleError (fmt .Errorf ("parsing deleted job selector: %v" , err ))
2080
- return
2081
- }
2082
- pods , _ := jm .podStore .Pods (job .Namespace ).List (selector )
2083
- for _ , pod := range pods {
2084
- if metav1 .IsControlledBy (pod , job ) && hasJobTrackingFinalizer (pod ) {
2085
- jm .enqueueOrphanPod (pod )
2086
- }
2087
- }
2088
- }
2089
-
2090
2082
func recordJobPodsCreationTotal (job * batch.Job , jobCtx * syncJobCtx , succeeded , failed int32 ) {
2091
2083
reason := metrics .PodCreateNew
2092
2084
if feature .DefaultFeatureGate .Enabled (features .JobPodReplacementPolicy ) {
0 commit comments