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

Pick the PriorityClass with the lowest value of priority in case more than one global default exists #59991

Merged
merged 4 commits into from
Feb 21, 2018

Conversation

bsalamat
Copy link
Member

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:

Priority admission controller picks a global default with the lowest priority value if more than one such default PriorityClass exists.

/sig scheduling
cc/ @liggitt

@k8s-ci-robot k8s-ci-robot added 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/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 Feb 16, 2018
for _, pci := range list {
if pci.GlobalDefault {
return pci, nil
defaultPCs = append(defaultPCs, pci)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Makes sense. PTAL.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 16, 2018
if defaultPC == nil {
// This is the first default PC found.
defaultPC = pci
} else {
Copy link
Member

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 {
Copy link
Member

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

Copy link
Member Author

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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 17, 2018
@liggitt
Copy link
Member

liggitt commented Feb 17, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 17, 2018
@liggitt
Copy link
Member

liggitt commented Feb 17, 2018

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 {
Copy link
Member

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?

Copy link
Member Author

@bsalamat bsalamat Feb 17, 2018

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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.

@bsalamat
Copy link
Member Author

bsalamat commented Feb 17, 2018

Should document on the API field what happens if multiple objects say they are the default

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.

@liggitt
Copy link
Member

liggitt commented Feb 17, 2018

For the API to be portable, I'd expect the tie-breaking behavior to be specified on the API field

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 17, 2018
@bsalamat bsalamat force-pushed the default_pc branch 2 times, most recently from 702d818 to 573101e Compare February 17, 2018 02:27
@bsalamat
Copy link
Member Author

For the API to be portable, I'd expect the tie-breaking behavior to be specified on the API field

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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. PTAL.

@liggitt
Copy link
Member

liggitt commented Feb 19, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2018
attributes: admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, nil),
expectedDefaultBefore: defaultClass1.Value,
expectedDefaultAfter: defaultClass2.Value,
},
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 have one more test case with 2 default priorityClasses with same priority value then the first one is choosen(as per the current logic).

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@bsalamat
Copy link
Member Author

@deads2k Could you please approve this if you are fine with the change?

@deads2k
Copy link
Contributor

deads2k commented Feb 21, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /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 Feb 21, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 2a604f6 into kubernetes:master Feb 21, 2018
@bsalamat bsalamat deleted the default_pc branch February 22, 2018 03:56
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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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/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.

Priority admission controller should choose one default priority class deterministically
6 participants