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

Update status conditions during reconcile error #831

Merged
merged 1 commit into from
Sep 29, 2019
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
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
}