Skip to content

Commit

Permalink
📖 Update cronjob_controller.go: simplify setting mostRecentTime logic (…
Browse files Browse the repository at this point in the history
…#3700)

simplify setting mostRecentTime logic
The change consolidates conditions under which mostRecentTime can be set to scheduledTimeForJob for better readability
  • Loading branch information
hp685 committed Dec 7, 2023
1 parent 5e81ad8 commit 79cec87
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Expand Up @@ -217,9 +217,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
continue
}
if scheduledTimeForJob != nil {
if mostRecentTime == nil {
mostRecentTime = scheduledTimeForJob
} else if mostRecentTime.Before(*scheduledTimeForJob) {
if mostRecentTime == nil || mostRecentTime.Before(*scheduledTimeForJob) {
mostRecentTime = scheduledTimeForJob
}
}
Expand Down Expand Up @@ -304,7 +302,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if int32(i) >= int32(len(successfulJobs))-*cronJob.Spec.SuccessfulJobsHistoryLimit {
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); err != nil {
log.Error(err, "unable to delete old successful job", "job", job)
} else {
log.V(0).Info("deleted old successful job", "job", job)
Expand Down
Expand Up @@ -204,9 +204,7 @@ const ControllerReconcileLogic = `log := log.FromContext(ctx)
continue
}
if scheduledTimeForJob != nil {
if mostRecentTime == nil {
mostRecentTime = scheduledTimeForJob
} else if mostRecentTime.Before(*scheduledTimeForJob) {
if mostRecentTime == nil || mostRecentTime.Before(*scheduledTimeForJob) {
mostRecentTime = scheduledTimeForJob
}
}
Expand Down Expand Up @@ -291,7 +289,7 @@ const ControllerReconcileLogic = `log := log.FromContext(ctx)
if int32(i) >= int32(len(successfulJobs))-*cronJob.Spec.SuccessfulJobsHistoryLimit {
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); err != nil {
log.Error(err, "unable to delete old successful job", "job", job)
} else {
log.V(0).Info("deleted old successful job", "job", job)
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/util/testdata/exampleFile.txt
@@ -1 +1 @@
exampleTargetexampleCodeexampleCodeexampleCodeexampleCodeexampleCodeexampleCode
exampleTargetexampleCodeexampleCodeexampleCodeexampleCodeexampleCodeexampleCodeexampleCode

0 comments on commit 79cec87

Please sign in to comment.