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

Add PriorityClass API object under new "scheduling" API group #48377

Merged
merged 3 commits into from Jul 20, 2017

Conversation

bsalamat
Copy link
Member

@bsalamat bsalamat commented Jul 1, 2017

What this PR does / why we need it: This PR is a part of a series of PRs to add pod priority to Kubernetes. This PR adds a new API group called "scheduling" with a new API object called "PriorityClass". PriorityClass maps the string value of priority to its integer value.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer: Given the size of this PR, I will add the admission controller for the PriorityClass in a separate PR.

Release note:

Add PriorityClass API object under new "scheduling" API group

ref/ #47604
ref/ #48646

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 1, 2017
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/new-api size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jul 1, 2017
@bsalamat
Copy link
Member Author

bsalamat commented Jul 1, 2017

@kubernetes/api-approvers
@kubernetes/api-reviewers
@kubernetes/sig-scheduling-api-reviews
@kubernetes/sig-scheduling-pr-reviews

@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Jul 1, 2017
// integer value. The value can be any valid integer.
type PriorityClass struct {
metav1.TypeMeta
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding more comments here?

// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, @gyliu513 ! Done.

// PriorityClassList is a collection of priority classes.
type PriorityClassList struct {
metav1.TypeMeta
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

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

        // Standard list metadata.
	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
	// +optional

allErrs := apivalidation.ValidateObjectMetaUpdate(&pc.ObjectMeta, &oldPc.ObjectMeta, field.NewPath("metadata"))
// Name is immutable and is checked by the ObjectMeta validator.
if pc.Value != oldPc.Value {
allErrs = append(allErrs, field.Forbidden(field.NewPath("Value"), "may not be changed in an update."))
Copy link
Contributor

Choose a reason for hiding this comment

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

How about putting the Value in the error message?

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 think putting the value in the error message is a bit misleading and may make users think that there is an issue with the value itself. We don't allow changing value regardless of its content.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense, thanks @bsalamat

if pc.Value != oldPc.Value {
allErrs = append(allErrs, field.Forbidden(field.NewPath("Value"), "may not be changed in an update."))
}
if pc.GlobalDefault != oldPc.GlobalDefault {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why cannot change GlobalDefault? It not, the comments for this fn also need some update.

Copy link
Member Author

@bsalamat bsalamat Jul 5, 2017

Choose a reason for hiding this comment

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

It has a similar problem to changing value, i.e., if the GlobalDefault changes, the integer value of pods without any priority class which were resolved before the change of GlobalDefault may confuse users. Besides, there is a risk of having multiple priority classes with GlobalDefault set. I updated the comment.

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 revisited the idea of letting GlobalDefault be updatable today. I can prevent users from setting multiple priority classes as default in the admission controller. So, the main risk can be mitigated. The confusion problem of updating GlobalDefault stills remain, but the flexibility that allowing the update provides may justify it. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is always good idea to mitigate the risk even though it cannot fully resolve the issue, +1 on this, thanks @bsalamat ;-)

allErrs = append(allErrs, field.Forbidden(field.NewPath("Value"), "may not be changed in an update."))
}
if pc.GlobalDefault != oldPc.GlobalDefault {
allErrs = append(allErrs, field.Forbidden(field.NewPath("GlobalDefault"), "may not be changed in an update."))
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding the GlobalDefault to the error message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to my comment about putting value in the error message, I think it may be misleading.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2017
@bsalamat bsalamat force-pushed the priority_class branch 2 times, most recently from 41fd2a1 to e9cea8b Compare July 5, 2017 21:58
@bsalamat
Copy link
Member Author

bsalamat commented Jul 5, 2017

ref/ kubernetes/community#604

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2017
@justinsb
Copy link
Member

justinsb commented Jul 6, 2017

/lgtm

This is probably api-machinery for approval though.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 6, 2017
@justinsb justinsb added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jul 6, 2017
func ValidatePriorityClassUpdate(pc, oldPc *scheduling.PriorityClass) field.ErrorList {
allErrs := apivalidation.ValidateObjectMetaUpdate(&pc.ObjectMeta, &oldPc.ObjectMeta, field.NewPath("metadata"))
// Name is immutable and is checked by the ObjectMeta validator.
if pc.Value != oldPc.Value {
Copy link
Member

Choose a reason for hiding this comment

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

The comments say that Name and Value are immutable, but you check Value & GlobalDefault.

Copy link
Member

Choose a reason for hiding this comment

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

+1

btw, do we allow update Default?

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 fixed the comment to say that Name, Value, and GlobalDefault are immutable. Name is checked by the default validation of metadata.

@k82cn no, we don't.

Copy link
Member

Choose a reason for hiding this comment

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

Got it; and there'll be only one default priority in the cluster, right? and we'll check it in admission controller.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, and yes!

old := scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: "", ResourceVersion: "1",
Annotations: map[string]string{
"kbernetes.io/description": "Used for the highest priority pods.",
Copy link
Member

Choose a reason for hiding this comment

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

typo: kbernetes

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I removed the whole annotation. I learned that we should not use annotations for information which should be discoverable by users. So, I changed description from an annotation to a field and this was a remnant of the initial code. Thanks for pointing it out!

)

// GroupName is the group name use in this package
const GroupName = "scheduling.k8s.io"
Copy link
Member

Choose a reason for hiding this comment

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

scheduling? seems others are without k8s.io.

Copy link
Member Author

Choose a reason for hiding this comment

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

Our document says that we should use xyz.k8s.io. Some of the other groups use the k8s.io suffix and some don't. I think the suffix is preferred.

Copy link
Member

Choose a reason for hiding this comment

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

Can you share the doc link? if xxx.k8s.io is preferred, I think we need to open a PR/Issue to correct others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Opened #48527 to align the GroupName. lgtm for this PR.

func ValidatePriorityClassUpdate(pc, oldPc *scheduling.PriorityClass) field.ErrorList {
allErrs := apivalidation.ValidateObjectMetaUpdate(&pc.ObjectMeta, &oldPc.ObjectMeta, field.NewPath("metadata"))
// Name is immutable and is checked by the ObjectMeta validator.
if pc.Value != oldPc.Value {
Copy link
Member

Choose a reason for hiding this comment

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

+1

btw, do we allow update Default?

},
}

for k, v := range errorCases {
Copy link
Member

Choose a reason for hiding this comment

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

suggest merge errorCases & successCases like others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some of the other groups, such as autoscaling, storage, rbac, ... follow this pattern of separate error and success cases.

// set correctly.
func ValidatePriorityClass(pc *scheduling.PriorityClass) field.ErrorList {
allErrs := field.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&pc.ObjectMeta, false, ValidatePriorityClassName, field.NewPath("metadata"))...)
Copy link
Member

Choose a reason for hiding this comment

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

PriorityClass is global by default, so the namespace should be empty.

Copy link
Member Author

@bsalamat bsalamat Jul 6, 2017

Choose a reason for hiding this comment

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

The API object is defined as "nonNamespaced" in staging/src/k8s.io/api/scheduling/v1alpha1/types.go. My understanding is that the system enforces the rule of not having a namespace for "nonNamespaced" resources.
We have tests that verify it does not take any namespace.

Copy link
Member

Choose a reason for hiding this comment

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

Great to know !

BTW, do you know which component handled nonNamespaced ? just want to learn :).

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 don't know. I wonder if the // +nonNamespaced=true annotation in the types.go file causes some validation code to be generated that checks this.

Copy link
Member

Choose a reason for hiding this comment

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

ok, np.

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

@gyliu513 gyliu513 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 7, 2017
@bsalamat
Copy link
Member Author

/assign @smarterclayton
For approval

@lavalamp lavalamp added sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jul 13, 2017
@lavalamp
Copy link
Member

@justinsb SIG API Machinery doesn't own the contents of the API.

@cblecker
Copy link
Member

cross-build is currently broken: #48887

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 14, 2017
@bsalamat
Copy link
Member Author

@smarterclayton Fixed the comments. PTAL.

@cblecker
Copy link
Member

/test pull-kubernetes-cross


// PriorityClass defines the mapping from a priority class name to the priority
// integer value. The value can be any valid integer.
type PriorityClass struct {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry that I'm behind on reviews... trying pretty frantically to catch up.

Why exactly do we create our own api group, and won't this need to be referenced by the main pod objects? B/c we don't typically cross groups, they are self contained.

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 tried to see if we can place the PriorityClass in any of the existing API groups, but it didn't really fit nicely in any of them. So, I spoke with @thockin and the conclusion was to create a new API group for scheduling.

The priority class is not being referenced by pod objects. Pod API can have a PriorityClass name which is resolved to its integer value by an admission controller. The integer value is set in the pod object and all the components of the system will work with this integer value.

Copy link
Member

Choose a reason for hiding this comment

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

That is wonky to me, what other api constructs split across groups like this?

Copy link
Member

Choose a reason for hiding this comment

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

PV.Spec.StorageClassName and storage.k8s.io/StorageClass. I agree it's weird.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, storage class is similar to this as well. Why are the API groups should be self contained? What is the concern with referencing an API group from another one?

Copy link
Member

Choose a reason for hiding this comment

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

It's just a UX issue and consistency thing. Operators already have a tough time rationalizing the system. We should be sure to document this accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no doubt about documenting it, but my understanding is that API groups are not exposed to operators. In other words, when one adds a PriorityClass, for example, she adds it the same way no matter which API group the PriorityClass is located in.

Copy link
Member

Choose a reason for hiding this comment

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

my understanding is that API groups are not exposed to operators. In other words, when one adds a PriorityClass, for example, she adds it the same way no matter which API group the PriorityClass is located in.

That is definitely not correct. The API group is included in the object definition, and is required to fully-qualify the object kind.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is definitely not correct. The API group is included in the object definition, and is required to fully-qualify the object kind.

True. I guess you are referring to apiVersion in object definition where API group is mentioned.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 18, 2017
@bsalamat bsalamat force-pushed the priority_class branch 2 times, most recently from 30c9f6c to 036f93d Compare July 18, 2017 22:35
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 18, 2017
Add PriorityClass to pkg/registry

Add PriorityClass to pkg/master/master.go

Add PriorityClass to import_know_versions.go

Update linted packages

minor fix
@bsalamat
Copy link
Member Author

ping @smarterclayton

@smarterclayton
Copy link
Contributor

/approve

@smarterclayton
Copy link
Contributor

/lgtm

As well

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bsalamat, davidopp, gyliu513, justinsb, smarterclayton

No associated issue. Update pull-request body to add a reference to an issue, or get approval with /approve no-issue

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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 20, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 8d26afa into kubernetes:master Jul 20, 2017
@bsalamat bsalamat deleted the priority_class branch July 20, 2017 04:50
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/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet