@@ -24,6 +24,7 @@ import (
24
24
"github.com/aws/aws-sdk-go/service/autoscaling"
25
25
"github.com/aws/aws-sdk-go/service/ec2"
26
26
"github.com/pkg/errors"
27
+ corev1 "k8s.io/api/core/v1"
27
28
"k8s.io/utils/pointer"
28
29
29
30
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -126,34 +127,17 @@ func (s *Service) ASGIfExists(name *string) (*expinfrav1.AutoScalingGroup, error
126
127
case err != nil :
127
128
record .Eventf (s .scope .InfraCluster (), "FailedDescribeAutoScalingGroups" , "failed to describe ASG %q: %v" , * name , err )
128
129
return nil , errors .Wrapf (err , "failed to describe AutoScaling Group: %q" , * name )
130
+ case len (out .AutoScalingGroups ) == 0 :
131
+ record .Eventf (s .scope .InfraCluster (), corev1 .EventTypeNormal , expinfrav1 .ASGNotFoundReason , "Unable to find ASG matching %q" , * name )
132
+ return nil , nil
129
133
}
130
- //TODO: double check if you're handling nil vals
131
134
return s .SDKToAutoScalingGroup (out .AutoScalingGroups [0 ])
132
135
}
133
136
134
137
// GetASGByName returns the existing ASG or nothing if it doesn't exist.
135
138
func (s * Service ) GetASGByName (scope * scope.MachinePoolScope ) (* expinfrav1.AutoScalingGroup , error ) {
136
- s .scope .Debug ("Looking for existing AutoScalingGroup by name" )
137
-
138
- input := & autoscaling.DescribeAutoScalingGroupsInput {
139
- AutoScalingGroupNames : []* string {
140
- aws .String (scope .Name ()),
141
- },
142
- }
143
-
144
- out , err := s .ASGClient .DescribeAutoScalingGroups (input )
145
- switch {
146
- case awserrors .IsNotFound (err ):
147
- return nil , nil
148
- case err != nil :
149
- record .Eventf (s .scope .InfraCluster (), "FailedDescribeInstances" , "Failed to describe instances by tags: %v" , err )
150
- return nil , errors .Wrap (err , "failed to describe instances by tags" )
151
- case len (out .AutoScalingGroups ) == 0 :
152
- record .Eventf (scope .AWSMachinePool , "FailedDescribeInstances" , "No Auto Scaling Groups with %s found" , scope .Name ())
153
- return nil , nil
154
- }
155
-
156
- return s .SDKToAutoScalingGroup (out .AutoScalingGroups [0 ])
139
+ name := scope .Name ()
140
+ return s .ASGIfExists (& name )
157
141
}
158
142
159
143
// CreateASG runs an autoscaling group.
0 commit comments