Skip to content

Commit

Permalink
Fix multiple ServerClaims claiming same Server object
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Oct 30, 2024
1 parent a2edca0 commit 248d1b4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/controller/serverclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ func (r *ServerClaimReconciler) reconcile(ctx context.Context, log logr.Logger,
}
log.V(1).Info("Applied BootConfiguration for ServerClaim")

if modified, err := r.ensureObjectRefForServer(ctx, log, claim, server); err != nil || modified {
return ctrl.Result{}, err
}
log.V(1).Info("Ensured ObjectRef for Server", "Server", server.Name)

if modified, err := r.patchServerClaimPhase(ctx, claim, metalv1alpha1.PhaseBound); err != nil || modified {
return ctrl.Result{}, err
}
Expand All @@ -185,6 +180,7 @@ func (r *ServerClaimReconciler) reconcile(ctx context.Context, log logr.Logger,

func (r *ServerClaimReconciler) ensureObjectRefForServer(ctx context.Context, log logr.Logger, claim *metalv1alpha1.ServerClaim, server *metalv1alpha1.Server) (bool, error) {
if server.Spec.ServerClaimRef != nil {
log.V(1).Info("Server is already claimed", "Server", server.Name, "Claim", server.Spec.ServerClaimRef.Name)
return false, nil
}

Expand Down Expand Up @@ -332,6 +328,12 @@ func (r *ServerClaimReconciler) claimServer(ctx context.Context, log logr.Logger
return nil, nil
}
log.V(1).Info("Matching server found", "Server", server.Name)

if modified, err := r.ensureObjectRefForServer(ctx, log, claim, server); err != nil || modified {
return nil, err
}
log.V(1).Info("Ensured ObjectRef for Server", "Server", server.Name)

return server, nil
}

Expand Down

0 comments on commit 248d1b4

Please sign in to comment.