Skip to content

Commit 97ee722

Browse files
ratailoropenshift-merge-bot[bot]
authored andcommitted
Do not update status when reconciler exits due to panic
Currently we use deferred call to always update the status field when Reconcile call exits, which seems correct for any other error except Reconciler exits due to panic. This change adds a call to recover function and try to handle panic and log error. Closes: OSPRH-17017
1 parent 61bb696 commit 97ee722

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

controllers/watcher_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
421421
// Always patch the instance status when exiting this function so we can
422422
// persist any changes.
423423
defer func() {
424+
// Don't update the status, if reconciler Panics
425+
if r := recover(); r != nil {
426+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
427+
panic(r)
428+
}
424429
condition.RestoreLastTransitionTimes(
425430
&instance.Status.Conditions, savedConditions)
426431
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/watcherapi_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func (r *WatcherAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request)
126126
// Always patch the instance status when exiting this function so we can
127127
// persist any changes.
128128
defer func() {
129+
// Don't update the status, if reconciler Panics
130+
if r := recover(); r != nil {
131+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
132+
panic(r)
133+
}
129134
condition.RestoreLastTransitionTimes(
130135
&instance.Status.Conditions, savedConditions)
131136
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/watcherapplier_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func (r *WatcherApplierReconciler) Reconcile(ctx context.Context, req ctrl.Reque
124124
// Always patch the instance status when exiting this function so we can
125125
// persist any changes.
126126
defer func() {
127+
// Don't update the status, if reconciler Panics
128+
if r := recover(); r != nil {
129+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
130+
panic(r)
131+
}
127132
condition.RestoreLastTransitionTimes(
128133
&instance.Status.Conditions, savedConditions)
129134
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/watcherdecisionengine_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func (r *WatcherDecisionEngineReconciler) Reconcile(ctx context.Context, req ctr
122122
// Always patch the instance status when exiting this function so we can
123123
// persist any changes.
124124
defer func() {
125+
// Don't update the status, if reconciler Panics
126+
if r := recover(); r != nil {
127+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
128+
panic(r)
129+
}
125130
condition.RestoreLastTransitionTimes(
126131
&instance.Status.Conditions, savedConditions)
127132
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

0 commit comments

Comments
 (0)