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
Use cmp.Diff() replace reflect and diagnosis #103508
Conversation
@boenn: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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/test-infra repository. |
Hi @boenn. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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/test-infra repository. |
/ok-to-test |
/retest |
/remove-kind design |
pkg/scheduler/framework/interface.go
Outdated
@@ -196,6 +196,9 @@ func (s *Status) Equal(x *Status) bool { | |||
if s.code == Error { | |||
return cmp.Equal(s.err, x.err, cmpopts.EquateErrors()) | |||
} | |||
if s.failedPlugin != "" || x.failedPlugin != "" { | |||
return s.failedPlugin == x.failedPlugin | |||
} |
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.
changes looks good to me, @Huang-Wei do you aware of any negative impact of this change?
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.
No need for the if statement
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.
the code in here
so there will be no inconsistency between Status.failedPlugin and UnschedulablePlugins. If you manually modify all these fields like:
expected := framework.Diagnosis{
NodeToStatusMap: framework.NodeToStatusMap{
"1": framework.NewStatus(framework.Unschedulable, st.ErrReasonFake).WithFailedPlugin("AnotherFilter"),
"2": framework.NewStatus(framework.Unschedulable, st.ErrReasonFake).WithFailedPlugin("AnotherFilter"),
"3": framework.NewStatus(framework.Unschedulable, st.ErrReasonFake).WithFailedPlugin("AnotherFilter"),
},
UnschedulablePlugins: sets.NewString("AnotherFilter"),
}
cmp.Diff is possible, and do not need to modify Equal.
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.
changes looks good to me, @Huang-Wei do you aware of any negative impact of this change?
when I reviewed this PR, this code wasn't there... And the latest code also removed it.
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.
so there will be no inconsistency between Status.failedPlugin and UnschedulablePlugins. If you manually modify all these fields like:
Not follow here, shouldn't cmp.Diff
expect to compare each of the fields here? Suppose diagnosis
return struct where the field plugin is MatchFilter
, and expected
is defined as FakeFilter
but the test pass, does that make sense?
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.
@Huang-Wei , code is here, not sure why the code is reverted by boenn.
kubernetes/pkg/scheduler/framework/interface.go
Lines 214 to 225 in e326c00
func (s *Status) Equal(x *Status) bool { | |
if s == nil || x == nil { | |
return s.IsSuccess() && x.IsSuccess() | |
} | |
if s.code != x.code { | |
return false | |
} | |
if s.code == Error { | |
return cmp.Equal(s.err, x.err, cmpopts.EquateErrors()) | |
} | |
return cmp.Equal(s.reasons, x.reasons) | |
} |
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.
Sorry I modified the code without explanation. I'm not sure that it is necessary to verify the failedPlugin, because from the code I said above, it will be locked when the failedPlugin is modified, and the result of manual modification may never appear. This part of the check is redundant.And..here is the code:
func (s *Status) Equal(x *Status) bool {
if s == nil || x == nil {
return s.IsSuccess() && x.IsSuccess()
}
if s.code != x.code {
return false
}
if s.code == Error {
return cmp.Equal(s.err, x.err, cmpopts.EquateErrors())
}
if s.failedPlugin != "" || x.failedPlugin != "" {
return s.failedPlugin == x.failedPlugin
}
return cmp.Equal(s.reasons, x.reasons)
}
/retest |
should be part of the issue, or else it will close that entirely. |
@boenn please squash the commits, and reword |
fine, thanks for your guidance.. |
/retest |
1 similar comment
/retest |
https://github.com/kubernetes/kubernetes/pull/103508/files#r665007443 still stands, +1 to your last version where the method |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: boenn, Huang-Wei 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 |
/retest |
1 similar comment
/retest |
/milestone v1.22 |
I understand what you mean, but here I think adding check |
What type of PR is this?
/kind design
What this PR does / why we need it:
Which issue(s) this PR fixes:
Part of #94696
Special notes for your reviewer:
Use cmp.Diff() replace reflect and diagnosis
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
/sig scheduling
/assign @ahg-g