Skip to content

Commit

Permalink
check all scaling activities instead of just the last one
Browse files Browse the repository at this point in the history
  • Loading branch information
David Morrison committed Mar 2, 2022
1 parent aebd984 commit 8d608ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type asg struct {
minSize int
maxSize int
curSize int
lastUpdateTime *time.Time
lastUpdateTime time.Time

AvailabilityZones []string
LaunchConfigurationName string
Expand Down Expand Up @@ -254,7 +254,7 @@ func (m *asgCache) setAsgSizeNoLock(asg *asg, size int) error {
}

// Proactively set the ASG size so autoscaler makes better decisions
asg.lastUpdateTime = &start
asg.lastUpdateTime = start
asg.curSize = size

return nil
Expand Down Expand Up @@ -489,12 +489,13 @@ func (m *asgCache) isNodeGroupAvailable(group *autoscaling.Group) (bool, error)
return true, err // If we can't describe the scaling activities we assume the node group is available
}

if len(response.Activities) > 0 {
activity := response.Activities[0]
for _, activity := range response.Activities {
asgRef := AwsRef{Name: *group.AutoScalingGroupName}
if a, ok := m.registeredAsgs[asgRef]; ok {
lut := a.lastUpdateTime
if lut != nil && activity.StartTime.After(*lut) && *activity.StatusCode == "Failed" {
if activity.StartTime.Before(lut) {
break
} else if *activity.StatusCode == "Failed" {
return false, nil
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestCreatePlaceholders(t *testing.T) {
name string
desiredCapacity *int64
activities []*autoscaling.Activity
groupLastUpdateTime *time.Time
groupLastUpdateTime time.Time
describeErr error
asgToCheck *string
}{
Expand All @@ -85,7 +85,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(10, 0)),
},
},
groupLastUpdateTime: aws.Time(time.Unix(9, 0)),
groupLastUpdateTime: time.Unix(9, 0),
},
{
name: "AWS scaling failed event before CA scale_up",
Expand All @@ -96,7 +96,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(9, 0)),
},
},
groupLastUpdateTime: aws.Time(time.Unix(10, 0)),
groupLastUpdateTime: time.Unix(10, 0),
},
{
name: "asg not registered",
Expand All @@ -107,7 +107,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(10, 0)),
},
},
groupLastUpdateTime: aws.Time(time.Unix(9, 0)),
groupLastUpdateTime: time.Unix(9, 0),
asgToCheck: aws.String("unregisteredAsgName"),
},
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestCreatePlaceholders(t *testing.T) {
}
asgCache.createPlaceholdersForDesiredNonStartedInstances(groups)
assert.Equal(t, int64(len(groups[0].Instances)), *tc.desiredCapacity)
if tc.activities != nil && *tc.activities[0].StatusCode == "Failed" && tc.activities[0].StartTime.After(*tc.groupLastUpdateTime) && asgName == registeredAsgName {
if tc.activities != nil && *tc.activities[0].StatusCode == "Failed" && tc.activities[0].StartTime.After(tc.groupLastUpdateTime) && asgName == registeredAsgName {
assert.Equal(t, *groups[0].Instances[0].HealthStatus, placeholderUnfulfillableStatus)
} else if len(groups[0].Instances) > 0 {
assert.Equal(t, *groups[0].Instances[0].HealthStatus, "")
Expand Down

0 comments on commit 8d608ac

Please sign in to comment.