Skip to content

Commit bac7e93

Browse files
committed
Prevent the binpacking estimator from retrying to add additional nodes
when reaching the limits.
1 parent 6b55dc9 commit bac7e93

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

cluster-autoscaler/estimator/binpacking_estimator.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (e *BinpackingNodeEstimator) Estimate(
108108
}()
109109

110110
estimationState := newEstimationState()
111+
newNodesAvailable := true
111112
for _, podsEquivalenceGroup := range podsEquivalenceGroups {
112113
var err error
113114
var remainingPods []*apiv1.Pod
@@ -118,10 +119,12 @@ func (e *BinpackingNodeEstimator) Estimate(
118119
return 0, nil
119120
}
120121

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+
}
125128
}
126129
}
127130

@@ -160,7 +163,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
160163
estimationState *estimationState,
161164
nodeTemplate *framework.NodeInfo,
162165
pods []*apiv1.Pod,
163-
) error {
166+
) (bool, error) {
164167
for _, pod := range pods {
165168
found := false
166169

@@ -172,7 +175,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
172175
estimationState.trackScheduledPod(pod, estimationState.lastNodeName)
173176
} else if err.Type() == clustersnapshot.SchedulingInternalError {
174177
// Unexpected error.
175-
return err
178+
return false, err
176179
}
177180
// The pod can't be scheduled on the newly created node because of scheduling predicates.
178181
}
@@ -182,7 +185,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
182185
// on a new node either. There is no point adding more nodes to snapshot in such case, especially because of
183186
// performance cost each extra node adds to future FitsAnyNodeMatching calls.
184187
if estimationState.lastNodeName != "" && !estimationState.newNodesWithPods[estimationState.lastNodeName] {
185-
break
188+
return true, nil
186189
}
187190

188191
// Stop binpacking if we reach the limit of nodes we can add.
@@ -192,12 +195,12 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
192195
// each call that returns true, one node gets added. Therefore this
193196
// must be the last check right before really adding a node.
194197
if !e.limiter.PermissionToAddNode() {
195-
break
198+
return false, nil
196199
}
197200

198201
// Add new node
199202
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)
201204
}
202205

203206
// And try to schedule pod to it.
@@ -206,7 +209,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
206209
// adding and removing node to snapshot for each such pod.
207210
if err := e.clusterSnapshot.SchedulePod(pod, estimationState.lastNodeName); err != nil && err.Type() == clustersnapshot.SchedulingInternalError {
208211
// Unexpected error.
209-
return err
212+
return false, err
210213
} else if err != nil {
211214
// The pod can't be scheduled on the new node because of scheduling predicates.
212215
break
@@ -215,7 +218,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
215218
estimationState.trackScheduledPod(pod, estimationState.lastNodeName)
216219
}
217220
}
218-
return nil
221+
return true, nil
219222
}
220223

221224
func (e *BinpackingNodeEstimator) addNewNodeToSnapshot(

0 commit comments

Comments
 (0)