@@ -44,10 +44,10 @@ func NewSchedulerPluginRunner(fwHandle *framework.Handle, snapshot clustersnapsh
4444// function - until a Node where the Filters pass is found. Filters are only run for matching Nodes. If no matching Node with passing Filters is found, an error is returned.
4545//
4646// The node iteration always starts from the next Node from the last Node that was found by this method. TODO: Extract the iteration strategy out of SchedulerPluginRunner.
47- func (p * SchedulerPluginRunner ) RunFiltersUntilPassingNode (pod * apiv1.Pod , nodeMatches func (* framework.NodeInfo ) bool ) (string , clustersnapshot.SchedulingError ) {
47+ func (p * SchedulerPluginRunner ) RunFiltersUntilPassingNode (pod * apiv1.Pod , nodeMatches func (* framework.NodeInfo ) bool ) (* apiv1. Node , * schedulerframework. CycleState , clustersnapshot.SchedulingError ) {
4848 nodeInfosList , err := p .snapshot .ListNodeInfos ()
4949 if err != nil {
50- return "" , clustersnapshot .NewSchedulingInternalError (pod , fmt .Sprintf ("error listing NodeInfos: %v" , err ))
50+ return nil , nil , clustersnapshot .NewSchedulingInternalError (pod , fmt .Sprintf ("error listing NodeInfos: %v" , err ))
5151 }
5252
5353 p .fwHandle .DelegatingLister .UpdateDelegate (p .snapshot )
@@ -61,7 +61,7 @@ func (p *SchedulerPluginRunner) RunFiltersUntilPassingNode(pod *apiv1.Pod, nodeM
6161 if ! preFilterStatus .IsSuccess () {
6262 // If any of the plugin PreFilter methods isn't successful, the corresponding Filter method can't be run, so the whole scheduling cycle is aborted.
6363 // Match that behavior here.
64- return "" , clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter failed" , "" )
64+ return nil , nil , clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter failed" , "" )
6565 }
6666
6767 for i := range nodeInfosList {
@@ -92,18 +92,18 @@ func (p *SchedulerPluginRunner) RunFiltersUntilPassingNode(pod *apiv1.Pod, nodeM
9292 if filterStatus .IsSuccess () {
9393 // Filter passed for all plugins, so this pod can be scheduled on this Node.
9494 p .lastIndex = (p .lastIndex + i + 1 ) % len (nodeInfosList )
95- return nodeInfo .Node (). Name , nil
95+ return nodeInfo .Node (), state , nil
9696 }
9797 // Filter didn't pass for some plugin, so this Node won't work - move on to the next one.
9898 }
99- return "" , clustersnapshot .NewNoNodesPassingPredicatesFoundError (pod )
99+ return nil , nil , clustersnapshot .NewNoNodesPassingPredicatesFoundError (pod )
100100}
101101
102102// RunFiltersOnNode runs the scheduler framework PreFilter and Filter phases to check if the given pod can be scheduled on the given node.
103- func (p * SchedulerPluginRunner ) RunFiltersOnNode (pod * apiv1.Pod , nodeName string ) clustersnapshot.SchedulingError {
103+ func (p * SchedulerPluginRunner ) RunFiltersOnNode (pod * apiv1.Pod , nodeName string ) ( * apiv1. Node , * schedulerframework. CycleState , clustersnapshot.SchedulingError ) {
104104 nodeInfo , err := p .snapshot .GetNodeInfo (nodeName )
105105 if err != nil {
106- return clustersnapshot .NewSchedulingInternalError (pod , fmt .Sprintf ("error obtaining NodeInfo for name %q: %v" , nodeName , err ))
106+ return nil , nil , clustersnapshot .NewSchedulingInternalError (pod , fmt .Sprintf ("error obtaining NodeInfo for name %q: %v" , nodeName , err ))
107107 }
108108
109109 p .fwHandle .DelegatingLister .UpdateDelegate (p .snapshot )
@@ -113,10 +113,10 @@ func (p *SchedulerPluginRunner) RunFiltersOnNode(pod *apiv1.Pod, nodeName string
113113 // Run the PreFilter phase of the framework for the Pod and check the results. See the corresponding comments in RunFiltersUntilPassingNode() for more info.
114114 preFilterResult , preFilterStatus , _ := p .fwHandle .Framework .RunPreFilterPlugins (context .TODO (), state , pod )
115115 if ! preFilterStatus .IsSuccess () {
116- return clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter failed" , "" )
116+ return nil , nil , clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter failed" , "" )
117117 }
118118 if ! preFilterResult .AllNodes () && ! preFilterResult .NodeNames .Has (nodeInfo .Node ().Name ) {
119- return clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter filtered the Node out" , "" )
119+ return nil , nil , clustersnapshot .NewFailingPredicateError (pod , preFilterStatus .Plugin (), preFilterStatus .Reasons (), "PreFilter filtered the Node out" , "" )
120120 }
121121
122122 // Run the Filter phase of the framework for the Pod and the Node and check the results. See the corresponding comments in RunFiltersUntilPassingNode() for more info.
@@ -128,10 +128,22 @@ func (p *SchedulerPluginRunner) RunFiltersOnNode(pod *apiv1.Pod, nodeName string
128128 if ! filterStatus .IsRejected () {
129129 unexpectedErrMsg = fmt .Sprintf ("unexpected filter status %q" , filterStatus .Code ().String ())
130130 }
131- return clustersnapshot .NewFailingPredicateError (pod , filterName , filterReasons , unexpectedErrMsg , p .failingFilterDebugInfo (filterName , nodeInfo ))
131+ return nil , nil , clustersnapshot .NewFailingPredicateError (pod , filterName , filterReasons , unexpectedErrMsg , p .failingFilterDebugInfo (filterName , nodeInfo ))
132132 }
133133
134134 // PreFilter and Filter phases checked, this Pod can be scheduled on this Node.
135+ return nodeInfo .Node (), state , nil
136+ }
137+
138+ // RunReserveOnNode runs the scheduler framework Reserve phase to update the scheduler plugins state to reflect the Pod being scheduled on the Node.
139+ func (p * SchedulerPluginRunner ) RunReserveOnNode (pod * apiv1.Pod , nodeName string , postFilterState * schedulerframework.CycleState ) error {
140+ p .fwHandle .DelegatingLister .UpdateDelegate (p .snapshot )
141+ defer p .fwHandle .DelegatingLister .ResetDelegate ()
142+
143+ status := p .fwHandle .Framework .RunReservePluginsReserve (context .Background (), postFilterState , pod , nodeName )
144+ if ! status .IsSuccess () {
145+ return fmt .Errorf ("couldn't reserve node %s for pod %s/%s: %v" , nodeName , pod .Namespace , pod .Name , status .Message ())
146+ }
135147 return nil
136148}
137149
0 commit comments