diff --git a/internal/controller/sqljob_controller.go b/internal/controller/sqljob_controller.go index ad80847a..6b0efe15 100644 --- a/internal/controller/sqljob_controller.go +++ b/internal/controller/sqljob_controller.go @@ -235,6 +235,8 @@ func (r *SqlJobReconciler) reconcileCronJob(ctx context.Context, sqlJob *mariadb } patch := client.MergeFrom(existingCronJob.DeepCopy()) + existingCronJob.Spec.FailedJobsHistoryLimit = desiredCronJob.Spec.FailedJobsHistoryLimit + existingCronJob.Spec.SuccessfulJobsHistoryLimit = desiredCronJob.Spec.SuccessfulJobsHistoryLimit existingCronJob.Spec.Schedule = desiredCronJob.Spec.Schedule existingCronJob.Spec.Suspend = desiredCronJob.Spec.Suspend existingCronJob.Spec.JobTemplate.Spec.BackoffLimit = desiredCronJob.Spec.JobTemplate.Spec.BackoffLimit diff --git a/internal/controller/sqljob_controller_test.go b/internal/controller/sqljob_controller_test.go index cefe3750..6617ba69 100644 --- a/internal/controller/sqljob_controller_test.go +++ b/internal/controller/sqljob_controller_test.go @@ -266,5 +266,24 @@ var _ = Describe("SqlJob", func() { *scheduledSqlJobWithHistoryLimits.Spec.FailedJobsHistoryLimit return isSuccessfulJobHistoryLimitCorrect && isFailedJobHistoryLimitCorrect }, testHighTimeout, testInterval).Should(BeTrue()) + + patch := client.MergeFrom(scheduledSqlJobWithHistoryLimits.DeepCopy()) + scheduledSqlJobWithHistoryLimits.Spec.SuccessfulJobsHistoryLimit = ptr.To[int32](7) + scheduledSqlJobWithHistoryLimits.Spec.FailedJobsHistoryLimit = ptr.To[int32](7) + By("Updating a scheduled SqlJob's history limits") + Expect(k8sClient.Patch(testCtx, scheduledSqlJobWithHistoryLimits, patch)).To(Succeed()) + + By("Expecting to update the CronJob history limits eventually") + Eventually(func() bool { + var cronJob batchv1.CronJob + if k8sClient.Get(testCtx, client.ObjectKeyFromObject(scheduledSqlJobWithHistoryLimits), &cronJob) != nil { + return false + } + isSuccessfulJobHistoryLimitCorrect := *cronJob.Spec.SuccessfulJobsHistoryLimit == + *scheduledSqlJobWithHistoryLimits.Spec.SuccessfulJobsHistoryLimit + isFailedJobHistoryLimitCorrect := *cronJob.Spec.FailedJobsHistoryLimit == + *scheduledSqlJobWithHistoryLimits.Spec.FailedJobsHistoryLimit + return isSuccessfulJobHistoryLimitCorrect && isFailedJobHistoryLimitCorrect + }, testHighTimeout, testInterval).Should(BeTrue()) }) })