Skip to content

Commit

Permalink
1.28 Backport fix - Fix/aws asg unsafe decommission kubernetes#5829 k…
Browse files Browse the repository at this point in the history
  • Loading branch information
kmsarabu committed Jul 8, 2024
1 parent eb43120 commit 423d0e6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,26 @@ func (m *asgCache) DeleteInstances(instances []*AwsInstanceRef) error {
}

for _, instance := range instances {

if m.isPlaceholderInstance(instance) {
// skipping placeholder as placeholder instances don't exist
// and we have already reduced ASG size during placeholder check.
continue
}

// check if the instance is already terminating - if it is, don't bother terminating again
// as doing so causes unnecessary API calls and can cause the curSize cached value to decrement
// unnecessarily.
lifecycle, err := m.findInstanceLifecycle(*instance)
if err != nil {
return err
}

if lifecycle != nil &&
*lifecycle == autoscaling.LifecycleStateTerminated ||
*lifecycle == autoscaling.LifecycleStateTerminating ||
*lifecycle == autoscaling.LifecycleStateTerminatingWait ||
*lifecycle == autoscaling.LifecycleStateTerminatingProceed {
klog.V(2).Infof("instance %s is already terminating, will skip instead", instance.Name)
klog.V(2).Infof("instance %s is already terminating in state %s, will skip instead", instance.Name, *lifecycle)
continue
}

Expand All @@ -377,6 +379,7 @@ func (m *asgCache) DeleteInstances(instances []*AwsInstanceRef) error {

// Proactively decrement the size so autoscaler makes better decisions
commonAsg.curSize--

}
return nil
}
Expand Down

0 comments on commit 423d0e6

Please sign in to comment.