Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling of Reset ad-hoc operation to Server type #125

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bmc/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BMC interface {
PowerOff(systemUUID string) error

// Reset performs a reset on the system.
Reset() error
Reset(systemUUID string, resetType redfish.ResetType) error

// SetPXEBootOnce sets the boot device for the next system boot.
SetPXEBootOnce(systemUUID string) error
Expand Down
10 changes: 8 additions & 2 deletions bmc/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ func (r *RedfishBMC) PowerOff(systemUUID string) error {
}

// Reset performs a reset on the system using Redfish.
func (r *RedfishBMC) Reset() error {
// Implementation details...
func (r *RedfishBMC) Reset(systemUUID string, resetType redfish.ResetType) error {
system, err := r.getSystemByUUID(systemUUID)
if err != nil {
return fmt.Errorf("failed to get systems: %w", err)
}
if err := system.Reset(resetType); err != nil {
return fmt.Errorf("failed to reset system: %w", err)
}
return nil
}

Expand Down
30 changes: 30 additions & 0 deletions internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1"
"github.com/ironcore-dev/metal-operator/internal/api/registry"
"github.com/ironcore-dev/metal-operator/internal/ignition"
"github.com/stmcginnis/gofish/redfish"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -125,6 +126,10 @@ func (r *ServerReconciler) reconcile(ctx context.Context, log logr.Logger, serve
return ctrl.Result{}, err
}
}
if modified, err := r.handleAnnotionOperations(ctx, log, server); err != nil || modified {
return ctrl.Result{}, err
}
log.V(1).Info("Handled annotation operations")

if modified, err := clientutils.PatchEnsureFinalizer(ctx, r.Client, server, ServerFinalizer); err != nil || modified {
return ctrl.Result{}, err
Expand Down Expand Up @@ -812,6 +817,31 @@ func (r *ServerReconciler) applyBiosSettings(ctx context.Context, log logr.Logge
return nil
}

func (r *ServerReconciler) handleAnnotionOperations(ctx context.Context, log logr.Logger, server *metalv1alpha1.Server) (bool, error) {
annotations := server.GetAnnotations()
operation, ok := annotations[metalv1alpha1.OperationAnnotation]
afritzler marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return false, nil
}
bmcClient, err := GetBMCClientForServer(ctx, r.Client, server, r.Insecure)
if err != nil {
return false, fmt.Errorf("failed to create BMC client: %w", err)
}
defer bmcClient.Logout()
log.V(1).Info("Handling operation", "Operation", operation)
if err := bmcClient.Reset(server.Spec.UUID, redfish.ResetType(operation)); err != nil {
return false, fmt.Errorf("failed to reset server: %w", err)
}
log.V(1).Info("Operation completed", "Operation", operation)
serverBase := server.DeepCopy()
delete(annotations, metalv1alpha1.OperationAnnotation)
server.SetAnnotations(annotations)
if err := r.Patch(ctx, server, client.MergeFrom(serverBase)); err != nil {
return false, fmt.Errorf("failed to patch server annotations: %w", err)
}
return true, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *ServerReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Create a channel to send periodic events
Expand Down