-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Add specific errors for pod affinity predicates #51889
Add specific errors for pod affinity predicates #51889
Conversation
Hi @guangxuli. 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 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. I understand the commands that are listed here. |
/cc @bsalamat |
/sig scheduling |
/release-note-none |
834627a
to
b6f92fa
Compare
/retest |
/test pull-kubernetes-e2e-kops-aws |
if !c.satisfiesExistingPodsAntiAffinity(pod, meta, nodeInfo) { | ||
return false, []algorithm.PredicateFailureReason{ErrPodAffinityNotMatch}, nil | ||
if result, err := c.satisfiesExistingPodsAntiAffinity(pod, meta, nodeInfo); !result { | ||
return false, []algorithm.PredicateFailureReason{ErrPodAffinityNotMatch}, err |
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.
We should not return these as errors. We should define three new predicate failure reasons and return them in []algorithm.PredicateFailureReason
in addition to ErrPodAffinityNotMatch
.
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, you are right. I make a misunderstanding. I have made another modification.
b6f92fa
to
5142e51
Compare
@bsalamat ptal, thanks. |
/retest |
|
||
tests := []struct { | ||
pod *v1.Pod | ||
pods []*v1.Pod | ||
nodes []v1.Node | ||
nodes []NodeTest |
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.
optional: instead of a new type ("NodeTest"), you could have added another slice that would list the expected failure reasons in the same order as the nodes array.
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.
reasonable,done
@@ -2564,7 +2572,7 @@ func TestInterPodAffinity(t *testing.T) { | |||
test: "verify that PodAntiAffinity from existing pod is respected when pod has no AntiAffinity constraints. satisfy PodAntiAffinity symmetry with the existing pod", | |||
}, | |||
} | |||
expectedFailureReasons := []algorithm.PredicateFailureReason{ErrPodAffinityNotMatch} | |||
//expectedFailureReasons := []algorithm.PredicateFailureReason{ErrPodAffinityNotMatch} |
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.
Please delete the line.
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.
done
@@ -1115,10 +1115,10 @@ func (c *PodAffinityChecker) getMatchingAntiAffinityTerms(pod *v1.Pod, allPods [ | |||
|
|||
// Checks if scheduling the pod onto this node would break any anti-affinity | |||
// rules indicated by the existing pods. | |||
func (c *PodAffinityChecker) satisfiesExistingPodsAntiAffinity(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) bool { | |||
func (c *PodAffinityChecker) satisfiesExistingPodsAntiAffinity(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, algorithm.PredicateFailureReason) { |
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 see why you are returning algorithm.PredicateFailureReason
in this function, but the failure reason is always ErrExistingPodsAntiAffinityRulesNotMatch
, unless there is an error. It would be better to return an error
instead of algorithm.PredicateFailureReason
and then in InterPodAffinityMatches
function you check the error. If it is nil, you add ErrExistingPodsAntiAffinityRulesNotMatch
to the failure reasons. If it is not nil, you return the error
. You should do this for satisfiesPodsAffinityAntiAffinity
as well. This would be more compatible with the existing behavior and would also address a problem in the current code that errors occurred in satisfiesPodsAffinityAntiAffinity
and satisfiesExistingPodsAntiAffinity
are not trickled up.
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 we don't return algorithm.PredicateFailureReason in function satisfiesPodsAffinityAntiAffinity , we have to check the specific error just as your comment, two cases:
a. check the error: PodAffinityRulesNotMatch
b. check the error: PodAntiAffinityRulesNotMatch
if error is a or b, we add ErrPodsAffinityRulesNotMatch or ErrPodsAntiAffinityRulesNotMatch to algorithm.PredicateFailureReason in addition to ErrPodAffinityNotMatc and return nil. If got other errors we should return the error directly, right?
9643627
to
e928999
Compare
@bsalamat ptal. |
3e3f999
to
a9dabb9
Compare
@bsalamat I have added the specific returning error. IMO, i think there is no need to check the err again which done in original test case. It is enough just to check predicates failure reason. |
a9dabb9
to
63cd9ad
Compare
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. Thanks! Just a minor comment.
@@ -1156,25 +1158,28 @@ func (c *PodAffinityChecker) satisfiesExistingPodsAntiAffinity(pod *v1.Pod, meta | |||
// present in nodeInfo. Pods on other nodes pass the filter. | |||
filteredPods, err := c.podLister.FilteredList(nodeInfo.Filter, labels.Everything()) | |||
if err != nil { | |||
glog.Errorf("Failed to get all pods, %+v", err) | |||
return false | |||
format := "Failed to get all pods, %+v" |
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 would be cleaner (and a bit more efficient) if we did:
errMessage := fmt.sprintf("Failed to get all pods, %+v", err)
glog.Error(errMessage)
return ErrExistingPodsAntiAffinityRulesNotMatch, errors.New(errMessage)
If you agree, please change it for the cases below as well.
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, that's more cleaner than what i have done. :) thanks. Will do.
63cd9ad
to
358c2e9
Compare
358c2e9
to
a724a0f
Compare
@bsalamat All comments have addressed. PTAL. |
Thanks, @guangxuli! /lgtm |
/assign @k82cn |
/test pull-kubernetes-e2e-gce-bazel |
/test pull-kubernetes-e2e-gce-bazel |
1 similar comment
/test pull-kubernetes-e2e-gce-bazel |
@k82cn ptal. |
/test pull-kubernetes-e2e-gce-bazel |
sure, I'll review it today :). |
/approve |
/test pull-kubernetes-e2e-gce-bazel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bsalamat, guangxuli, k82cn Associated issue: 51655 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/retest Review the full test history for this PR. |
/retest |
/test all Tests are more than 96 hours old. Re-running tests. |
Automatic merge from submit-queue (batch tested with PRs 52168, 48939, 51889, 52051, 50396). If you want to cherry-pick this change to another branch, please follow the instructions here.. |
What this PR does / why we need it:
Add specific error for pod affinity predicates
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #fix #51655
Special notes for your reviewer:
none
Release note:
none