Skip to content
Snippets Groups Projects
Commit 8d608ac0 authored by David Morrison's avatar David Morrison
Browse files

check all scaling activities instead of just the last one

parent aebd984e
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ type asg struct { ...@@ -67,7 +67,7 @@ type asg struct {
minSize int minSize int
maxSize int maxSize int
curSize int curSize int
lastUpdateTime *time.Time lastUpdateTime time.Time
AvailabilityZones []string AvailabilityZones []string
LaunchConfigurationName string LaunchConfigurationName string
...@@ -254,7 +254,7 @@ func (m *asgCache) setAsgSizeNoLock(asg *asg, size int) error { ...@@ -254,7 +254,7 @@ func (m *asgCache) setAsgSizeNoLock(asg *asg, size int) error {
} }
// Proactively set the ASG size so autoscaler makes better decisions // Proactively set the ASG size so autoscaler makes better decisions
asg.lastUpdateTime = &start asg.lastUpdateTime = start
asg.curSize = size asg.curSize = size
return nil return nil
...@@ -489,12 +489,13 @@ func (m *asgCache) isNodeGroupAvailable(group *autoscaling.Group) (bool, error) ...@@ -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 return true, err // If we can't describe the scaling activities we assume the node group is available
} }
if len(response.Activities) > 0 { for _, activity := range response.Activities {
activity := response.Activities[0]
asgRef := AwsRef{Name: *group.AutoScalingGroupName} asgRef := AwsRef{Name: *group.AutoScalingGroupName}
if a, ok := m.registeredAsgs[asgRef]; ok { if a, ok := m.registeredAsgs[asgRef]; ok {
lut := a.lastUpdateTime 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 return false, nil
} }
} else { } else {
......
...@@ -59,7 +59,7 @@ func TestCreatePlaceholders(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestCreatePlaceholders(t *testing.T) {
name string name string
desiredCapacity *int64 desiredCapacity *int64
activities []*autoscaling.Activity activities []*autoscaling.Activity
groupLastUpdateTime *time.Time groupLastUpdateTime time.Time
describeErr error describeErr error
asgToCheck *string asgToCheck *string
}{ }{
...@@ -85,7 +85,7 @@ func TestCreatePlaceholders(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(10, 0)), 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", name: "AWS scaling failed event before CA scale_up",
...@@ -96,7 +96,7 @@ func TestCreatePlaceholders(t *testing.T) { ...@@ -96,7 +96,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(9, 0)), StartTime: aws.Time(time.Unix(9, 0)),
}, },
}, },
groupLastUpdateTime: aws.Time(time.Unix(10, 0)), groupLastUpdateTime: time.Unix(10, 0),
}, },
{ {
name: "asg not registered", name: "asg not registered",
...@@ -107,7 +107,7 @@ func TestCreatePlaceholders(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestCreatePlaceholders(t *testing.T) {
StartTime: aws.Time(time.Unix(10, 0)), StartTime: aws.Time(time.Unix(10, 0)),
}, },
}, },
groupLastUpdateTime: aws.Time(time.Unix(9, 0)), groupLastUpdateTime: time.Unix(9, 0),
asgToCheck: aws.String("unregisteredAsgName"), asgToCheck: aws.String("unregisteredAsgName"),
}, },
} }
...@@ -158,7 +158,7 @@ func TestCreatePlaceholders(t *testing.T) { ...@@ -158,7 +158,7 @@ func TestCreatePlaceholders(t *testing.T) {
} }
asgCache.createPlaceholdersForDesiredNonStartedInstances(groups) asgCache.createPlaceholdersForDesiredNonStartedInstances(groups)
assert.Equal(t, int64(len(groups[0].Instances)), *tc.desiredCapacity) 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) assert.Equal(t, *groups[0].Instances[0].HealthStatus, placeholderUnfulfillableStatus)
} else if len(groups[0].Instances) > 0 { } else if len(groups[0].Instances) > 0 {
assert.Equal(t, *groups[0].Instances[0].HealthStatus, "") assert.Equal(t, *groups[0].Instances[0].HealthStatus, "")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment