Skip to content

Commit

Permalink
Fix reconciling PowerState from serverclaims
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdr committed Jun 20, 2024
1 parent da986bd commit d560f9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 0 additions & 2 deletions bmc/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func (r *RedfishBMC) PowerOn(systemID string) error {
if err := system.Reset(redfish.OnResetType); err != nil {
return fmt.Errorf("failed to reset system to power on state: %w", err)
}
} else {
fmt.Printf("System %s is already powered on.\n", systemID)
}
break
}
Expand Down
21 changes: 13 additions & 8 deletions internal/controller/serverclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,19 @@ func (r *ServerClaimReconciler) reconcile(ctx context.Context, log logr.Logger,
return ctrl.Result{}, fmt.Errorf("failed to get server: %w", err)
}

if server.Status.State != metalv1alpha1.ServerStateAvailable {
log.V(1).Info("Failed to claim server in non available state", "Server", server.Name, "ServerState", server.Status.State)
return ctrl.Result{}, nil
}

// did somebody else claimed this server?
// did somebody else claim this server?
if claimRef := server.Spec.ServerClaimRef; claimRef != nil && claimRef.UID != claim.UID {
log.V(1).Info("Server claim ref UID does not match claim", "Server", server.Name, "ClaimUID", claimRef.UID)
return ctrl.Result{}, nil
}

if err := r.applyBootConfiguration(ctx, server, claim); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to apply boot configuration: %w", err)
// Check server state and only proceed if it is Available or Reserved
if server.Status.State != metalv1alpha1.ServerStateAvailable && server.Status.State != metalv1alpha1.ServerStateReserved {
log.V(1).Info("Server not in a claimable state", "Server", server.Name, "ServerState", server.Status.State)
return ctrl.Result{}, nil
}

// Prepare the server modification ahead of state-specific actions.
serverBase := server.DeepCopy()
server.Spec.ServerClaimRef = &v1.ObjectReference{
APIVersion: "metal.ironcore.dev/v1alpha1",
Expand All @@ -170,6 +168,13 @@ func (r *ServerClaimReconciler) reconcile(ctx context.Context, log logr.Logger,
Name: claim.Name,
UID: claim.UID,
}

if server.Status.State == metalv1alpha1.ServerStateAvailable {
if err := r.applyBootConfiguration(ctx, server, claim); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to apply boot configuration: %w", err)
}
}

server.Spec.Power = claim.Spec.Power
if err := r.Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to patch claim ref for server: %w", err)
Expand Down

0 comments on commit d560f9a

Please sign in to comment.