Skip to content

Commit

Permalink
fix: ensure servers always get patched
Browse files Browse the repository at this point in the history
This PR fixes a bug encountered when pivoting clusters where we weren't
updating in-use status on every reconcile loop. Statuses aren't copied
over with a `clusterctl move`, so we need to make sure it gets updated.

Signed-off-by: Spencer Smith <robertspencersmith@gmail.com>
  • Loading branch information
rsmitty committed Aug 20, 2020
1 parent 25cfd1d commit e372d82
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func (r *MetalMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, err
if err = r.Get(ctx, namespacedName, serverResource); err != nil {
return ctrl.Result{}, err
}

// double check server is already marked in use
// this is especially needed after pivoting the cluster from bootstrap -> mgmt plane
if err = r.patchServerInUse(ctx, serverResource); err != nil {
return ctrl.Result{}, err
}
} else {
if metalMachine.Spec.ServerClassRef == nil {
return ctrl.Result{}, fmt.Errorf("either a server or serverclass ref must be supplied")
Expand Down Expand Up @@ -273,10 +279,7 @@ func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, class
}

// patch server with in use bool
serverPatch := client.MergeFrom(serverObj.DeepCopy())
serverObj.Status.InUse = true

if err := r.Status().Patch(ctx, serverObj, serverPatch); err != nil {
if err := r.patchServerInUse(ctx, serverObj); err != nil {
return nil, err
}

Expand Down Expand Up @@ -347,3 +350,15 @@ func (r *MetalMachineReconciler) patchProviderID(ctx context.Context, cluster *c

return nil
}

// patchServerInUse updates a server to mark it as "in use".
func (r *MetalMachineReconciler) patchServerInUse(ctx context.Context, serverObj *metalv1alpha1.Server) error {
serverPatch := client.MergeFrom(serverObj.DeepCopy())
serverObj.Status.InUse = true

if err := r.Status().Patch(ctx, serverObj, serverPatch); err != nil {
return err
}

return nil
}

0 comments on commit e372d82

Please sign in to comment.