@@ -17,6 +17,7 @@ import (
17
17
metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1"
18
18
"github.com/ironcore-dev/metal-operator/internal/api/registry"
19
19
"github.com/ironcore-dev/metal-operator/internal/ignition"
20
+ "github.com/stmcginnis/gofish/redfish"
20
21
v1 "k8s.io/api/core/v1"
21
22
apierrors "k8s.io/apimachinery/pkg/api/errors"
22
23
meta "k8s.io/apimachinery/pkg/api/meta"
@@ -125,6 +126,10 @@ func (r *ServerReconciler) reconcile(ctx context.Context, log logr.Logger, serve
125
126
return ctrl.Result {}, err
126
127
}
127
128
}
129
+ if modified , err := r .handleAnnotionOperations (ctx , log , server ); err != nil || modified {
130
+ return ctrl.Result {}, err
131
+ }
132
+ log .V (1 ).Info ("Handled annotation operations" )
128
133
129
134
if modified , err := clientutils .PatchEnsureFinalizer (ctx , r .Client , server , ServerFinalizer ); err != nil || modified {
130
135
return ctrl.Result {}, err
@@ -812,6 +817,31 @@ func (r *ServerReconciler) applyBiosSettings(ctx context.Context, log logr.Logge
812
817
return nil
813
818
}
814
819
820
+ func (r * ServerReconciler ) handleAnnotionOperations (ctx context.Context , log logr.Logger , server * metalv1alpha1.Server ) (bool , error ) {
821
+ annotations := server .GetAnnotations ()
822
+ operation , ok := annotations [metalv1alpha1 .OperationAnnotation ]
823
+ if ! ok {
824
+ return false , nil
825
+ }
826
+ bmcClient , err := GetBMCClientForServer (ctx , r .Client , server , r .Insecure )
827
+ if err != nil {
828
+ return false , fmt .Errorf ("failed to create BMC client: %w" , err )
829
+ }
830
+ defer bmcClient .Logout ()
831
+ log .V (1 ).Info ("Handling operation" , "Operation" , operation )
832
+ if err := bmcClient .Reset (server .Spec .UUID , redfish .ResetType (operation )); err != nil {
833
+ return false , fmt .Errorf ("failed to reset server: %w" , err )
834
+ }
835
+ log .V (1 ).Info ("Operation completed" , "Operation" , operation )
836
+ serverBase := server .DeepCopy ()
837
+ delete (annotations , metalv1alpha1 .OperationAnnotation )
838
+ server .SetAnnotations (annotations )
839
+ if err := r .Patch (ctx , server , client .MergeFrom (serverBase )); err != nil {
840
+ return false , fmt .Errorf ("failed to patch server annotations: %w" , err )
841
+ }
842
+ return true , nil
843
+ }
844
+
815
845
// SetupWithManager sets up the controller with the Manager.
816
846
func (r * ServerReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
817
847
// Create a channel to send periodic events
0 commit comments