Skip to content

Commit

Permalink
Closes #3: Don't decrement desired capacity on termination if desired…
Browse files Browse the repository at this point in the history
… == min
  • Loading branch information
TwiN committed May 8, 2020
1 parent 2c85128 commit b1f4e9a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cloud/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func SetAutoScalingGroupDesiredCount(svc autoscalingiface.AutoScalingAPI, asg *a
return nil
}

func TerminateEc2Instance(svc autoscalingiface.AutoScalingAPI, instance *autoscaling.Instance) error {
func TerminateEc2Instance(svc autoscalingiface.AutoScalingAPI, instance *autoscaling.Instance, shouldDecrementDesiredCapacity bool) error {
_, err := svc.TerminateInstanceInAutoScalingGroup(&autoscaling.TerminateInstanceInAutoScalingGroupInput{
InstanceId: instance.InstanceId,
ShouldDecrementDesiredCapacity: aws.Bool(true),
ShouldDecrementDesiredCapacity: aws.Bool(shouldDecrementDesiredCapacity),
})
return err
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func HandleRollingUpgrade(kubernetesClient k8s.KubernetesClientApi, ec2Service e
if minutesSinceTerminated == -1 {
// Terminate node
log.Printf("[%s][%s] Terminating node", aws.StringValue(autoScalingGroup.AutoScalingGroupName), aws.StringValue(outdatedInstance.InstanceId))
err = cloud.TerminateEc2Instance(autoScalingService, outdatedInstance)
shouldDecrementDesiredCapacity := aws.Int64Value(autoScalingGroup.DesiredCapacity) != aws.Int64Value(autoScalingGroup.MinSize)
err = cloud.TerminateEc2Instance(autoScalingService, outdatedInstance, shouldDecrementDesiredCapacity)
if err != nil {
log.Printf("[%s][%s] Ran into error while terminating node: %v", aws.StringValue(autoScalingGroup.AutoScalingGroupName), aws.StringValue(outdatedInstance.InstanceId), err.Error())
continue
Expand Down

0 comments on commit b1f4e9a

Please sign in to comment.