Skip to content

Commit dac1f7d

Browse files
enxebreelmiko
authored andcommitted
Compare against minSize in deleteNodes() in cluster-autoscaler CAPI
provider When calling deleteNodes() we should fail early if the operation could delete nodes below the nodeGroup minSize(). This is one in a series of PR to mitigate kubernetes#3104
1 parent 9c8b78a commit dac1f7d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
9595
ng.machineController.accessLock.Lock()
9696
defer ng.machineController.accessLock.Unlock()
9797

98+
replicas, err := ng.scalableResource.Replicas()
99+
if err != nil {
100+
return err
101+
}
102+
103+
// if we are at minSize already we wail early.
104+
if int(replicas) <= ng.MinSize() {
105+
return fmt.Errorf("min size reached, nodes will not be deleted")
106+
}
107+
98108
// Step 1: Verify all nodes belong to this node group.
99109
for _, node := range nodes {
100110
actualNodeGroup, err := ng.machineController.nodeGroupForNode(node)
@@ -112,15 +122,10 @@ func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
112122
}
113123

114124
// Step 2: if deleting len(nodes) would make the replica count
115-
// <= 0, then the request to delete that many nodes is bogus
125+
// < minSize, then the request to delete that many nodes is bogus
116126
// and we fail fast.
117-
replicas, err := ng.scalableResource.Replicas()
118-
if err != nil {
119-
return err
120-
}
121-
122-
if replicas-int32(len(nodes)) <= 0 {
123-
return fmt.Errorf("unable to delete %d machines in %q, machine replicas are <= 0 ", len(nodes), ng.Id())
127+
if replicas-int32(len(nodes)) < int32(ng.MinSize()) {
128+
return fmt.Errorf("unable to delete %d machines in %q, machine replicas are %q, minSize is %q ", len(nodes), ng.Id(), replicas, ng.MinSize())
124129
}
125130

126131
// Step 3: annotate the corresponding machine that it is a

0 commit comments

Comments
 (0)