-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Pick the PriorityClass with the lowest value of priority in case more than one global default exists #59991
Conversation
for _, pci := range list { | ||
if pci.GlobalDefault { | ||
return pci, nil | ||
defaultPCs = append(defaultPCs, pci) |
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.
Avoid allocation here… happens on every pod admission. Start a value at nil, assign if nil, compare if non nil?
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.
Sure. Makes sense. PTAL.
if defaultPC == nil { | ||
// This is the first default PC found. | ||
defaultPC = pci | ||
} else { |
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.
else if pci.Value < defaultPC.Value { defaultPC = pci }
?
} | ||
} | ||
} | ||
if len(defaultPCs) > 0 { |
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.
Should be able to do the comparison in place rather than accumulating
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.
Absolutely. Fixing a PR while running to a meeting never works. Done.
… than one global default exists
/lgtm |
Should document on the API field what happens if multiple objects say they are the default |
for _, pci := range list { | ||
if pci.GlobalDefault { | ||
return pci, nil | ||
if defaultPC == nil || defaultPC.Value > pci.Value { |
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.
Heh, this is still non-deterministic, since two names can have the same priority. Sort by lowest priority, then by 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.
But that's fine, right? We care about the value of the PriorityClass and also care whether any default class exists or not. If two names have the same priority, the value that we pick will still be the same. We are able to detect whether a default class exists 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.
Doesn't this set the priority class on the pod? So the name it chose would be visible? Seems like we'd want the same name chosen consistently for multiple pods submitted
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.
Ah, looks like it doesn't set priority class, just priority
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.
Right, it only sets the value of priority.
I guess we can. One caveat is that this behavior is coming from an admission controller, not the API itself. So, if a cluster uses a different set of admission controllers, the behavior will be different. We can mention in the documentation that "assuming default admission controller" this will be the behavior. |
For the API to be portable, I'd expect the tie-breaking behavior to be specified on the API field |
702d818
to
573101e
Compare
I updated the API docs as well. PTAL. Thanks! |
@@ -39,6 +39,9 @@ type PriorityClass struct { | |||
|
|||
// globalDefault specifies whether this PriorityClass should be considered as | |||
// the default priority for pods that do not have any priority class. | |||
// Only one PriorityClass with can be marked as `globalDefault`. Due to race conditions, more than |
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.
Calling this a race condition makes it sound like a bug, which it isn't. I would just say that only one should have it, and if multiple do, this is the behavior
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. PTAL.
/lgtm |
attributes: admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, nil), | ||
expectedDefaultBefore: defaultClass1.Value, | ||
expectedDefaultAfter: defaultClass2.Value, | ||
}, |
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 have one more test case with 2 default priorityClasses with same priority value then the first one is choosen(as per the current logic).
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.
When the priority values are the same, how do you want to verify that the first one is picked? Admission controller does not update the "priorityClassName" field. It only sets the value of priority.
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.
Apologies, I wrote my earlier comment in haste. I was under the impression that this tests getDefaultPriorityClass(), it seems we are checking only getDefaultPriority() f(n) in TestDefaultPriority, so we will return always the same value but if we can call getDefaultPriorityClass() f(n) in this test, we can check for the priorityClass being used 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.
I see your point, but getDefaultPriorityClass is used for only two purposes: 1. Whether any default priority classes exists or not, 2. Find the value of default priority. That's why it does not matter which priority class it returns when there are two default priority classes with the same value.
Returning the value of the first priority class is a side effect of the current implementation. It is not necessary for the validity of the logic. For this reason, I believe we should not add a test for it. Having a test may make users and developers think that returning the first priority is a necessary part of the logic. Besides, I am not sure if a lister
is guaranteed to return the list of items always in the same order.
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.
Thanks for the clarification @bsalamat. Yeah, I think that it is a side-effect because we are using a list where order matters.
@deads2k Could you please approve this if you are fine with the change? |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bsalamat, deads2k, liggitt 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 |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
What this PR does / why we need it:
Please see the referenced issue.
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 #59987
Special notes for your reviewer:
Release note:
/sig scheduling
cc/ @liggitt