Skip to content

Conversation

@wgliang
Copy link
Contributor

@wgliang wgliang commented Oct 2, 2018

…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:

Move CacheComparer to pkg/scheduler/internal/cache/comparer.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 2, 2018
@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 2, 2018
@wgliang wgliang force-pushed the feature/move-cachecompare branch from 88dd293 to af78b3a Compare October 2, 2018 04:01
@shubheksha
Copy link
Contributor

/kind cleanup

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 2, 2018
Copy link

@misterikkit misterikkit left a 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.

@wgliang wgliang force-pushed the feature/move-cachecompare branch from af78b3a to a6381af Compare October 6, 2018 16:22
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 6, 2018
@wgliang wgliang force-pushed the feature/move-cachecompare branch 3 times, most recently from dddb5eb to 6dc71a7 Compare October 7, 2018 00:12
@wgliang
Copy link
Contributor Author

wgliang commented Oct 7, 2018

/ping @misterikkit @k82cn @bsalamat

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

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.

@k82cn
Copy link
Contributor

k82cn commented Oct 7, 2018

/approve

LGTM overall, give an approve label firstly :)

@k8s-ci-robot
Copy link
Contributor

[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

Details 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 Oct 7, 2018
Copy link

@misterikkit misterikkit left a comment

Choose a reason for hiding this comment

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

Looks pretty good.

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.

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.

Copy link
Contributor Author

@wgliang wgliang Oct 9, 2018

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.

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

@wgliang wgliang Oct 9, 2018

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?

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.

@wgliang wgliang force-pushed the feature/move-cachecompare branch 2 times, most recently from 83de78c to 7a49b39 Compare October 9, 2018 00:12
@wgliang
Copy link
Contributor Author

wgliang commented Oct 9, 2018

/retest

Copy link

@misterikkit misterikkit left a 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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understand

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.

Copy link
Contributor Author

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?)

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

@wgliang wgliang force-pushed the feature/move-cachecompare branch from 7a49b39 to 4fbfd02 Compare October 10, 2018 11:24
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2018
@wgliang wgliang force-pushed the feature/move-cachecompare branch from 4fbfd02 to 48e32af Compare October 10, 2018 11:32
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2018
@wgliang wgliang force-pushed the feature/move-cachecompare branch from 48e32af to f63f5ea Compare October 10, 2018 11:46
@wgliang wgliang force-pushed the feature/move-cachecompare branch from f63f5ea to f44f55c Compare October 10, 2018 13:28
@wgliang
Copy link
Contributor Author

wgliang commented Oct 10, 2018

/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 10, 2018
@wgliang
Copy link
Contributor Author

wgliang commented Oct 10, 2018

/retest

@k8s-ci-robot k8s-ci-robot merged commit 256fdb9 into kubernetes:master Oct 11, 2018
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. 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.

[scheduler cleanup phase 1]: Move CacheComparer to pkg/scheduler/internal/cache

5 participants