From 89ec1c9420da06353fc73e1f80c496cdcdeb02e2 Mon Sep 17 00:00:00 2001 From: ananya-2410 <107847554+ananya-2410@users.noreply.github.com> Date: Thu, 22 Jun 2023 14:09:04 +0530 Subject: [PATCH] scaler(aws_ec2_asg): limit desired capacity between Max and Min size (#27) * Update aws_ec2_asg.go * cap desiredCount between Max Min size * use simple if case --- internal/scaler/awsec2asg/aws_ec2_asg.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/scaler/awsec2asg/aws_ec2_asg.go b/internal/scaler/awsec2asg/aws_ec2_asg.go index 39b5a06..0f50b1e 100644 --- a/internal/scaler/awsec2asg/aws_ec2_asg.go +++ b/internal/scaler/awsec2asg/aws_ec2_asg.go @@ -318,15 +318,22 @@ 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 @@ -334,9 +341,13 @@ func (s *Scaler) Register(ctx context.Context) error { return } + if desiredCapacity < *asg.MinSize { + desiredCapacity = *asg.MinSize + } + updateAsg = &autoscaling.UpdateAutoScalingGroupInput{ AutoScalingGroupName: &inputData.ASGName, - DesiredCapacity: &inputData.DesiredCount, + DesiredCapacity: &desiredCapacity, } }