Fix reconciliation of SqlJob history limit updates

This commit is contained in:
Marin Bezhanov
2024-07-18 10:12:54 +03:00
committed by Martin Montes
parent aecf813f45
commit 4788a7e433
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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())
})
})