Skip to content
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

Implement AfterFunc for Clock, FakeClock and IntervalClock #221

Merged

Conversation

MadhavJivrajani
Copy link
Contributor

@MadhavJivrajani MadhavJivrajani commented Sep 23, 2021

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This PR implements the AfterFunc method for the clocks in k8s.io/utils/clock. Having this implemented, k8s.io/utils/clock should be able to be a functional replacement of k8s.io/apimachinery/pkg/util/clock and we'll be one step closer to solving the divergent clock packages issue kubernetes/kubernetes#94738.

Which issue(s) this PR fixes:

Fixes kubernetes/kubernetes#105173

Special notes for your reviewer:
None

Release note:

This PR introduces a new interface for the clock package: WithDelayedExecution - this extends the Clock interface by further including the AfterFunc method.

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 23, 2021
@MadhavJivrajani
Copy link
Contributor Author

/sig api-machinery
/assign @MikeSpreitzer @wojtek-t

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Sep 23, 2021
Copy link
Member

@wojtek-t wojtek-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment

@@ -116,6 +117,25 @@ func (f *FakeClock) NewTimer(d time.Duration) clock.Timer {
return timer
}

// AfterFunc is the Fake version of time.AfterFunc(d, cb).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thanks!

@wojtek-t do you know how the test failure can be rectified? The failure is occurring because the Clock interface is no longer compatible with the previous version.

cc @liggitt

@MadhavJivrajani MadhavJivrajani force-pushed the add-afterfunc-utils-clock branch from 565ef49 to 21bec34 Compare September 23, 2021 12:46
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 23, 2021
@wojtek-t
Copy link
Member

Actually - the API diff is a good question.

I can see a motivation for not allowing extending interfaces.
In such case - the only thing I can imagine is to create a new interface that is extending clock
(similarly as we have WithTicker: https://github.com/kubernetes/utils/blob/master/clock/clock.go#L50)

[all the rest of the code remains as is]

/assign @dims

@MadhavJivrajani
Copy link
Contributor Author

/hold
until apidiff can be figured out

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 23, 2021
@jonyhy96
Copy link

jonyhy96 commented Sep 29, 2021

@MadhavJivrajani hi~ sorry to bother, i was working on the same thing because i didn't found related issue(forgot to check prs) in the first place. My implements is quit the same #223 as yours but the testFunc maybe more clear. do u mind to merge my commit in your pr if u accept the testFunc? thx.

@liggitt
Copy link
Member

liggitt commented Sep 29, 2021

In such case - the only thing I can imagine is to create a new interface that is extending clock
(similarly as we have WithTicker: https://github.com/kubernetes/utils/blob/master/clock/clock.go#L50)

Something like that sounds like what I would expect.

…ntation.

- WithDelayedExecution extends the Clock interface so as to not break code that currently uses the Clock interface.
- Implement AfterFunc for RealClock, FakeClock and IntervalClock and add unit tests for the same

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
@MadhavJivrajani MadhavJivrajani force-pushed the add-afterfunc-utils-clock branch from 21bec34 to 9f0974d Compare September 30, 2021 07:00
@MadhavJivrajani
Copy link
Contributor Author

@MadhavJivrajani hi~ sorry to bother, i was working on the same thing because i didn't found related issue(forgot to check prs) in the first place. My implements is quit the same #223 as yours but the testFunc maybe more clear. do u mind to merge my commit in your pr if u accept the testFunc? thx.

Hi @jonyhy96 - no issues. Thanks for creating the PR. Atleast imo the tests in this commit are more appropriate because firstly they align with the existing tests upstream, while the tests you've written look clearer - I'm not sure its complete because we need to check if trigger happens for the right intervals in order and not just based off a count (called in your case).

@MadhavJivrajani
Copy link
Contributor Author

@wojtek-t @liggitt I've made the changes. PTAL :)

@wojtek-t
Copy link
Member

/lgtm

@dims - can you help with approving this?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 30, 2021
@wojtek-t
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 30, 2021
@MadhavJivrajani
Copy link
Contributor Author

Will vendor in k/k after this is merged and migrate the last bit of code :)

@dims
Copy link
Member

dims commented Sep 30, 2021

no change in API, has test cases. @MadhavJivrajani FTW! this looks good to me.

/approve
/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, MadhavJivrajani, wojtek-t

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 30, 2021
@k8s-ci-robot k8s-ci-robot merged commit cb0fa31 into kubernetes:master Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement AfterFunc for k8s.io/utils/clock
7 participants