kubernetes/pkg/controller/cronjob
Albert Sverdlov a46bab6930
Fix a job quota related deadlock (#119776)
* Fix a job quota related deadlock

In case ResourceQuota is used and sets a max # of jobs, a CronJob may get
trapped in a deadlock:
  1. Job quota for a namespace is reached.
  2. CronJob controller can't create a new job, because quota is
     reached.
  3. Cleanup of jobs owned by a cronjob doesn't happen, because a
     control loop iteration is finished because of an error to create a
     job.

To fix this we stop early quitting from a control loop iteration when
cronjob reconciliation failed and always let old jobs to be cleaned up.

* Dont reorder imports

* Don't stop requeuing on reconciliation error

Previous code only logged the reconciliation error inside jm.sync() and
didn't return the reconciliation error to it's invoker
processNextWorkItem().

Adding a copy-paste back to avoid this issue.

* Remove copy-pasted cleanupFinishedJobs()

Now we always call jm.cleanupFinishedJobs() first and then
jm.syncCronJob().

We also extract cronJobCopy and updateStatus outside jm.syncCronJob
function and pass pointers to them in both jm.syncCronJob and
jm.cleanupFinishedJobs to make delayed updates handling more explicit
and not dependent on the order in which cleanupFinishedJobs and
syncCronJob are invoked.

* Return updateStatus bool instead of changing the reference

* Explicitly ignore err in tests to fix linter
2023-08-31 08:25:00 -07:00
..
config OWNERS cleanup - Jan 2021 Week 1 2022-01-10 08:14:29 -05:00
metrics Promote cronjob_job_creation_skew metric to stable 2022-11-04 13:55:32 +01:00
cronjob_controllerv2_test.go Fix a job quota related deadlock (#119776) 2023-08-31 08:25:00 -07:00
cronjob_controllerv2.go Fix a job quota related deadlock (#119776) 2023-08-31 08:25:00 -07:00
doc.go
injection.go cronjob: return immediately when failed to create job for the namespace is terminating 2023-02-22 17:37:31 +08:00
OWNERS Check in OWNERS modified by update-yamlfmt.sh 2021-12-09 21:31:26 -05:00
utils_test.go feat: Append job creation timestamp to cronjob annotations (#118137) 2023-07-06 14:39:04 -07:00
utils.go feat: Append job creation timestamp to cronjob annotations (#118137) 2023-07-06 14:39:04 -07:00