Skip to content

Commit 4acb5e8

Browse files
Substract ongoing deletions before unneeded node verification
1 parent f44fb9f commit 4acb5e8

File tree

1 file changed

+14
-7
lines changed
  • cluster-autoscaler/core/scaledown/unneeded

1 file changed

+14
-7
lines changed

cluster-autoscaler/core/scaledown/unneeded/nodes.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,21 @@ func (n *Nodes) Drop(node string) {
119119
// unneeded, but are not removable, annotated by reason.
120120
func (n *Nodes) RemovableAt(context *context.AutoscalingContext, ts time.Time, resourcesLeft resource.Limits, resourcesWithLimits []string, as scaledown.ActuationStatus) (empty, needDrain []simulator.NodeToBeRemoved, unremovable []*simulator.UnremovableNode) {
121121
nodeGroupSize := utils.GetNodeGroupSizeMap(context.CloudProvider)
122+
substractonOngoingDeletions(nodeGroupSize, as)
122123
resourcesLeftCopy := resourcesLeft.DeepCopy()
123124
emptyNodes, drainNodes := n.splitEmptyAndNonEmptyNodes()
124125

125126
for nodeName, v := range emptyNodes {
126127
klog.V(2).Infof("%s was unneeded for %s", nodeName, ts.Sub(v.since).String())
127-
if r := n.unremovableReason(context, v, ts, nodeGroupSize, resourcesLeftCopy, resourcesWithLimits, as); r != simulator.NoReason {
128+
if r := n.unremovableReason(context, v, ts, nodeGroupSize, resourcesLeftCopy, resourcesWithLimits); r != simulator.NoReason {
128129
unremovable = append(unremovable, &simulator.UnremovableNode{Node: v.ntbr.Node, Reason: r})
129130
continue
130131
}
131132
empty = append(empty, v.ntbr)
132133
}
133134
for nodeName, v := range drainNodes {
134135
klog.V(2).Infof("%s was unneeded for %s", nodeName, ts.Sub(v.since).String())
135-
if r := n.unremovableReason(context, v, ts, nodeGroupSize, resourcesLeftCopy, resourcesWithLimits, as); r != simulator.NoReason {
136+
if r := n.unremovableReason(context, v, ts, nodeGroupSize, resourcesLeftCopy, resourcesWithLimits); r != simulator.NoReason {
136137
unremovable = append(unremovable, &simulator.UnremovableNode{Node: v.ntbr.Node, Reason: r})
137138
continue
138139
}
@@ -141,7 +142,7 @@ func (n *Nodes) RemovableAt(context *context.AutoscalingContext, ts time.Time, r
141142
return
142143
}
143144

144-
func (n *Nodes) unremovableReason(context *context.AutoscalingContext, v *node, ts time.Time, nodeGroupSize map[string]int, resourcesLeft resource.Limits, resourcesWithLimits []string, as scaledown.ActuationStatus) simulator.UnremovableReason {
145+
func (n *Nodes) unremovableReason(context *context.AutoscalingContext, v *node, ts time.Time, nodeGroupSize map[string]int, resourcesLeft resource.Limits, resourcesWithLimits []string) simulator.UnremovableReason {
145146
node := v.ntbr.Node
146147
// Check if node is marked with no scale down annotation.
147148
if eligibility.HasNoScaleDownAnnotation(node) {
@@ -182,7 +183,7 @@ func (n *Nodes) unremovableReason(context *context.AutoscalingContext, v *node,
182183
}
183184
}
184185

185-
if reason := verifyMinSize(node.Name, nodeGroup, nodeGroupSize, as); reason != simulator.NoReason {
186+
if reason := verifyMinSize(node.Name, nodeGroup, nodeGroupSize); reason != simulator.NoReason {
186187
return reason
187188
}
188189

@@ -225,16 +226,22 @@ func (n *Nodes) splitEmptyAndNonEmptyNodes() (empty, needDrain map[string]*node)
225226
return
226227
}
227228

228-
func verifyMinSize(nodeName string, nodeGroup cloudprovider.NodeGroup, nodeGroupSize map[string]int, as scaledown.ActuationStatus) simulator.UnremovableReason {
229+
func verifyMinSize(nodeName string, nodeGroup cloudprovider.NodeGroup, nodeGroupSize map[string]int) simulator.UnremovableReason {
229230
size, found := nodeGroupSize[nodeGroup.Id()]
230231
if !found {
231232
klog.Errorf("Error while checking node group size %s: group size not found in cache", nodeGroup.Id())
232233
return simulator.UnexpectedError
233234
}
234-
deletionsInProgress := as.DeletionsCount(nodeGroup.Id())
235-
if size-deletionsInProgress <= nodeGroup.MinSize() {
235+
if size <= nodeGroup.MinSize() {
236236
klog.V(1).Infof("Skipping %s - node group min size reached", nodeName)
237237
return simulator.NodeGroupMinSizeReached
238238
}
239239
return simulator.NoReason
240240
}
241+
242+
func substractonOngoingDeletions(nodeGroupSize map[string]int, as scaledown.ActuationStatus) {
243+
for nodeGroupId, size := range nodeGroupSize {
244+
deletionsInProgress := as.DeletionsCount(nodeGroupId)
245+
nodeGroupSize[nodeGroupId] = size - deletionsInProgress
246+
}
247+
}

0 commit comments

Comments
 (0)