-
Notifications
You must be signed in to change notification settings - Fork 42.1k
[scheduler cleanup phase 1]: Move CacheComparer to pkg/scheduler/inte… #69317
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
[scheduler cleanup phase 1]: Move CacheComparer to pkg/scheduler/inte… #69317
Conversation
88dd293 to
af78b3a
Compare
|
/kind cleanup |
misterikkit
left a comment
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.
I think you need to fix the import in factory.go.
af78b3a to
a6381af
Compare
dddb5eb to
6dc71a7
Compare
|
/ping @misterikkit @k82cn @bsalamat |
pkg/scheduler/factory/factory.go
Outdated
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 add a NewCacheComparer func for this, and add a Run func to cover the following codes, e.g. signal, go routine?
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.
Add a NewCacheComparer is always a good idea. But this PR is just move code. I am more inclined to optimize this part of the code in a new PR. What do you think of it? @k82cn
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.
Personally, I'd like this to be the first line of struct followed with a empty line to distinguish normal field.
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, I agree with you. But maybe we need a new PR for this.
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.
I think it's fine in this PR since this type is moving out of the package that needed to use it. And when a package has basically only one type to export, having a function called simply New is fine.
|
/approve LGTM overall, give an approve label firstly :) |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: k82cn, wgliang The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
misterikkit
left a comment
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 pretty good.
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.
I think it's fine in this PR since this type is moving out of the package that needed to use it. And when a package has basically only one type to export, having a function called simply New is fine.
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.
I don't see where this type is referenced outside of this package. Does it need to be exported?
I suspect this is public because you can't initialize a struct from another package with internal fields.
The comment on this also implies that there is an interface somewhere being satisfied, but I couldn't find one. It's a bit strange that this code was organized this way. Not something that needs to be addressed in this PR though.
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.
I think maybe it should be exported. CacheComparer and its other fields are public.
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.
Do these tests compile if you change this package name to comparer_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.
It should be ok, but the package name comparer_test should not be the naming method recommended by kubernetes?
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.
em m m, maybe you should say the file name instead of the package name?
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.
I actually did mean the package name. It forces us to test the public API without doing any "mucking" with package internals. It's not always easy, but in this case I think it might be.
83de78c to
7a49b39
Compare
|
/retest |
misterikkit
left a comment
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 good but I'm holding off on rubber stamping it for one more round of comments.
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.
I would prefer this to be named New. Since you brought up the idea of sending follow-up PRs to clean this file, I'm okay with this being changed in a different PR.
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.
OK
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.
If you do a follow-up PR. Maybe these methods can be moved onto the CacheComparer type and CompareStrategy can be deleted. I don't see the benefit of having it as a separate, embedded type.
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.
Understand
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.
If it's trivial, please change package name to comparer_test in this PR.
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.
Why do we should name the package as combiner_test? Sorry, I can't understand the benefits of doing this?
But, even if we do, what should we name our file name? If we don't make any changes of files in combiner_test, we will get:
pkg/scheduler/factory/factory.go:63:2: found packages comparer (comparer.go) and comparer (comparer_test.go)
(I'm sure I have set the package name in comparer.go and comparer_test.go as comparer_test. Perhaps contrary to Go's naming rules?)
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.
I think this is coming from my c++ background, where we try to test via public interfaces. For example, suppose one of the structs in our package has a private field protected by a private sync.Mutex. Nothing prevents a unit test from accessing the field without holding the mutex. (Hopefully go test -race would catch it.)
The point is that direct access to private fields might lead us to test the wrong thing. To follow from the previous example, if we have a strong guarantee that all access to the field is protected by a mutex, we can make certain assumptions about concurrent access.
Regardless of the package name, the file name "comparer_test.go" is appropriate.
/lgtm
7a49b39 to
4fbfd02
Compare
4fbfd02 to
48e32af
Compare
48e32af to
f63f5ea
Compare
…rnal/cache/comparer
f63f5ea to
f44f55c
Compare
|
/retest |
|
/retest |
…rnal/cache/comparer
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #68960
Special notes for your reviewer:
@misterikkit
Release note: