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

[fix]: refactor code to replace time.Now() with Now() in clock package in pkg/scheduler(#3380) #3421

Merged
merged 8 commits into from
Nov 6, 2024

Conversation

TusharMohapatra07
Copy link
Contributor

@TusharMohapatra07 TusharMohapatra07 commented Nov 4, 2024

What type of PR is this?

/kind feature
/kind flake

What this PR does / why we need it:

Replaces time.Now() to use the Now() function present inside clock package

Which issue(s) this PR fixes:

Fixes #3380

Special notes for your reviewer:

This PR is work-in-progress. I've refactored the code inside pkg/scheduler for now. I shall proceed to refactor more post review.

NONE

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/flake Categorizes issue or PR as related to a flaky test. labels Nov 4, 2024
Copy link

linux-foundation-easycla bot commented Nov 4, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 4, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @TusharMohapatra07!

It looks like this is your first PR to kubernetes-sigs/kueue 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kueue has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @TusharMohapatra07. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 4, 2024
Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit f7d342b
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/672a24575894b70008c28472

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 4, 2024
@mimowo
Copy link
Contributor

mimowo commented Nov 4, 2024

cc @mbobrovskyi for first pass

Copy link
Contributor

@mbobrovskyi mbobrovskyi left a comment

Choose a reason for hiding this comment

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

  • Don't forget to change time.Since(...) to s.clock.Since(...) as well.
  • Please update scheduler_test.go using FakeClock instead of time.
  • Implement new Option to provide FakeClock to scheduler.

@TusharMohapatra07
Copy link
Contributor Author

@mbobrovskyi can you please elaborate on the Option thing ? i couldn't exactly understand the requirement. Also if there's any way i could join any slack or discord , that would be great as it would make a direct source of communication. I tried to join the slack channel but it's showing that it couldn't find my gmail.

@mbobrovskyi
Copy link
Contributor

@mbobrovskyi can you please elaborate on the Option thing ?

We already have a few options on Scheduler

func WithPodsReadyRequeuingTimestamp(ts config.RequeuingTimestamp) Option {
return func(o *options) {
o.podsReadyRequeuingTimestamp = ts
}
}
func WithFairSharing(fs *config.FairSharing) Option {
return func(o *options) {
if fs != nil {
o.fairSharing = *fs
}
}
}

So you need just to add one more like here

// WithClock sets the clock of the reconciler.
// It default to system's clock and should only
// be changed in testing.
func WithClock(_ testing.TB, c clock.Clock) Option {
return func(o *Options) {
o.Clock = c
}
}

Also if there's any way i could join any slack or discord , that would be great as it would make a direct source of communication. I tried to join the slack channel but it's showing that it couldn't find my gmail.

Yes, here https://kubernetes.slack.com/.

@TusharMohapatra07
Copy link
Contributor Author

TusharMohapatra07 commented Nov 4, 2024

@mbobrovskyi
image
i get this mail when i try to login.
image
i do not have this email btw

@mbobrovskyi
Copy link
Contributor

Try this https://slack.k8s.io/

@TusharMohapatra07
Copy link
Contributor Author

@mbobrovskyi please check if the 1st and 3rd requirement are being fulfilled.

about the 2nd one, is it similar to what's implemented here

fakeClock := testingclock.NewFakeClock(now)
?

@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Nov 4, 2024

@mbobrovskyi please check if the 1st and 3rd requirement are being fulfilled.

about the 2nd one, is it similar to what's implemented here

fakeClock := testingclock.NewFakeClock(now)

?

Yes, exactly.

@mbobrovskyi
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Nov 4, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 0eaed30412bd4b2bc6ab9e89428d341f5929c67c

@mbobrovskyi
Copy link
Contributor

/kind cleanup

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Nov 5, 2024
@mbobrovskyi
Copy link
Contributor

/release-note-edit

NONE

@k8s-ci-robot
Copy link
Contributor

@mbobrovskyi: /release-note-edit must be used with a single release note block.

In response to this:

/release-note-edit

NONE

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-sigs/prow repository.

@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Nov 5, 2024

@TusharMohapatra07 Please add

```release-note
NONE
```

on the PR description.

@mbobrovskyi
Copy link
Contributor

/remove-kind feature flake

@k8s-ci-robot k8s-ci-robot removed kind/feature Categorizes issue or PR as related to a new feature. kind/flake Categorizes issue or PR as related to a flaky test. labels Nov 5, 2024
@mbobrovskyi
Copy link
Contributor

/cc @mimowo

@k8s-ci-robot k8s-ci-robot requested a review from mimowo November 5, 2024 14:46
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 5, 2024
@TusharMohapatra07
Copy link
Contributor Author

@mbobrovskyi about the case that you asked me to cover

now := time.Now()
i couldn't find any scheduler instance being created inside the test function to pass the fakeClock to

@mbobrovskyi
Copy link
Contributor

@mbobrovskyi about the case that you asked me to cover

now := time.Now()

i couldn't find any scheduler instance being created inside the test function to pass the fakeClock to

Yeah, you right, it's not need. Thanks for investigation.

@mbobrovskyi
Copy link
Contributor

@TusharMohapatra07 Also please remove WIP on PR title if it's ready to review.

@TusharMohapatra07
Copy link
Contributor Author

@mbobrovskyi what about other packages ? should i raise another pr for those ? i think it would be a good idea to make one PR for each package refactor

@mbobrovskyi
Copy link
Contributor

@mbobrovskyi what about other packages ? should i raise another pr for those ? i think it would be a good idea to make one PR for each package refactor

Yes, feel free to follow up on separate PRs.

@TusharMohapatra07 TusharMohapatra07 changed the title [fix]: refactor code to replace time.Now() with Now() in clock package [WIP](#3380) [fix]: refactor code to replace time.Now() with Now() in clock package in pkg/scheduler(#3380) Nov 5, 2024
@TusharMohapatra07
Copy link
Contributor Author

@mbobrovskyi done

@mimowo
Copy link
Contributor

mimowo commented Nov 6, 2024

/approve
thanks folks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mimowo, TusharMohapatra07

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 Nov 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit adbafbd into kubernetes-sigs:main Nov 6, 2024
15 of 16 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.10 milestone Nov 6, 2024
@TusharMohapatra07 TusharMohapatra07 deleted the time_refactor branch November 16, 2024 16:20
kannon92 pushed a commit to kannon92/kueue that referenced this pull request Dec 5, 2024
…e in pkg/scheduler(kubernetes-sigs#3380) (kubernetes-sigs#3421)

* refactor time.Now() in pkg/scheduler

* replace time.Since() with Since() present in clock package

* add new option to provide fakeclock to scheduler

* add realClock to options and pass in fakeClock while testing

* use options.clock instead of realClock

* add more fakeClock(s)
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace time.Now() code with clock.Clock.Now()
4 participants