-
Notifications
You must be signed in to change notification settings - Fork 39k
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
Add AddedAffinity to NodeAffinity Filter and Score plugin #96202
Conversation
/triage accepted |
6c935d6
to
62f10b8
Compare
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. |
@alculquicondor can you please see the https://github.com/kubernetes/community/blob/master/sig-architecture/api-review-process.md#mechanics and request an API review? |
/hold I'm looking at the integration test failure. |
62f10b8
to
44ee4e8
Compare
/hold cancel Just needed to update the error message in the integration test check. /label api-review |
|
||
// 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 |
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.
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.
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.
That's fair. Although I find Additional
confusing. What about ImplicitAffinity
? @Huang-Wei @ahg-g any other suggestions?
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.
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
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.
No, that's not the behavior. It's AND
semantics.
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.
Ahh, then yeah something besides Default is a good idea
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.
Not an expert on naming... But yes, "default" is not concise.
Another option: somehow "SupplementalAffinity" jumps out of my mind :)
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.
AppendedAffinity/Constraints
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 am inclined to use additional/added/supplemental adjective
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 am inclined to use additional/added/supplemental adjective
agree those are better than implicit/default
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.
Went with AddedAffinity
@@ -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) | |||
} |
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 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.
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.
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
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.
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 |
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 am inclined to use additional/added/supplemental adjective
agree those are better than implicit/default
// Daemonset Pods might remain unschedulable in some Nodes when this option | ||
// is used. |
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.
generalize this to "pods with affinity requirements that match specific nodes (such as daemonset pods)..."
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.
comments also apply to the versioned types.go
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
af788d7
to
e5d21dd
Compare
e5d21dd
to
cfcff7e
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.
Only found some place forget to rename
pkg/scheduler/apis/config/validation/validation_pluginargs_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/apis/config/validation/validation_pluginargs_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go
Outdated
Show resolved
Hide resolved
pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go
Outdated
Show resolved
Hide resolved
cfcff7e
to
4b16281
Compare
Done |
/priority important-soon |
allErrs = append(allErrs, field.Invalid(f.Child("preferredDuringSchedulingIgnoredDuringExecution"), affinity.PreferredDuringSchedulingIgnoredDuringExecution, err.Error())) | ||
} | ||
} | ||
return allErrs.ToAggregate() |
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.
add a TODO to validate RequiredDuringSchedulingRequiredDuringExecution once implemented
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
/approve one TODO requested, will leave lgtm to scheduler reviewers |
And use it in Filter and Score. Change-Id: I173d8f2d5578762e9873181d5b44ea30b6dbbbc2
4b16281
to
3ce1457
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.
Just a nit/question. LGTM otherwise.
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 |
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.
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]".
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 don't think it's worth.
See my documentation PR https://github.com/kubernetes/website/pull/24914/files#diff-ba98b126fe5dd6bf0570b39d4928eb9143d1f2ed60fbaf9fa2051810acc2e8a6R192
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.
SG.
/retest |
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.
/lgtm
[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 |
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?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: