code: func cleanupFinishedJobs(sj *batchv1beta1.CronJob, js []batchv1.Job, jc jobControlInterface,
  	sjc sjControlInterface, recorder record.EventRecorder) {
  	// If neither limits are active, there is no need to do anything.
  	if sj.Spec.FailedJobsHistoryLimit == nil && sj.Spec.SuccessfulJobsHistoryLimit == nil {
  		return
  	}
  
  	failedJobs := []batchv1.Job{}
  	succesfulJobs := []batchv1.Job{}
  
  	for _, job := range js {
  		isFinished, finishedStatus := getFinishedStatus(&job)
  		if isFinished && finishedStatus == batchv1.JobComplete {
  			succesfulJobs = append(succesfulJobs, job)
  		} else if isFinished && finishedStatus == batchv1.JobFailed {
  			failedJobs = append(failedJobs, job)
  		}
  	}
  
  	if sj.Spec.SuccessfulJobsHistoryLimit != nil {
  		removeOldestJobs(sj,
  			succesfulJobs,
  			jc,
  			*sj.Spec.SuccessfulJobsHistoryLimit,
  			recorder)
  	}
  
  	if sj.Spec.FailedJobsHistoryLimit != nil {
  		removeOldestJobs(sj,
  			failedJobs,
  			jc,
  			*sj.Spec.FailedJobsHistoryLimit,
  			recorder)
  	}
  
  	// Update the CronJob, in case jobs were removed from the list.
  	if _, err := sjc.UpdateStatus(sj); err != nil {
  		nameForLog := fmt.Sprintf("%s/%s", sj.Namespace, sj.Name)
  		klog.Infof("Unable to update status for %s (rv = %s): %v", nameForLog, sj.ResourceVersion, err)
  	}
  }
docs: // cleanupFinishedJobs cleanups finished jobs created by a CronJob