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

Use cmp.Diff() replace reflect and diagnosis #103508

Merged
merged 1 commit into from Jul 9, 2021

Conversation

boenn
Copy link
Contributor

@boenn boenn commented Jul 6, 2021

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?

none

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


/sig scheduling
/assign @ahg-g

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/design Categorizes issue or PR as related to design. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 6, 2021
@k8s-ci-robot
Copy link
Contributor

@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 triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 6, 2021
@k8s-ci-robot
Copy link
Contributor

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 /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/test-infra repository.

@chendave
Copy link
Member

chendave commented Jul 6, 2021

/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 Jul 6, 2021
@boenn
Copy link
Contributor Author

boenn commented Jul 6, 2021

/retest

pkg/scheduler/generic_scheduler_test.go Outdated Show resolved Hide resolved
pkg/scheduler/generic_scheduler_test.go Outdated Show resolved Hide resolved
@chendave
Copy link
Member

chendave commented Jul 7, 2021

/remove-kind design
/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 kind/design Categorizes issue or PR as related to design. labels Jul 7, 2021
@@ -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
}
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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.

@chendave

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

@chendave chendave Jul 8, 2021

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.

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

Copy link
Contributor Author

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

@Huang-Wei

@chendave
Copy link
Member

chendave commented Jul 7, 2021

/retest

@chendave
Copy link
Member

chendave commented Jul 7, 2021

Fixes #94696

should be part of the issue, or else it will close that entirely.

@Huang-Wei
Copy link
Member

@boenn please squash the commits, and reword Fixes #94696 to Part of #94696 in the PR description.

@boenn
Copy link
Contributor Author

boenn commented Jul 8, 2021

@boenn please squash the commits, and reword Fixes #94696 to Part of #94696 in the PR description.

fine, thanks for your guidance..

@boenn
Copy link
Contributor Author

boenn commented Jul 8, 2021

/retest

1 similar comment
@boenn
Copy link
Contributor Author

boenn commented Jul 8, 2021

/retest

@chendave
Copy link
Member

chendave commented Jul 8, 2021

https://github.com/kubernetes/kubernetes/pull/103508/files#r665007443 still stands, +1 to your last version where the method Equal of the Status should be updated.

@Huang-Wei
Copy link
Member

/lgtm
/approve
/retest

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

[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 /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 Jul 8, 2021
@Huang-Wei
Copy link
Member

/retest

1 similar comment
@Huang-Wei
Copy link
Member

/retest

@puerco
Copy link
Member

puerco commented Jul 9, 2021

/milestone v1.22

@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone Jul 9, 2021
@boenn
Copy link
Contributor Author

boenn commented Jul 9, 2021

I understand what you mean, but here I think adding check failedPlugin is redundant, because findNodesThatFitPod doen't have this problem. Maybe it is better to add check failedPlugin and its corresponding test case in another PR.I will continue to think about this problem,thank you。 @chendave

@k8s-ci-robot k8s-ci-robot merged commit 8daced4 into kubernetes:master Jul 9, 2021
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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. 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. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants