Skip to content

Commit

Permalink
scaler(aws_ec2_asg): limit desired capacity between Max and Min size (#…
Browse files Browse the repository at this point in the history
…27)

* Update aws_ec2_asg.go

* cap desiredCount between Max Min size

* use simple if case
  • Loading branch information
ananya-2410 authored Jun 22, 2023
1 parent 4795561 commit 89ec1c9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/scaler/awsec2asg/aws_ec2_asg.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,36 @@ func (s *Scaler) Register(ctx context.Context) error {
asg := asgOutput.AutoScalingGroups[0]

var updateAsg *autoscaling.UpdateAutoScalingGroupInput

desiredCapacity := inputData.DesiredCount

if *asg.DesiredCapacity < inputData.DesiredCount {
// scale-out
if s.DisableScaleOut != nil && *s.DisableScaleOut {
return
}

if desiredCapacity > *asg.MaxSize {
desiredCapacity = *asg.MaxSize
}

updateAsg = &autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: &inputData.ASGName,
DesiredCapacity: &inputData.DesiredCount,
DesiredCapacity: &desiredCapacity,
}
} else if *asg.DesiredCapacity > inputData.DesiredCount {
// scale-in
if s.DisableScaleIn != nil && *s.DisableScaleIn {
return
}

if desiredCapacity < *asg.MinSize {
desiredCapacity = *asg.MinSize
}

updateAsg = &autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: &inputData.ASGName,
DesiredCapacity: &inputData.DesiredCount,
DesiredCapacity: &desiredCapacity,
}
}

Expand Down

0 comments on commit 89ec1c9

Please sign in to comment.