Skip to content

Commit

Permalink
Update status conditions during reconcile error (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnugeorge authored and k8s-ci-robot committed Sep 29, 2019
1 parent 92069c2 commit adaffc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/controller.v1alpha3/suggestion/suggestion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (r *ReconcileSuggestion) Reconcile(request reconcile.Request) (reconcile.Re
if err != nil {
r.recorder.Eventf(instance, corev1.EventTypeWarning,
consts.ReconcileErrorReason, err.Error())

// Try updating just the status condition when possible
// Status conditions might need to be updated even in error
// Ignore all other status fields else it will be inconsistent during retry
_ = r.updateStatusCondition(instance, oldS)
logger.Error(err, "Reconcile Suggestion error")
return reconcile.Result{}, err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller.v1alpha3/suggestion/suggestion_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ func (r *ReconcileSuggestion) updateStatus(s *suggestionsv1alpha3.Suggestion, ol
}
return nil
}

func (r *ReconcileSuggestion) updateStatusCondition(s *suggestionsv1alpha3.Suggestion, oldS *suggestionsv1alpha3.Suggestion) error {
if !equality.Semantic.DeepEqual(s.Status.Conditions, oldS.Status.Conditions) {
newConditions := s.Status.Conditions
s.Status = oldS.Status
s.Status.Conditions = newConditions
if err := r.Status().Update(context.TODO(), s); err != nil {
return err
}
}
return nil
}

0 comments on commit adaffc5

Please sign in to comment.