Skip to content

Commit 851cf43

Browse files
authored
Merge pull request kubernetes#127487 from hakuna-matatah/jobperf-delete-eventhandler
Offload the main Job reconciler w.r.t cleaning finalizers
2 parents 7ff0580 + 0615ded commit 851cf43

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

pkg/controller/job/job_controller.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ func (jm *Controller) updateJob(logger klog.Logger, old, cur interface{}) {
486486
if err != nil {
487487
return
488488
}
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+
}
489495

490496
if curJob.Generation == oldJob.Generation {
491497
// 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{}) {
530536
return
531537
}
532538
}
539+
jm.enqueueLabelSelector(jobObj)
540+
}
541+
542+
func (jm *Controller) enqueueLabelSelector(jobObj *batch.Job) {
533543
selector, err := metav1.LabelSelectorAsSelector(jobObj.Spec.Selector)
534544
if err != nil {
535545
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) {
826836

827837
// if job was finished previously, we don't want to redo the termination
828838
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)
832839
err := jm.podBackoffStore.removeBackoffRecord(key)
833840
if err != nil {
834841
// re-syncing here as the record has to be removed for finished/deleted jobs
@@ -2072,21 +2079,6 @@ func onlyReplaceFailedPods(job *batch.Job) bool {
20722079
return job.Spec.PodFailurePolicy != nil
20732080
}
20742081

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-
20902082
func recordJobPodsCreationTotal(job *batch.Job, jobCtx *syncJobCtx, succeeded, failed int32) {
20912083
reason := metrics.PodCreateNew
20922084
if feature.DefaultFeatureGate.Enabled(features.JobPodReplacementPolicy) {

0 commit comments

Comments
 (0)