Skip to content

Commit bc0385b

Browse files
committed
wip
1 parent 2e73cf6 commit bc0385b

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

pkg/controllers/machinesetmigration/machineset_migration_controller.go

+34-32
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,27 @@ func (r *MachineSetMigrationReconciler) Reconcile(ctx context.Context, req recon
170170

171171
logger.Info("Confirmed syncronized status for to-be authoritative resource")
172172

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+
// }
181181

182-
logger.Info("Confirmed finalizer on to-be authoritative resource")
182+
// logger.Info("Confirmed finalizer on to-be authoritative resource")
183183

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+
// }
192192

193-
logger.Info("Confirmed finalizer removed on old authoritative resource")
193+
// logger.Info("Confirmed finalizer removed on old authoritative resource")
194194

195195
// Set the actual AuthoritativeAPI to the desired one.
196196
if err := r.applyStatusAuthoritativeAPIWithPatch(ctx, mapiMachineSet, mapiMachineSet.Spec.AuthoritativeAPI); err != nil {
@@ -364,25 +364,25 @@ func (r *MachineSetMigrationReconciler) ensureFinalizerOnNewAuthoritativeAPI(ctx
364364
// TODO: InfraMachineTemplate.
365365
capiMachineSet := &capiv1beta1.MachineSet{}
366366
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)
368368
}
369369

370370
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+
371380
case machinev1beta1.MachineAuthorityMachineAPI:
372-
newAuthoritativeResource = mapiMachineSet
381+
// No need to set finalizers on the Machine API machine set.
373382
default:
374383
// Any other value is disallowed by the openAPI schema validation.
375384
}
376385

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-
386386
if err := r.Update(ctx, newAuthoritativeResource); err != nil {
387387
return false, fmt.Errorf("error updating authoritativeAPI resource: %w", err)
388388
}
@@ -396,23 +396,25 @@ func (r *MachineSetMigrationReconciler) ensureFinalizerOnNewAuthoritativeAPI(ctx
396396
// Removing the finalizer in a separate reconcile ensures that spec updates are separate from status updates.
397397
func (r *MachineSetMigrationReconciler) ensureFinalizerRemovedOnOldAuthoritativeAPI(ctx context.Context, mapiMachineSet *machinev1beta1.MachineSet) (bool, error) {
398398
var oldAuthoritativeResource client.Object
399+
var finalizerToRemove string
399400
switch mapiMachineSet.Spec.AuthoritativeAPI {
400401
case machinev1beta1.MachineAuthorityClusterAPI:
401402
// TODO: InfraMachineTemplate.
402403
capiMachineSet := &capiv1beta1.MachineSet{}
403404
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)
405406
}
406407

407408
oldAuthoritativeResource = capiMachineSet.DeepCopy()
409+
finalizerToRemove = capiv1beta1.MachineSetFinalizer
408410
case machinev1beta1.MachineAuthorityMachineAPI:
409-
oldAuthoritativeResource = mapiMachineSet.DeepCopy()
411+
// No need to remove any finalizer on the Machine API machine set.
410412
default:
411413
// Any other value is disallowed by the openAPI schema validation.
412414
}
413415

414416
// Remove finalizer from the old authoritative API.
415-
if finalizerUpdated := controllerutil.RemoveFinalizer(oldAuthoritativeResource, migrationControllerFinalizer); finalizerUpdated {
417+
if finalizerUpdated := controllerutil.RemoveFinalizer(oldAuthoritativeResource, finalizerToRemove); finalizerUpdated {
416418
if err := r.Update(ctx, oldAuthoritativeResource); err != nil {
417419
return false, fmt.Errorf("failed to update old authoritativeAPI resource: %w", err)
418420
}

0 commit comments

Comments
 (0)