@@ -108,6 +108,7 @@ func (e *BinpackingNodeEstimator) Estimate(
108
108
}()
109
109
110
110
estimationState := newEstimationState ()
111
+ newNodesAvailable := true
111
112
for _ , podsEquivalenceGroup := range podsEquivalenceGroups {
112
113
var err error
113
114
var remainingPods []* apiv1.Pod
@@ -118,10 +119,12 @@ func (e *BinpackingNodeEstimator) Estimate(
118
119
return 0 , nil
119
120
}
120
121
121
- err = e .tryToScheduleOnNewNodes (estimationState , nodeTemplate , remainingPods )
122
- if err != nil {
123
- klog .Error (err .Error ())
124
- return 0 , nil
122
+ if newNodesAvailable {
123
+ newNodesAvailable , err = e .tryToScheduleOnNewNodes (estimationState , nodeTemplate , remainingPods )
124
+ if err != nil {
125
+ klog .Error (err .Error ())
126
+ return 0 , nil
127
+ }
125
128
}
126
129
}
127
130
@@ -160,7 +163,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
160
163
estimationState * estimationState ,
161
164
nodeTemplate * framework.NodeInfo ,
162
165
pods []* apiv1.Pod ,
163
- ) error {
166
+ ) ( bool , error ) {
164
167
for _ , pod := range pods {
165
168
found := false
166
169
@@ -172,7 +175,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
172
175
estimationState .trackScheduledPod (pod , estimationState .lastNodeName )
173
176
} else if err .Type () == clustersnapshot .SchedulingInternalError {
174
177
// Unexpected error.
175
- return err
178
+ return false , err
176
179
}
177
180
// The pod can't be scheduled on the newly created node because of scheduling predicates.
178
181
}
@@ -182,7 +185,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
182
185
// on a new node either. There is no point adding more nodes to snapshot in such case, especially because of
183
186
// performance cost each extra node adds to future FitsAnyNodeMatching calls.
184
187
if estimationState .lastNodeName != "" && ! estimationState .newNodesWithPods [estimationState .lastNodeName ] {
185
- break
188
+ return true , nil
186
189
}
187
190
188
191
// Stop binpacking if we reach the limit of nodes we can add.
@@ -192,12 +195,12 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
192
195
// each call that returns true, one node gets added. Therefore this
193
196
// must be the last check right before really adding a node.
194
197
if ! e .limiter .PermissionToAddNode () {
195
- break
198
+ return false , nil
196
199
}
197
200
198
201
// Add new node
199
202
if err := e .addNewNodeToSnapshot (estimationState , nodeTemplate ); err != nil {
200
- return fmt .Errorf ("Error while adding new node for template to ClusterSnapshot; %w" , err )
203
+ return false , fmt .Errorf ("Error while adding new node for template to ClusterSnapshot; %w" , err )
201
204
}
202
205
203
206
// And try to schedule pod to it.
@@ -206,7 +209,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
206
209
// adding and removing node to snapshot for each such pod.
207
210
if err := e .clusterSnapshot .SchedulePod (pod , estimationState .lastNodeName ); err != nil && err .Type () == clustersnapshot .SchedulingInternalError {
208
211
// Unexpected error.
209
- return err
212
+ return false , err
210
213
} else if err != nil {
211
214
// The pod can't be scheduled on the new node because of scheduling predicates.
212
215
break
@@ -215,7 +218,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
215
218
estimationState .trackScheduledPod (pod , estimationState .lastNodeName )
216
219
}
217
220
}
218
- return nil
221
+ return true , nil
219
222
}
220
223
221
224
func (e * BinpackingNodeEstimator ) addNewNodeToSnapshot (
0 commit comments