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

Replace time.Now() with clock.Clock.Now() in pkg/pod #3775

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

TusharMohapatra07
Copy link
Contributor

What type of PR is this?

/kind cleanup

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:

Part of #3380

Special notes for your reviewer:

This PR is work-in-progress.

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Dec 9, 2024
@TusharMohapatra07 TusharMohapatra07 marked this pull request as draft December 9, 2024 15:37
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2024
@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 the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 9, 2024
Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 4aee186
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/6759e61474d18b0008db53c8

@mbobrovskyi
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2024
@mbobrovskyi
Copy link
Contributor

mbobrovskyi commented Dec 10, 2024

Please take a look at this

replCond.LastTransitionTime = metav1.Now()
as well.

@mbobrovskyi
Copy link
Contributor

I think here

lastTransition := metav1.Now()
we don't need Now(). Please optimize it.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 11, 2024
@mbobrovskyi
Copy link
Contributor

/test all

@TusharMohapatra07 TusharMohapatra07 marked this pull request as ready for review December 11, 2024 19:21
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2024
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.

/lgtm
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mbobrovskyi, TusharMohapatra07
Once this PR has been reviewed and has the lgtm label, please assign tenzen-y for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Contributor

LGTM label has been added.

Git tree hash: 61d3b47cefc9c126048fe8f7e1ba6dcc33707d7f

@@ -206,6 +209,13 @@ func (p *Pod) isUnretriableGroup() bool {
return false
}

func (p *Pod) getClock() clock.Clock {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead a function like this - can we please make sure the clock is always set, this will make the code much simpler to reason about, and can prevent panics when someone assumes it is set and forgets to call the function. It is very hard to see this type of a bug when reviewing and seeing on GH only fragment of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mimowo So, pod doesnot have a constructor so, we can no more implement options in it. What other approach do you think would fit in this situation ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I synced with @PBundyra and he should be able to help more, but I think it you could make this work with:

  • make the lastActiveTime and sortInactivePods to be receiving the (p *Pod) received from FindMatchingWorkloads
  • then we could have a function like NewPod accepting the clock (possibly as an option). In production code pass the real clock, and in tests the fake one

You can follow the pattern for the WorkloadReconciler from workload_controller.go

@TusharMohapatra07 TusharMohapatra07 marked this pull request as draft December 23, 2024 05:06
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 23, 2024
@TusharMohapatra07
Copy link
Contributor Author

TusharMohapatra07 commented Jan 2, 2025

What all fields should i include in the argument so that it must and should be passed while called (rest could be made passed as an option)

type Pod struct {
	pod                   corev1.Pod
	key                   types.NamespacedName
	isFound               bool
	isGroup               bool
	unretriableGroup      *bool
	list                  corev1.PodList
	absentPods            int
	excessPodExpectations *expectations.Store
	satisfiedExcessPods   bool
}

For Example, in NewWorkloadReconciler, we must pass client, queues, cache and recorder:

NewWorkloadReconciler(client client.Client, queues *queue.Manager, cache *cache.Cache, recorder record.EventRecorder, opts ...Option) *WorkloadReconciler

cc: @mimowo @PBundyra @mbobrovskyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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.

4 participants