Skip to content

Commit

Permalink
fix: emits ReconcileError events correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Oct 4, 2023
1 parent 70701ce commit aab6268
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions controllers/tortoise_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ type TortoiseReconciler struct {
//+kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete

func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
defer func() {
if reterr != nil {
r.EventRecorder.Event(&autoscalingv1beta1.Tortoise{}, "Warning", "ReconcileError", reterr.Error())
}
}()

logger := log.FromContext(ctx)
now := time.Now()

Expand All @@ -89,6 +83,11 @@ func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
logger.Error(err, "failed to get tortoise", "tortoise", req.NamespacedName)
return ctrl.Result{}, err
}
defer func() {
if reterr != nil {
r.EventRecorder.Event(tortoise, "Warning", "ReconcileError", reterr.Error())
}
}()

if !tortoise.ObjectMeta.DeletionTimestamp.IsZero() {
// Tortoise is deleted by user and waiting for finalizer.
Expand Down

0 comments on commit aab6268

Please sign in to comment.