New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CronJob controller cleanups #110838
CronJob controller cleanups #110838
Conversation
@soltysh: GitHub didn't allow me to request PR reviews from the following users: d-honeybadger. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/triage accepted |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for letting me know!
Had to think for a bit how StartingDeadlineSeconds
was unnecessary in the mostRecentTime()
calculations, but pretty convinced now that that's correct.
I took the libery of leaving a couple nit comments.
pkg/controller/cronjob/utils.go
Outdated
@@ -33,6 +33,7 @@ import ( | |||
|
|||
// Utilities for dealing with Jobs and CronJobs and time. | |||
|
|||
// inActiveListByName take a job and checks if activeJobs has a job with the same UID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the comment got copied here by mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment to make it more explanatory.
pkg/controller/cronjob/utils.go
Outdated
) | ||
// mostRecentScheduleTime returns: | ||
// - the last schedule time or CronJob's creation time, | ||
// - the most recent time a Job should be created or nil, if that's before now, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or nil, if that's before now
shoud be or nil, if that's after now
I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, thx!
pkg/controller/cronjob/utils.go
Outdated
@@ -42,6 +43,17 @@ func inActiveList(cj batchv1.CronJob, uid types.UID) bool { | |||
return false | |||
} | |||
|
|||
// inActiveListByName take a job and checks if activeJobs has a job with the same | |||
// name and namespace. | |||
func inActiveListByName(job *batchv1.Job, activeJobs []corev1.ObjectReference) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be more similar to inActiveList
- we could switch flip the arguments: (what, where) -> (where, what)
- pass
CronJob
instead of[]corev1.ObjectReference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, updated.
pkg/controller/cronjob/utils.go
Outdated
// - the last schedule time or CronJob's creation time, | ||
// - the most recent time a Job should be created or nil, if that's before now, | ||
// - number of missed schedules | ||
// - error in an edge case where the schedule specification is gramatically correct, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// - error in an edge case where the schedule specification is gramatically correct, | |
// - error in an edge case where the schedule specification is grammatically correct, |
;-)
pkg/controller/cronjob/utils_test.go
Outdated
}{ | ||
{ | ||
name: "both have nil start times", | ||
input: []batchv1.Job{bNil, aNil}, | ||
expected: []batchv1.Job{aNil, bNil}, | ||
input: []*batchv1.Job{&bNil, &aNil}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be simpler to create a pointer when declaring the variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - fixed.
pkg/controller/cronjob/utils_test.go
Outdated
}, | ||
expectedTime: nil, | ||
now: topOfTheHour().Add(time.Second * 30), | ||
expectedRecentTime: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would not throw an error if we got non nil result
pkg/controller/cronjob/utils_test.go
Outdated
t.Error("mostRecentScheduleTime() got error when none expected") | ||
} | ||
if gotEarliestTime.IsZero() && tt.expectedEarliestTime != nil { | ||
t.Errorf("mostRecentScheduleTime() got 0, want %v", tt.expectedEarliestTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we describe in all of these, what variable name are we expecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
fcad11c
to
8190a73
Compare
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
If you still need this PR then please rebase, if not, please close the PR |
8190a73
to
949c953
Compare
949c953
to
ed99d82
Compare
Unrelated failure on CustomResourcePublishOpenAPI test |
@soltysh: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Unrelated failure on CustomResourcePublishOpenAPI test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the PR looks in a good shape
pkg/controller/cronjob/utils_test.go
Outdated
} | ||
if gotTime != nil && tt.expectedTime != nil && !gotTime.Equal(*tt.expectedTime) { | ||
t.Errorf("getMostRecentScheduleTime() got = %v, want %v", gotTime, tt.expectedTime) | ||
if gotRecentTime != nil && tt.expectedRecentTime != nil && !gotRecentTime.Equal(*tt.expectedRecentTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be more readable to use reflect.DeepEqual
here
1. Squash two identical sorters byTime 2. Move helper for searching active jobs into utils to exist next to its counterpart
20c1527
to
76218ff
Compare
…Duration 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.
76218ff
to
be44d67
Compare
looks good, thx |
LGTM label has been added. Git tree hash: fbb7921b5768228d7e1dd01db83443a2257182fd
|
What type of PR is this?
/kind cleanup
/sig apps
/priority backlog
What this PR does / why we need it:
There are 2 major changes introduced in this PR:
byJobStartTimeStar
sorter) and moving helpers into utils.go file.nextScheduledTimeDuration
andgetNextScheduledTime
(especially after we landed Fix requeueing of cronjobs with every-style schedule #109250).Special notes for your reviewer:
/assign @atiratree
/cc @d-honeybadger
Does this PR introduce a user-facing change?