Skip to content

Commit

Permalink
Compare updated opreq status with latest opreq (#950)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan authored Jul 20, 2023
1 parent 6450c26 commit 3519d07
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions controllers/operandrequest/operandrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re

// Always attempt to patch the status after each reconciliation.
defer func() {
if reflect.DeepEqual(originalInstance.Status, requestInstance.Status) {
// get the latest instance from the server and check if the status has changed
existingInstance := &operatorv1alpha1.OperandRequest{}
if err := r.Client.Get(ctx, req.NamespacedName, existingInstance); err != nil {
// Error reading the latest object - requeue the request.
reconcileErr = utilerrors.NewAggregate([]error{reconcileErr, fmt.Errorf("error while get latest OperandRequest.Status from server: %v", err)})
}

if reflect.DeepEqual(existingInstance.Status, requestInstance.Status) {
return
}
if err := r.Client.Status().Patch(ctx, requestInstance, client.MergeFrom(originalInstance)); err != nil && !apierrors.IsNotFound(err) {
if err := r.Client.Status().Patch(ctx, requestInstance, client.MergeFrom(existingInstance)); err != nil && !apierrors.IsNotFound(err) {
reconcileErr = utilerrors.NewAggregate([]error{reconcileErr, fmt.Errorf("error while patching OperandRequest.Status: %v", err)})
}
}()
Expand Down

0 comments on commit 3519d07

Please sign in to comment.