@@ -48,6 +48,7 @@ import (
4848 nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
4949 "github.com/openshift-kni/numaresources-operator/internal/api/annotations"
5050 "github.com/openshift-kni/numaresources-operator/internal/platforminfo"
51+ intreconcile "github.com/openshift-kni/numaresources-operator/internal/reconcile"
5152 "github.com/openshift-kni/numaresources-operator/internal/relatedobjects"
5253 "github.com/openshift-kni/numaresources-operator/pkg/apply"
5354 "github.com/openshift-kni/numaresources-operator/pkg/hash"
@@ -115,23 +116,45 @@ func (r *NUMAResourcesSchedulerReconciler) Reconcile(ctx context.Context, req ct
115116 }
116117
117118 initialStatus := * instance .Status .DeepCopy ()
119+ if len (initialStatus .Conditions ) == 0 {
120+ instance .Status .Conditions = status .NewNUMAResourcesSchedulerBaseConditions ()
121+ }
118122
119123 if req .Name != objectnames .DefaultNUMAResourcesSchedulerCrName {
120124 message := fmt .Sprintf ("incorrect NUMAResourcesScheduler resource name: %s" , instance .Name )
121- return ctrl.Result {}, r .updateStatus (ctx , initialStatus , instance , status . ConditionDegraded , status .ConditionTypeIncorrectNUMAResourcesSchedulerResourceName , message )
125+ return ctrl.Result {}, r .degradeStatus (ctx , initialStatus , instance , status .ConditionTypeIncorrectNUMAResourcesSchedulerResourceName , message )
122126 }
123127
124128 if annotations .IsPauseReconciliationEnabled (instance .Annotations ) {
125129 klog .InfoS ("Pause reconciliation enabled" , "object" , req .NamespacedName )
126130 return ctrl.Result {}, nil
127131 }
128132
129- result , condition , err := r .reconcileResource (ctx , instance )
130- if err := r .updateStatus (ctx , initialStatus , instance , condition , status .ReasonFromError (err ), status .MessageFromError (err )); err != nil {
131- klog .InfoS ("Failed to update numaresourcesscheduler status" , "Desired condition" , condition , "error" , err )
133+ step := r .reconcileResource (ctx , instance )
134+ instance .Status .Conditions , _ = status .UpdateConditions (instance .Status .Conditions , step .ConditionInfo .ToMetav1Condition (instance .Generation ), time .Now ())
135+ if err := r .updateStatus (ctx , initialStatus , instance ); err != nil {
136+ klog .InfoS ("Failed to update numaresourcesscheduler status" , "error" , err )
132137 }
133138
134- return result , err
139+ return step .Result , step .Error
140+ }
141+
142+ func (r * NUMAResourcesSchedulerReconciler ) degradeStatus (ctx context.Context , initialStatus nropv1.NUMAResourcesSchedulerStatus , instance * nropv1.NUMAResourcesScheduler , reason string , message string ) error {
143+ condition := metav1.Condition {
144+ Type : status .ConditionDegraded ,
145+ Status : metav1 .ConditionTrue ,
146+ Reason : reason ,
147+ Message : message ,
148+ ObservedGeneration : instance .Generation ,
149+ }
150+
151+ instance .Status .Conditions , _ = status .UpdateConditions (instance .Status .Conditions , condition , time .Now ())
152+
153+ err := r .updateStatus (ctx , initialStatus , instance )
154+ if err != nil {
155+ klog .InfoS ("Failed to update numaresourcesoperator status" , "error" , err )
156+ }
157+ return err
135158}
136159
137160// SetupWithManager sets up the controller with the Manager.
@@ -183,24 +206,24 @@ func (r *NUMAResourcesSchedulerReconciler) nodeToNUMAResourcesScheduler(ctx cont
183206 return requests
184207}
185208
186- func (r * NUMAResourcesSchedulerReconciler ) reconcileResource (ctx context.Context , instance * nropv1.NUMAResourcesScheduler ) (reconcile. Result , string , error ) {
209+ func (r * NUMAResourcesSchedulerReconciler ) reconcileResource (ctx context.Context , instance * nropv1.NUMAResourcesScheduler ) intreconcile. Step {
187210 schedStatus , err := r .syncNUMASchedulerResources (ctx , instance )
188211 if err != nil {
189- return ctrl. Result {}, status . ConditionDegraded , fmt .Errorf ("FailedSchedulerSync: %w" , err )
212+ return intreconcile . StepFailed ( fmt .Errorf ("FailedSchedulerSync: %w" , err ) )
190213 }
191214
192215 instance .Status = schedStatus
193216 instance .Status .RelatedObjects = relatedobjects .Scheduler (r .Namespace , instance .Status .Deployment )
194217
195218 ok , err := isDeploymentRunning (ctx , r .Client , schedStatus .Deployment )
196219 if err != nil {
197- return ctrl. Result {}, status . ConditionDegraded , err
220+ return intreconcile . StepFailed ( err )
198221 }
199222 if ! ok {
200- return ctrl. Result { RequeueAfter : 5 * time .Second }, status . ConditionProgressing , nil
223+ return intreconcile . StepOngoing ( 5 * time .Second )
201224 }
202225
203- return ctrl. Result {}, status . ConditionAvailable , nil
226+ return intreconcile . StepSuccess ()
204227}
205228
206229func isDeploymentRunning (ctx context.Context , c client.Client , key nropv1.NamespacedName ) (bool , error ) {
@@ -303,7 +326,7 @@ func (r *NUMAResourcesSchedulerReconciler) syncNUMASchedulerResources(ctx contex
303326 Duration : cacheResyncPeriod ,
304327 }
305328
306- schedStatus .Conditions = updateDedicatedInformerCondition (status . NewNUMAResourcesSchedulerBaseConditions (), * instance , schedSpec )
329+ schedStatus .Conditions = updateDedicatedInformerCondition (schedStatus . Conditions , instance . Generation , schedSpec )
307330
308331 r .SchedulerManifests .Deployment .Spec .Replicas = schedSpec .Replicas
309332 klog .V (4 ).InfoS ("using scheduler replicas" , "replicas" , * r .SchedulerManifests .Deployment .Spec .Replicas )
@@ -367,52 +390,29 @@ func platformNormalize(spec *nropv1.NUMAResourcesSchedulerSpec, platInfo platfor
367390 klog .V (4 ).InfoS ("SchedulerInformer default is overridden" , "Platform" , platInfo .Platform , "PlatformVersion" , platInfo .Version .String (), "SchedulerInformer" , * spec .SchedulerInformer )
368391}
369392
370- func updateDedicatedInformerCondition (conds []metav1.Condition , instance nropv1.NUMAResourcesScheduler , normalized nropv1.NUMAResourcesSchedulerSpec ) []metav1.Condition {
371- condition := status .FindCondition (conds , status .ConditionDedicatedInformerActive )
372- if condition == nil { // should never happen
373- klog .InfoS ("missing condition: %q" , status .ConditionDedicatedInformerActive )
374- return conds
375- }
376- if normalized .SchedulerInformer == nil { // should never happen
377- klog .InfoS ("nil SchedulerInformer in spec" )
378- condition .Status = metav1 .ConditionUnknown
379- return conds
380- }
393+ func updateDedicatedInformerCondition (conds []metav1.Condition , instanceGeneration int64 , normalized nropv1.NUMAResourcesSchedulerSpec ) []metav1.Condition {
394+ dedicatedStatus := metav1 .ConditionFalse
381395 if * normalized .SchedulerInformer == nropv1 .SchedulerInformerDedicated {
382- condition .Status = metav1 .ConditionTrue
383- } else {
384- condition .Status = metav1 .ConditionFalse
396+ dedicatedStatus = metav1 .ConditionTrue
385397 }
386- condition .ObservedGeneration = instance .Generation
387- return conds
388- }
389398
390- func (r * NUMAResourcesSchedulerReconciler ) updateStatus (ctx context.Context , initialStatus nropv1.NUMAResourcesSchedulerStatus , sched * nropv1.NUMAResourcesScheduler , condition string , reason string , message string ) error {
391- conds := status .CloneConditions (sched .Status .Conditions )
392- if len (conds ) == 0 {
393- conds = status .NewNUMAResourcesSchedulerBaseConditions ()
399+ informerCondition := metav1.Condition {
400+ Type : status .ConditionDedicatedInformerActive ,
401+ Status : dedicatedStatus ,
402+ Reason : status .ConditionDedicatedInformerActive ,
403+ ObservedGeneration : instanceGeneration ,
404+ LastTransitionTime : metav1 .Now (),
394405 }
395- ok := status .UpdateConditionsInPlace (conds , metav1.Condition {
396- Type : condition ,
397- Status : metav1 .ConditionTrue ,
398- ObservedGeneration : sched .Generation ,
399- Reason : reason ,
400- Message : message ,
401- }, time .Now ())
402- if ! ok {
403- klog .InfoS ("fail to update condition" , "conditionType" , condition , "reason" , reason , "message" , message )
404- }
405- // we need to set something anyway
406- sched .Status .Conditions = conds
407406
407+ conds , _ = status .UpdateConditions (conds , informerCondition , time.Time {})
408+ return conds
409+ }
410+
411+ func (r * NUMAResourcesSchedulerReconciler ) updateStatus (ctx context.Context , initialStatus nropv1.NUMAResourcesSchedulerStatus , sched * nropv1.NUMAResourcesScheduler ) error {
408412 if ! status .NUMAResourcesSchedulerNeedsUpdate (initialStatus , sched .Status ) {
409413 return nil
410414 }
411415
412- if status .EqualConditions (initialStatus .Conditions , sched .Status .Conditions ) {
413- sched .Status .Conditions = initialStatus .Conditions
414- }
415-
416416 if err := r .Client .Status ().Update (ctx , sched ); err != nil {
417417 return fmt .Errorf ("could not update status for object %s: %w" , client .ObjectKeyFromObject (sched ), err )
418418 }
0 commit comments