@@ -228,13 +228,30 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
228228 ec2Svc := r .getEC2Service (ec2Scope )
229229 asgsvc := r .getASGService (clusterScope )
230230
231+ // Find existing ASG
232+ asg , err := r .findASG (machinePoolScope , asgsvc )
233+ if err != nil {
234+ conditions .MarkUnknown (machinePoolScope .AWSMachinePool , expinfrav1 .ASGReadyCondition , expinfrav1 .ASGNotFoundReason , err .Error ())
235+ return err
236+ }
237+
231238 canUpdateLaunchTemplate := func () (bool , error ) {
232239 // If there is a change: before changing the template, check if there exist an ongoing instance refresh,
233240 // because only 1 instance refresh can be "InProgress". If template is updated when refresh cannot be started,
234241 // that change will not trigger a refresh. Do not start an instance refresh if only userdata changed.
242+ if asg == nil {
243+ // If the ASG hasn't been created yet, there is no need to check if we can start the instance refresh.
244+ // But we want to update the LaunchTemplate because an error in the LaunchTemplate may be blocking the ASG creation.
245+ return true , nil
246+ }
235247 return asgsvc .CanStartASGInstanceRefresh (machinePoolScope )
236248 }
237249 runPostLaunchTemplateUpdateOperation := func () error {
250+ // skip instance refresh if ASG is not created yet
251+ if asg == nil {
252+ machinePoolScope .Debug ("ASG does not exist yet, skipping instance refresh" )
253+ return nil
254+ }
238255 // skip instance refresh if explicitly disabled
239256 if machinePoolScope .AWSMachinePool .Spec .RefreshPreferences != nil && machinePoolScope .AWSMachinePool .Spec .RefreshPreferences .Disable {
240257 machinePoolScope .Debug ("instance refresh disabled, skipping instance refresh" )
@@ -261,13 +278,6 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
261278 // set the LaunchTemplateReady condition
262279 conditions .MarkTrue (machinePoolScope .AWSMachinePool , expinfrav1 .LaunchTemplateReadyCondition )
263280
264- // Find existing ASG
265- asg , err := r .findASG (machinePoolScope , asgsvc )
266- if err != nil {
267- conditions .MarkUnknown (machinePoolScope .AWSMachinePool , expinfrav1 .ASGReadyCondition , expinfrav1 .ASGNotFoundReason , err .Error ())
268- return err
269- }
270-
271281 if asg == nil {
272282 // Create new ASG
273283 if err := r .createPool (machinePoolScope , clusterScope ); err != nil {
0 commit comments