@@ -226,13 +226,30 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
226
226
ec2Svc := r .getEC2Service (ec2Scope )
227
227
asgsvc := r .getASGService (clusterScope )
228
228
229
+ // Find existing ASG
230
+ asg , err := r .findASG (machinePoolScope , asgsvc )
231
+ if err != nil {
232
+ conditions .MarkUnknown (machinePoolScope .AWSMachinePool , expinfrav1 .ASGReadyCondition , expinfrav1 .ASGNotFoundReason , err .Error ())
233
+ return err
234
+ }
235
+
229
236
canUpdateLaunchTemplate := func () (bool , error ) {
230
237
// If there is a change: before changing the template, check if there exist an ongoing instance refresh,
231
238
// because only 1 instance refresh can be "InProgress". If template is updated when refresh cannot be started,
232
239
// that change will not trigger a refresh. Do not start an instance refresh if only userdata changed.
240
+ if asg == nil {
241
+ // If the ASG hasn't been created yet, there is no need to check if we can start the instance refresh.
242
+ // But we want to update the LaunchTemplate because an error in the LaunchTemplate may be blocking the ASG creation.
243
+ return true , nil
244
+ }
233
245
return asgsvc .CanStartASGInstanceRefresh (machinePoolScope )
234
246
}
235
247
runPostLaunchTemplateUpdateOperation := func () error {
248
+ // skip instance refresh if ASG is not created yet
249
+ if asg == nil {
250
+ machinePoolScope .Debug ("ASG does not exist yet, skipping instance refresh" )
251
+ return nil
252
+ }
236
253
// skip instance refresh if explicitly disabled
237
254
if machinePoolScope .AWSMachinePool .Spec .RefreshPreferences != nil && machinePoolScope .AWSMachinePool .Spec .RefreshPreferences .Disable {
238
255
machinePoolScope .Debug ("instance refresh disabled, skipping instance refresh" )
@@ -259,13 +276,6 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
259
276
// set the LaunchTemplateReady condition
260
277
conditions .MarkTrue (machinePoolScope .AWSMachinePool , expinfrav1 .LaunchTemplateReadyCondition )
261
278
262
- // Find existing ASG
263
- asg , err := r .findASG (machinePoolScope , asgsvc )
264
- if err != nil {
265
- conditions .MarkUnknown (machinePoolScope .AWSMachinePool , expinfrav1 .ASGReadyCondition , expinfrav1 .ASGNotFoundReason , err .Error ())
266
- return err
267
- }
268
-
269
279
if asg == nil {
270
280
// Create new ASG
271
281
if err := r .createPool (machinePoolScope , clusterScope ); err != nil {
0 commit comments