Skip to content

Commit

Permalink
Ensure serverclaim is bound before proceeding
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdr committed Jul 31, 2024
1 parent 60b5416 commit 2381b91
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions internal/controller/metalmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,20 @@ func (r *MetalMachineReconciler) reconcileNormal(ctx context.Context, machineSco
return ctrl.Result{}, err
}

machineScope.Info("Patching ProviderID in MetalMachine")
if err := r.patchMetalMachineProviderID(ctx, machineScope.Logger, machineScope.MetalMachine, serverClaim); err != nil {
machineScope.Error(err, "failed to patch the MetalMachine with providerid")
return ctrl.Result{}, err
}

if serverClaim.Status.Phase != metalv1alpha1.PhaseBound {
bound, _ := r.ensureServerClaimBound(ctx, serverClaim)
if !bound {
machineScope.Info("Waiting for ServerClaim to be Bound")
return ctrl.Result{
RequeueAfter: infrav1alpha1.DefaultReconcilerRequeue,
}, nil
}

machineScope.Info("Patching ProviderID in MetalMachine")
if err := r.patchMetalMachineProviderID(ctx, machineScope.Logger, machineScope.MetalMachine, serverClaim); err != nil {
machineScope.Error(err, "failed to patch the MetalMachine with providerid")
return ctrl.Result{}, err
}

machineScope.SetReady()
machineScope.Logger.Info("MetalMachine is ready")

Expand Down Expand Up @@ -351,3 +352,15 @@ func (r *MetalMachineReconciler) patchMetalMachineProviderID(ctx context.Context
log.Info("Successfully patched MetalMachine with ProviderID", "ProviderID", providerID)
return nil
}

func (r *MetalMachineReconciler) ensureServerClaimBound(ctx context.Context, serverClaim *metalv1alpha1.ServerClaim) (bool, error) {
claimObj := &metalv1alpha1.ServerClaim{}
if err := r.Get(ctx, client.ObjectKeyFromObject(serverClaim), claimObj); err != nil {
return false, err
}

if claimObj.Status.Phase != metalv1alpha1.PhaseBound {
return false, nil
}
return true, nil
}

0 comments on commit 2381b91

Please sign in to comment.