Skip to content

Commit

Permalink
Skip ASGs configured with a mixed instances policy
Browse files Browse the repository at this point in the history
  • Loading branch information
cristim committed Jun 27, 2019
1 parent 17d7f87 commit ff4cd3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ func (r *region) findMatchingASGsInPageOfResults(groups []*autoscaling.Group,

for _, group := range groups {
asgName := *group.AutoScalingGroupName

if group.MixedInstancesPolicy != nil {
logger.Printf("Skipping group %s because it's using a mixed instances policy",
asgName)
continue
}

groupMatchesExpectedTags := isASGWithMatchingTags(group, tagsToMatch)
// Go lacks a logical XOR operator, this is the equivalent to that logical
// expression. The goal is to add the matching ASGs when running in opt-in
Expand Down
33 changes: 32 additions & 1 deletion core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestFilterAsgs(t *testing.T) {
want: []string{"asg2", "asg4"},
},
{
name: "Test filters with invalid glob expression",
name: "Test filters with invalid glob expression",
tregion: &region{
tagsToFilterASGsBy: []Tag{
{Key: "spot-enabled", Value: "true"},
Expand Down Expand Up @@ -587,6 +587,37 @@ func TestFilterAsgs(t *testing.T) {
},
want: nullSlice,
},
{
name: "Test skipping execution against mixed groups",
want: []string{"asg1"},
tregion: &region{
tagsToFilterASGsBy: []Tag{{Key: "spot-enabled", Value: "true"}},
conf: &Config{},
services: connections{
autoScaling: mockASG{
dasgo: &autoscaling.DescribeAutoScalingGroupsOutput{
AutoScalingGroups: []*autoscaling.Group{
{
Tags: []*autoscaling.TagDescription{
{Key: aws.String("environment"), Value: aws.String("dev"), ResourceId: aws.String("asg1")},
{Key: aws.String("spot-enabled"), Value: aws.String("true"), ResourceId: aws.String("asg1")},
},
AutoScalingGroupName: aws.String("asg1"),
},
{
MixedInstancesPolicy: &autoscaling.MixedInstancesPolicy{},
Tags: []*autoscaling.TagDescription{
{Key: aws.String("environment"), Value: aws.String("dev"), ResourceId: aws.String("asg2")},
{Key: aws.String("spot-enabled"), Value: aws.String("true"), ResourceId: aws.String("asg2")},
},
AutoScalingGroupName: aws.String("asg2"),
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ff4cd3a

Please sign in to comment.