From 1f26996d59d5c9847f2ac2ab8bda3ee3dab7de58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Thu, 5 Sep 2024 11:11:24 -0300 Subject: [PATCH] Expose an event when restart nginx for certificate reasons --- controllers/rpaasinstance_controller.go | 9 ++++++++- controllers/system_rate_limit.go | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/controllers/rpaasinstance_controller.go b/controllers/rpaasinstance_controller.go index 5f5c31f3..f591b28a 100644 --- a/controllers/rpaasinstance_controller.go +++ b/controllers/rpaasinstance_controller.go @@ -219,6 +219,9 @@ func (r *RpaasInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Reques } if certificatesHasChanges { + msg := "RPaaS controller has updated this resource due a certificate change" + logger.Info(msg) + r.EventRecorder.Event(instance, corev1.EventTypeWarning, "RpaasInstanceCertificatesChanged", msg) reservation.Cancel() } else if listOfChanges := getChangesList(changes); len(listOfChanges) > 0 { if systemRollout { @@ -231,7 +234,11 @@ func (r *RpaasInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Reques } if err = r.refreshStatus(ctx, instance, instanceHash, nginx); err != nil { - return ctrl.Result{}, err + reservation.Cancel() + return ctrl.Result{ + Requeue: true, + RequeueAfter: time.Second * 10, + }, err } return ctrl.Result{}, nil diff --git a/controllers/system_rate_limit.go b/controllers/system_rate_limit.go index 4c866561..64c251dc 100644 --- a/controllers/system_rate_limit.go +++ b/controllers/system_rate_limit.go @@ -38,7 +38,21 @@ func (r *systemRolloutRateLimiter) Reserve() (allowed bool, reservation SystemRo return false, nil } - return true, rateLimitReservation + return true, &onceReservation{Reservation: rateLimitReservation} +} + +type onceReservation struct { + *rate.Reservation + canceled bool +} + +func (r *onceReservation) Cancel() { + if r.canceled { + return + } + + r.Reservation.Cancel() + r.canceled = true } type noopReservation struct{}