Optimize the code of NodeUnschedulable to reduce TolerationsTolerateTaint function calls

Signed-off-by: wackxu <xushiwei5@huawei.com>
This commit is contained in:
wackxu 2023-07-18 21:00:05 +08:00
parent b2a9c06b2e
commit a9d26ac7c7

View File

@ -61,14 +61,19 @@ func (pl *NodeUnschedulable) Name() string {
func (pl *NodeUnschedulable) Filter(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
node := nodeInfo.Node()
if !node.Spec.Unschedulable {
return nil
}
// If pod tolerate unschedulable taint, it's also tolerate `node.Spec.Unschedulable`.
podToleratesUnschedulable := v1helper.TolerationsTolerateTaint(pod.Spec.Tolerations, &v1.Taint{
Key: v1.TaintNodeUnschedulable,
Effect: v1.TaintEffectNoSchedule,
})
if node.Spec.Unschedulable && !podToleratesUnschedulable {
if !podToleratesUnschedulable {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonUnschedulable)
}
return nil
}