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 AddedAffinity to NodeAffinity Filter and Score plugin #96202

Merged

Conversation

alculquicondor
Copy link
Member

@alculquicondor alculquicondor commented Nov 3, 2020

What type of PR is this?

/kind feature

/kind api-change

What this PR does / why we need it:

/sig scheduling

Add the AddedAffinity to the NodeAffinityArgs and use it in Filter and Score.

This can be used to replace legacy NodeLabel plugin with a more rich API that is consistent with PodSpec.
It can be useful to associate a scheduling profile with a set of Nodes.

Which issue(s) this PR fixes:

Fixes #95738

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NodeAffinity plugin can be configured with AddedAffinity.

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

- [Usage]: https://kubernetes.io/docs/reference/scheduling/config/
- [KEP]: https://git.k8s.io/enhancements/keps/sig-scheduling/785-scheduler-component-config-api

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. labels Nov 3, 2020
@alculquicondor
Copy link
Member Author

/triage accepted
/assign @damemi

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 3, 2020
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. labels Nov 3, 2020
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@dims
Copy link
Member

dims commented Nov 4, 2020

@alculquicondor
Copy link
Member Author

/hold

I'm looking at the integration test failure.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 4, 2020
@alculquicondor
Copy link
Member Author

/hold cancel

Just needed to update the error message in the integration test check.

/label api-review

@k8s-ci-robot k8s-ci-robot added api-review Categorizes an issue or PR as actively needing an API review. area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 4, 2020

// DefaultAffinity is applied to all Pods additionally to the NodeAffinity
// specified in the PodSpec. That is, Nodes need to satisfy DefaultAffinity
// AND .spec.NodeAffinity. DefaultAffinity is empty by default (all Nodes
Copy link
Contributor

Choose a reason for hiding this comment

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

Already using default as the value when pod doesn't specify one somewhere, I guess most people will think about that semantic in the beginning. Maybe call it 'AdditionalNodeAffinity', then can help people to aware that is different semantic.

Copy link
Member Author

@alculquicondor alculquicondor Nov 5, 2020

Choose a reason for hiding this comment

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

That's fair. Although I find Additional confusing. What about ImplicitAffinity? @Huang-Wei @ahg-g any other suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

So if a pod doesn't specify any affinity, we have a default affinity that's applied to it? If this DefaultAffinity is set, does that override the other default affinity? If so, then I think "Default" is fine

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that's not the behavior. It's AND semantics.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, then yeah something besides Default is a good idea

Copy link
Member

Choose a reason for hiding this comment

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

Not an expert on naming... But yes, "default" is not concise.

Another option: somehow "SupplementalAffinity" jumps out of my mind :)

Copy link
Member

Choose a reason for hiding this comment

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

AppendedAffinity/Constraints

Copy link
Member

Choose a reason for hiding this comment

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

I am inclined to use additional/added/supplemental adjective

Copy link
Member

Choose a reason for hiding this comment

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

I am inclined to use additional/added/supplemental adjective

agree those are better than implicit/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.

Went with AddedAffinity

@alculquicondor alculquicondor changed the title Add DefaultAffinity to NodeAffinity Filter plugin Add DefaultAffinity to NodeAffinity Filter and Score plugin Nov 5, 2020
@@ -75,6 +88,9 @@ func (pl *NodeAffinity) Score(ctx context.Context, state *framework.CycleState,
affinity := pod.Spec.Affinity

var count int64
if pl.defPrefSchedTerms != nil {
count += pl.defPrefSchedTerms.Score(node)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the pod specified a same prefered affinity with default one, then that will be double count. For example, the default one is 'in zoneA with weight=1', the pod specified one is 'in zoneA with weight=1 and in zoneB with wieght=2'. In the end, actually zoneA and zoneB have the same weight. That changed the original intent for the user. But this is indeed the AND behavior as the design, just thinking about whether this makes sense for the user. Although I see the major use-case for this feature is required affinity, so I may over thing about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct, and I think that is working as intended.

However, in "AddedAffinity", you would probably use a label that Pods usually don't care about. I'll try to put some thoughts in kubernetes/website#24914

Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

mechanics lgtm, just a couple comments on names/comments


// DefaultAffinity is applied to all Pods additionally to the NodeAffinity
// specified in the PodSpec. That is, Nodes need to satisfy DefaultAffinity
// AND .spec.NodeAffinity. DefaultAffinity is empty by default (all Nodes
Copy link
Member

Choose a reason for hiding this comment

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

I am inclined to use additional/added/supplemental adjective

agree those are better than implicit/default

Comment on lines 195 to 196
// Daemonset Pods might remain unschedulable in some Nodes when this option
// is used.
Copy link
Member

Choose a reason for hiding this comment

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

generalize this to "pods with affinity requirements that match specific nodes (such as daemonset pods)..."

Copy link
Member

Choose a reason for hiding this comment

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

comments also apply to the versioned types.go

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 6, 2020
@alculquicondor alculquicondor changed the title Add DefaultAffinity to NodeAffinity Filter and Score plugin Add AddedAffinity to NodeAffinity Filter and Score plugin Nov 6, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 6, 2020
Copy link
Contributor

@soulxu soulxu left a comment

Choose a reason for hiding this comment

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

Only found some place forget to rename

@alculquicondor
Copy link
Member Author

Only found some place forget to rename

Done

@alculquicondor
Copy link
Member Author

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 9, 2020
allErrs = append(allErrs, field.Invalid(f.Child("preferredDuringSchedulingIgnoredDuringExecution"), affinity.PreferredDuringSchedulingIgnoredDuringExecution, err.Error()))
}
}
return allErrs.ToAggregate()
Copy link
Member

Choose a reason for hiding this comment

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

add a TODO to validate RequiredDuringSchedulingRequiredDuringExecution once implemented

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

@liggitt
Copy link
Member

liggitt commented Nov 9, 2020

/approve
API changes look good, I didn't review the scheduler changes

one TODO requested, will leave lgtm to scheduler reviewers

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 9, 2020
And use it in Filter and Score.

Change-Id: I173d8f2d5578762e9873181d5b44ea30b6dbbbc2
Copy link
Member

@Huang-Wei Huang-Wei left a comment

Choose a reason for hiding this comment

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

Just a nit/question. LGTM otherwise.

Comment on lines +65 to 71
if pl.addedNodeSelector != nil && !pl.addedNodeSelector.Match(node) {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, errReasonEnforced)
}
if !pluginhelper.PodMatchesNodeSelectorAndAffinityTerms(pod, node) {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReason)
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonPod)
}
return nil
Copy link
Member

@Huang-Wei Huang-Wei Nov 9, 2020

Choose a reason for hiding this comment

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

Nit: is it more efficient to do a "smart merge" on addedAffinity and user-specified ones? so that we only run "match logic" once. For example, "foo in [bar]" and "foo in [bar]" gets de-duplicated to "foo in [bar]"; while "foo in [bar]" and "foo in [baz]" gets merged to one entry: "foo in [bar, baz]".

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.

SG.

@alculquicondor
Copy link
Member Author

/retest

Copy link
Contributor

@damemi damemi 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-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 9, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, damemi, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet area/test 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 kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add default node affinity constraints to NodeAffinity plugin
9 participants