Skip to content

Commit 8410cb5

Browse files
authored
Merge pull request #3978 from giantswarm/machinepool_subnet_filters
Fail creation of machine pool if no subnets matching filters found
2 parents cb8a777 + be14077 commit 8410cb5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/cloud/services/autoscaling/autoscalinggroup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ func (s *Service) SubnetIDs(scope *scope.MachinePoolScope) ([]string, error) {
526526
for _, subnet := range out.Subnets {
527527
subnetIDs = append(subnetIDs, *subnet.SubnetId)
528528
}
529+
530+
if len(subnetIDs) == 0 {
531+
errMessage := fmt.Sprintf("failed to create ASG %q, no subnets available matching criteria %q", scope.Name(), inputFilters)
532+
record.Warnf(scope.AWSMachinePool, "FailedCreate", errMessage)
533+
return subnetIDs, awserrors.NewFailedDependency(errMessage)
534+
}
529535
}
530536

531537
return scope.SubnetIDs(subnetIDs)

pkg/cloud/services/autoscaling/autoscalinggroup_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,26 @@ func TestServiceUpdateASGWithSubnetFilters(t *testing.T) {
643643
m.UpdateAutoScalingGroup(gomock.AssignableToTypeOf(&autoscaling.UpdateAutoScalingGroupInput{})).Return(&autoscaling.UpdateAutoScalingGroupOutput{}, nil)
644644
},
645645
},
646+
{
647+
name: "should return an error if no matching subnets found",
648+
machinePoolName: "update-asg-fail",
649+
wantErr: true,
650+
awsResourceReference: []infrav1.AWSResourceReference{
651+
{
652+
Filters: []infrav1.Filter{
653+
{
654+
Name: "tag:subnet-role",
655+
Values: []string{"non-existent"},
656+
},
657+
},
658+
},
659+
},
660+
expect: func(e *mocks.MockEC2APIMockRecorder, m *mock_autoscalingiface.MockAutoScalingAPIMockRecorder) {
661+
e.DescribeSubnets(gomock.AssignableToTypeOf(&ec2.DescribeSubnetsInput{})).Return(&ec2.DescribeSubnetsOutput{
662+
Subnets: []*ec2.Subnet{},
663+
}, nil)
664+
},
665+
},
646666
{
647667
name: "should return error if update ASG fails",
648668
machinePoolName: "update-asg-fail",

0 commit comments

Comments
 (0)