@@ -170,27 +170,27 @@ func (r *MachineSetMigrationReconciler) Reconcile(ctx context.Context, req recon
170
170
171
171
logger .Info ("Confirmed syncronized status for to-be authoritative resource" )
172
172
173
- // Add finalizer to new authoritative API.
174
- // This will ensure no status changes on the same reconcile.
175
- // The finalizer must be present on the object before we take any actions.
176
- if addedFinalizer , err := r .ensureFinalizerOnNewAuthoritativeAPI (ctx , mapiMachineSet ); err != nil {
177
- return ctrl.Result {}, fmt .Errorf ("error adding finalizer: %w" , err )
178
- } else if addedFinalizer {
179
- return ctrl.Result {Requeue : true }, nil
180
- }
173
+ // // // Add finalizer to new authoritative API.
174
+ // // // This will ensure no status changes on the same reconcile.
175
+ // // // The finalizer must be present on the object before we take any actions.
176
+ // if addedFinalizer, err := r.ensureFinalizerOnNewAuthoritativeAPI(ctx, mapiMachineSet); err != nil {
177
+ // return ctrl.Result{}, fmt.Errorf("error adding finalizer: %w", err)
178
+ // } else if addedFinalizer {
179
+ // return ctrl.Result{Requeue: true}, nil
180
+ // }
181
181
182
- logger .Info ("Confirmed finalizer on to-be authoritative resource" )
182
+ // logger.Info("Confirmed finalizer on to-be authoritative resource")
183
183
184
- // Remove finalizer from the old authoritative API.
185
- // This will ensure no status changes on the same reconcile.
186
- // The finalizer must be removed from the object before we take any actions.
187
- if removedFinalizer , err := r .ensureFinalizerRemovedOnOldAuthoritativeAPI (ctx , mapiMachineSet ); err != nil {
188
- return ctrl.Result {}, fmt .Errorf ("error removing finalizer: %w" , err )
189
- } else if removedFinalizer {
190
- return ctrl.Result {Requeue : true }, nil
191
- }
184
+ // // Remove finalizer from the old authoritative API.
185
+ // // This will ensure no status changes on the same reconcile.
186
+ // // The finalizer must be removed from the object before we take any actions.
187
+ // if removedFinalizer, err := r.ensureFinalizerRemovedOnOldAuthoritativeAPI(ctx, mapiMachineSet); err != nil {
188
+ // return ctrl.Result{}, fmt.Errorf("error removing finalizer: %w", err)
189
+ // } else if removedFinalizer {
190
+ // return ctrl.Result{Requeue: true}, nil
191
+ // }
192
192
193
- logger .Info ("Confirmed finalizer removed on old authoritative resource" )
193
+ // logger.Info("Confirmed finalizer removed on old authoritative resource")
194
194
195
195
// Set the actual AuthoritativeAPI to the desired one.
196
196
if err := r .applyStatusAuthoritativeAPIWithPatch (ctx , mapiMachineSet , mapiMachineSet .Spec .AuthoritativeAPI ); err != nil {
@@ -364,25 +364,25 @@ func (r *MachineSetMigrationReconciler) ensureFinalizerOnNewAuthoritativeAPI(ctx
364
364
// TODO: InfraMachineTemplate.
365
365
capiMachineSet := & capiv1beta1.MachineSet {}
366
366
if err := r .Get (ctx , client.ObjectKey {Namespace : consts .DefaultManagedNamespace , Name : mapiMachineSet .Name }, capiMachineSet ); err != nil {
367
- return false , fmt .Errorf ("failed to get CAPI machine set: %w" , err )
367
+ return false , fmt .Errorf ("failed to get Cluster API machine set: %w" , err )
368
368
}
369
369
370
370
newAuthoritativeResource = capiMachineSet
371
+ // Check if we need to add the finalizer.
372
+ for _ , finalizer := range newAuthoritativeResource .GetFinalizers () {
373
+ if finalizer == capiv1beta1 .MachineSetFinalizer {
374
+ return false , nil
375
+ }
376
+ }
377
+
378
+ newAuthoritativeResource .SetFinalizers (append (newAuthoritativeResource .GetFinalizers (), capiv1beta1 .MachineSetFinalizer ))
379
+
371
380
case machinev1beta1 .MachineAuthorityMachineAPI :
372
- newAuthoritativeResource = mapiMachineSet
381
+ // No need to set finalizers on the Machine API machine set.
373
382
default :
374
383
// Any other value is disallowed by the openAPI schema validation.
375
384
}
376
385
377
- // Check if we need to add the finalizer.
378
- for _ , finalizer := range newAuthoritativeResource .GetFinalizers () {
379
- if finalizer == migrationControllerFinalizer {
380
- return false , nil
381
- }
382
- }
383
-
384
- newAuthoritativeResource .SetFinalizers (append (newAuthoritativeResource .GetFinalizers (), migrationControllerFinalizer ))
385
-
386
386
if err := r .Update (ctx , newAuthoritativeResource ); err != nil {
387
387
return false , fmt .Errorf ("error updating authoritativeAPI resource: %w" , err )
388
388
}
@@ -396,23 +396,25 @@ func (r *MachineSetMigrationReconciler) ensureFinalizerOnNewAuthoritativeAPI(ctx
396
396
// Removing the finalizer in a separate reconcile ensures that spec updates are separate from status updates.
397
397
func (r * MachineSetMigrationReconciler ) ensureFinalizerRemovedOnOldAuthoritativeAPI (ctx context.Context , mapiMachineSet * machinev1beta1.MachineSet ) (bool , error ) {
398
398
var oldAuthoritativeResource client.Object
399
+ var finalizerToRemove string
399
400
switch mapiMachineSet .Spec .AuthoritativeAPI {
400
401
case machinev1beta1 .MachineAuthorityClusterAPI :
401
402
// TODO: InfraMachineTemplate.
402
403
capiMachineSet := & capiv1beta1.MachineSet {}
403
404
if err := r .Get (ctx , client.ObjectKey {Namespace : consts .DefaultManagedNamespace , Name : mapiMachineSet .Name }, capiMachineSet ); err != nil {
404
- return false , fmt .Errorf ("failed to get CAPI machine set: %w" , err )
405
+ return false , fmt .Errorf ("failed to get Cluster API machine set: %w" , err )
405
406
}
406
407
407
408
oldAuthoritativeResource = capiMachineSet .DeepCopy ()
409
+ finalizerToRemove = capiv1beta1 .MachineSetFinalizer
408
410
case machinev1beta1 .MachineAuthorityMachineAPI :
409
- oldAuthoritativeResource = mapiMachineSet . DeepCopy ()
411
+ // No need to remove any finalizer on the Machine API machine set.
410
412
default :
411
413
// Any other value is disallowed by the openAPI schema validation.
412
414
}
413
415
414
416
// Remove finalizer from the old authoritative API.
415
- if finalizerUpdated := controllerutil .RemoveFinalizer (oldAuthoritativeResource , migrationControllerFinalizer ); finalizerUpdated {
417
+ if finalizerUpdated := controllerutil .RemoveFinalizer (oldAuthoritativeResource , finalizerToRemove ); finalizerUpdated {
416
418
if err := r .Update (ctx , oldAuthoritativeResource ); err != nil {
417
419
return false , fmt .Errorf ("failed to update old authoritativeAPI resource: %w" , err )
418
420
}
0 commit comments