Skip to content

Commit

Permalink
UPSTREAM: <carry>: Compare against minSize in deleteNodes()
Browse files Browse the repository at this point in the history
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
Once we got all merge we'll put a PR upstream.
  • Loading branch information
enxebre committed May 4, 2020
1 parent be87f46 commit 2bad5d0
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (ng *nodegroup) IncreaseSize(delta int) error {
// Implementation required.
func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
// Step 1: Verify all nodes belong to this node group.

for _, node := range nodes {
actualNodeGroup, err := ng.machineController.nodeGroupForNode(node)
if err != nil {
Expand All @@ -112,10 +113,8 @@ func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
// and we fail fast.
replicas := ng.scalableResource.Replicas()

if replicas-int32(len(nodes)) < 0 {
return fmt.Errorf("unable to delete %d machines in %q, machine replicas are < 0 ", len(nodes), ng.Id())
} else if replicas-int32(len(nodes)) == 0 && !ng.scalableResource.CanScaleFromZero() {
return fmt.Errorf("unable to delete %d machines in %q, machine replicas are 0", len(nodes), ng.Id())
if replicas-int32(len(nodes)) <= int32(ng.MinSize()) {
return fmt.Errorf("unable to delete %d machines in %q, machine replicas are <= %d", len(nodes), ng.Id(), ng.MinSize())
}

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

0 comments on commit 2bad5d0

Please sign in to comment.