Skip to content

Commit

Permalink
nodeaffinity: scheduler queueing hints
Browse files Browse the repository at this point in the history
  • Loading branch information
carlory committed Dec 14, 2023
1 parent 98748cc commit 5dbb1f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
21 changes: 5 additions & 16 deletions pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (pl *NodeAffinity) EventsToRegister() []framework.ClusterEventWithHint {
// isSchedulableAfterNodeChange is invoked whenever a node changed. It checks whether
// that change made a previously unschedulable pod schedulable.
func (pl *NodeAffinity) isSchedulableAfterNodeChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
originalNode, modifiedNode, err := util.As[*v1.Node](oldObj, newObj)
_, modifiedNode, err := util.As[*v1.Node](oldObj, newObj)
if err != nil {
return framework.Queue, err
}
Expand All @@ -107,25 +107,14 @@ func (pl *NodeAffinity) isSchedulableAfterNodeChange(logger klog.Logger, pod *v1
if err != nil {
return framework.Queue, err
}
if !isMatched {
logger.V(4).Info("node was created or updated, but doesn't matches with the pod's NodeAffinity", "pod", klog.KObj(pod), "node", klog.KObj(modifiedNode))
return framework.QueueSkip, nil
}

wasMatched := false
if originalNode != nil {
wasMatched, err = requiredNodeAffinity.Match(originalNode)
if err != nil {
return framework.Queue, err
}
}

if !wasMatched {
// This modification makes this Node match with Pod's NodeAffinity.
if isMatched {
logger.V(4).Info("node was created or updated, and matches with the pod's NodeAffinity", "pod", klog.KObj(pod), "node", klog.KObj(modifiedNode))
return framework.Queue, nil
}

// TODO: also check if the original node meets the pod's requestments once preCheck is completely removed.
// See: https://github.com/kubernetes/kubernetes/issues/110175

logger.V(4).Info("node was created or updated, but it doesn't make this pod schedulable", "pod", klog.KObj(pod), "node", klog.KObj(modifiedNode))
return framework.QueueSkip, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1226,13 +1226,15 @@ func Test_isSchedulableAfterNodeChange(t *testing.T) {
newObj: st.MakeNode().Label("k", "v").Obj(),
expectedHint: framework.QueueSkip,
},
"skip-labels-changes-on-suitable-node": {
args: &config.NodeAffinityArgs{},
pod: podWithNodeAffinity.DeepCopy(),
oldObj: st.MakeNode().Label("foo", "bar").Obj(),
newObj: st.MakeNode().Label("foo", "bar").Label("k", "v").Obj(),
expectedHint: framework.QueueSkip,
},
// uncomment this case when the isSchedulableAfterNodeChange also check the
// original node's labels.
// "skip-labels-changes-on-suitable-node": {
// args: &config.NodeAffinityArgs{},
// pod: podWithNodeAffinity.DeepCopy(),
// oldObj: st.MakeNode().Label("foo", "bar").Obj(),
// newObj: st.MakeNode().Label("foo", "bar").Label("k", "v").Obj(),
// expectedHint: framework.QueueSkip,
// },
"skip-labels-changes-on-node-from-suitable-to-unsuitable": {
args: &config.NodeAffinityArgs{},
pod: podWithNodeAffinity.DeepCopy(),
Expand Down

0 comments on commit 5dbb1f5

Please sign in to comment.