Skip to content

Commit 4dc3f36

Browse files
committed
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 when Reconciler exits due to panic. This change adds a call to recover function and try to handle panic and log error. Closes: OSPRH-16968
1 parent dfdb0b8 commit 4dc3f36

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

controllers/autoscaling_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)
147147
// Always patch the instance status when exiting this function so we can
148148
// persist any changes.
149149
defer func() {
150+
// Don't update the status, if reconciler Panics
151+
if r := recover(); r != nil {
152+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
153+
panic(r)
154+
}
150155
condition.RestoreLastTransitionTimes(
151156
&instance.Status.Conditions, savedConditions)
152157
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/ceilometer_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ func (r *CeilometerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
151151
// Always patch the instance status when exiting this function so we can
152152
// persist any changes.
153153
defer func() {
154+
// Don't update the status, if reconciler Panics
155+
if r := recover(); r != nil {
156+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
157+
panic(r)
158+
}
154159
condition.RestoreLastTransitionTimes(
155160
&instance.Status.Conditions, savedConditions)
156161
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/logging_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
115115
// Always patch the instance status when exiting this function so we can
116116
// persist any changes.
117117
defer func() {
118+
// Don't update the status, if reconciler Panics
119+
if r := recover(); r != nil {
120+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
121+
panic(r)
122+
}
118123
condition.RestoreLastTransitionTimes(
119124
&instance.Status.Conditions, savedConditions)
120125
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/metricstorage_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ func (r *MetricStorageReconciler) Reconcile(ctx context.Context, req ctrl.Reques
174174
// Always patch the instance status when exiting this function so we can
175175
// persist any changes.
176176
defer func() {
177+
// Don't update the status, if reconciler Panics
178+
if r := recover(); r != nil {
179+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
180+
panic(r)
181+
}
177182
condition.RestoreLastTransitionTimes(
178183
&instance.Status.Conditions, savedConditions)
179184
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

controllers/telemetry_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ func (r *TelemetryReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
113113
// Always patch the instance status when exiting this function so we can
114114
// persist any changes.
115115
defer func() {
116+
// Don't update the status, if reconciler Panics
117+
if r := recover(); r != nil {
118+
Log.Info(fmt.Sprintf("panic during reconcile %v\n", r))
119+
panic(r)
120+
}
116121
condition.RestoreLastTransitionTimes(
117122
&instance.Status.Conditions, savedConditions)
118123
if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) {

0 commit comments

Comments
 (0)