Commit Graph

222 Commits

Author SHA1 Message Date
liyuerich
8e97c0ff7d drop deprecated pointer package in controller
Signed-off-by: liyuerich <yue.li@daocloud.io>

Update job_controller.go

Signed-off-by: liyuerich <yue.li@daocloud.io>
2024-05-09 11:34:25 +08:00
Kubernetes Prow Robot
d2e6c51b05
Merge pull request #123537 from kaisoz/commonize-job-util-functions
Add the util pkg to commonize job util functions
2024-05-07 16:59:28 -07:00
Tomas Tormo
c856c412b9 Add util pkg to commonize job util functions 2024-05-07 09:27:46 +00:00
Alvaro Aleman
6d0ac8c561 Use the generic/typed workqueue throughout
This change makes us use the generic workqueue throughout the project in
order to improve type safety and readability of the code.
2024-05-04 14:33:12 -04:00
Marek Siarkowicz
3ee8178768 Cleanup defer from SetFeatureGateDuringTest function call 2024-04-24 20:25:29 +02:00
Kubernetes Prow Robot
67a06c2056
Merge pull request #122293 from mengjiao-liu/controller-reconsider-log-verbosity
kube-controller-manager: readjust log verbosity
2024-02-29 11:55:21 -08:00
Kubernetes Prow Robot
12771ce773
Merge pull request #122493 from mengjiao-liu/fix-cronjob-error
cronjob: fix incorrect error checking
2024-02-27 14:14:54 -08:00
Michał Woźniak
3852d1c0c1
Make explicit check in CronJob if Job is successful before setting LastSuccessfulTime (#123380)
* Make explicit check in CronJob if Job is successful

before setting LastSuccessfulTime

* Review remarks for the CronJob

Co-authored-by: Filip Křepinský <fkrepins@redhat.com>

---------

Co-authored-by: Filip Křepinský <fkrepins@redhat.com>
2024-02-27 13:09:43 -08:00
Mengjiao Liu
b584b87a94 kube-controller-manager: readjust log verbosity
- Increase the global level for broadcaster's logging to 3 so that users can ignore event messages by lowering the logging level. It reduces information noise.
- Making sure the context is properly injected into the broadcaster, this will allow the -v flag value to be used also in that broadcaster, rather than the above global value.
- test: use cancellation from ktesting
- golangci-hints: checked error return value
2024-02-26 14:51:56 +08:00
Mengjiao Liu
8f2aaf63d7 Fix incorrect error checking 2023-12-27 15:33:28 +08:00
Maciej Szulik
bf2f640ea2
Add more test cases ensuring nextScheduleTimeDuration is never < 0 2023-10-24 11:08:02 +02:00
Maciej Szulik
db8b303156
Modify mostRecentScheduleTime to return more detailed information about missed schedules
Initially this method was returning a number of missed schedules, but
that turned out to be not reliable for some complex schedules. For
example, those which are being run only during week days. The second
approach was to only return a boolean indicating the too many missed
information. It turns out that we need to return all three values:
none missed, few missed and many missed, to let consumers know what to
do, but don't leak the wrong number out of mostRecentScheduleTime.
2023-10-18 20:03:03 +02:00
Maciej Szulik
6c4f71b31c
Fix spelling 2023-10-18 19:15:34 +02:00
Andrew Sy Kim
301aa69fec cronjob controller: ensure already existing jobs are added to Active list of cronjobs
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
2023-09-19 15:18:44 +00:00
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
Kubernetes Prow Robot
88c8bcbb4a
Merge pull request #115952 from pacoxu/cleanup-cronjob
cronjob: return immediately when failed to create job for the namespace is terminating
2023-07-18 21:28:02 -07:00
Heba Elayoty
2fe38f93e5
feat: Append job creation timestamp to cronjob annotations (#118137)
* Append job name to job annotations

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

* Update annotation description, remove timezone, and fix time

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

* Remove unused ctx

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

* code review comments

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

* code review comments

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

* Add timezone back

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>

---------

Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
2023-07-06 14:39:04 -07:00
Maciej Szulik
1240a29af9
Hide numberOfMissedSchedules as an algorithm internal number 2023-07-05 16:58:28 +02:00
Maciej Szulik
af1c9e49c4
Update schedule logic to properly calculate missed schedules
Before this change we've assumed a constant time between schedule runs,
which is not true for cases like "30 6-16/4 * * 1-5".
The fix is to calculate the potential next run using the fixed schedule
as the baseline, and then go back one schedule back and allow the cron
library to calculate the correct time.

This approach saves us from iterating multiple times between last
schedule time and now, if the cronjob for any reason wasn't running for
significant amount of time.
2023-06-27 11:29:30 +02:00
Paco Xu
ade63dd764 cronjob: add ut for namespace terminating cause no extra log 2023-03-23 21:40:33 +08:00
Maciej Szulik
1b825c179b
Promote CronJob TZ to GA 2023-03-07 12:58:57 +01:00
Paco Xu
a890724f9e cronjob: return immediately when failed to create job for the namespace is terminating 2023-02-22 17:37:31 +08:00
Paco Xu
37aff025ff cleanup: remove Clear for fake job controller 2023-02-22 17:17:47 +08:00
Mengjiao Liu
6f2cd1b5bd Update pkg/controller/cronjob/ for contextual logging 2023-02-02 14:27:13 +08:00
Patrick Ohly
bc6c7fa912 logging: fix names of keys
The stricter checking with the upcoming logcheck v0.4.1 pointed out these names
which don't comply with our recommendations in
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments.
2023-01-23 14:24:29 +01:00
Maciej Szulik
be44d67566
Re-use common parts between getNextScheduleTime and nextScheduledTimeDuration
The two methods nextScheduledTimeDuration and getNextScheduleTime have a
lot of similarities, so this commit squashes the common parts together
along with getMostRecentScheduleTime to avoid code duplication.
2023-01-18 16:52:45 +01:00
Maciej Szulik
cb491a8d0f
Cleanups in controller utils
1. Squash two identical sorters byTime
2. Move helper for searching active jobs into utils to exist next to its
  counterpart
2023-01-18 13:40:23 +01:00
Jordan Liggitt
78cb3862f1
Fix indentation/spacing in comments to render correctly in godoc 2022-12-17 23:27:38 -05:00
Kubernetes Prow Robot
ead17f3dc8
Merge pull request #113008 from soltysh/promote_cronjob_metrics
Promote cronjob_job_creation_skew metric to stable
2022-11-04 09:36:27 -07:00
Maciej Szulik
4af97e599a
Promote cronjob_job_creation_skew metric to stable 2022-11-04 13:55:32 +01:00
Wojciech Tyczyński
c84c27b6ac Clean shutdown of event broadcaster in controllers 2022-11-02 21:08:43 +01:00
Han Kang
2bbd445f50 remove rate limiter metric as it is not in use
Change-Id: I91157653e3860eeecc3f572aee88da6ffc65faed
2022-10-13 13:07:11 -07:00
Davanum Srinivas
a9593d634c
Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-07-26 13:14:05 -04:00
Kubernetes Prow Robot
6269784cd0
Merge pull request #109250 from d-honeybadger/fix-cronjob-scheduling-every-syntax
Fix requeueing of cronjobs with every-style schedule
2022-06-28 04:37:57 -07:00
Jordan Liggitt
495b01ef6c Move cron job feature gate to correct file 2022-04-03 22:56:01 -04:00
d-honeybadger
7ae21b9849 cronjob_controllerv2: fix requeueing of cronjobs with every-style schedule 2022-04-01 20:14:23 -04:00
Ross Peoples
dbb3906a09 Fix for timeZone validation and strategy 2022-03-29 11:40:34 -05:00
Ross Peoples
f3b928a23d Import tzdata in apiserver, CronJob.timeZone fixes 2022-03-28 16:33:05 -05:00
Ross Peoples
98837de446 TimeZone support for CronJobs 2022-03-28 16:33:00 -05:00
Kubernetes Prow Robot
343125cc6c
Merge pull request #107997 from d-honeybadger/fix-tracking-cronjob-owned-jobs
Fix cronjob status reconciliation when job template labels change
2022-02-23 07:14:18 -08:00
d-honeybadger
fb094dc44e cronjob_controllerv2: do not filter jobs to be reconciled by labels 2022-02-23 09:10:33 -05:00
jlsong01
d281e25426 Optimize cronjob controller status updates 2022-01-27 17:09:47 +08:00
Kubernetes Prow Robot
876d4e0ab0
Merge pull request #107659 from jlsong01/readability_ut_cj_controller
readability enhancement for cj controller unit test
2022-01-26 21:12:49 -08:00
jlsong01
79d921e040 readability enhancement for cj controller unit test 2022-01-20 23:10:10 +08:00
Wojciech Tyczyński
551790729f Remove selflink references in different testing-related files 2022-01-14 12:58:05 +01:00
Davanum Srinivas
9682b7248f
OWNERS cleanup - Jan 2021 Week 1
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-01-10 08:14:29 -05:00
Kubernetes Prow Robot
3bebe8f6b5
Merge pull request #105264 from devincd/fix_typo
fix the log description
2022-01-06 17:40:29 -08:00
Kubernetes Prow Robot
8ade75465a
Merge pull request #104799 from RyanAoh/cronjob_dev
fix the error when cleaning up finished jobs for cronjob
2021-12-17 13:23:53 -08:00
Davanum Srinivas
9405e9b55e
Check in OWNERS modified by update-yamlfmt.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2021-12-09 21:31:26 -05:00
Aohan Yang
ad4fe13528 fix the error when cleaning up jobs for cronjob 2021-11-22 17:06:22 +08:00