From e52d8378166da8c15800b05a3b3be14c303c16f9 Mon Sep 17 00:00:00 2001 From: Raihan Khan Date: Fri, 8 Nov 2024 19:56:46 +0600 Subject: [PATCH] Add MaintenanceWork trigger when cert deadline is reached (#32) Signed-off-by: raihankhan --- .../supervisor/recommendation_controller.go | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/controllers/supervisor/recommendation_controller.go b/pkg/controllers/supervisor/recommendation_controller.go index dfe30172..ec3c5cbd 100644 --- a/pkg/controllers/supervisor/recommendation_controller.go +++ b/pkg/controllers/supervisor/recommendation_controller.go @@ -140,21 +140,28 @@ func (r *RecommendationReconciler) Reconcile(ctx context.Context, req ctrl.Reque return r.handleErr(ctx, obj, err, api.Pending) } - if !isMaintenanceTime { - if obj.Status.Phase == api.Pending { - _, err := kmc.PatchStatus(ctx, r.Client, obj, func(obj client.Object) client.Object { - in := obj.(*api.Recommendation) - in.Status.Phase = api.Waiting - in.Status.Reason = api.WaitingForMaintenanceWindow - return in - }) - if err != nil { - return ctrl.Result{}, err - } + if !isMaintenanceTime && obj.Status.Phase == api.Pending { + _, err := kmc.PatchStatus(ctx, r.Client, obj, func(obj client.Object) client.Object { + in := obj.(*api.Recommendation) + in.Status.Phase = api.Waiting + in.Status.Reason = api.WaitingForMaintenanceWindow + return in + }) + if err != nil { + return ctrl.Result{}, err } + return ctrl.Result{RequeueAfter: r.RequeueAfterDuration}, nil } + // If WaitingForMaintenanceWindow, but certificate deadline is reached, + // trigger maintenanceWork anyway, requeue otherwise + if obj.Status.Phase == api.Waiting && obj.Status.Reason == api.WaitingForMaintenanceWindow { + if obj.Spec.Deadline != nil && obj.Spec.Deadline.UTC().After(r.Clock.Now()) { + return ctrl.Result{RequeueAfter: r.RequeueAfterDuration}, nil + } + } + return r.runMaintenanceWork(ctx, obj) } else if obj.Status.ApprovalStatus == api.ApprovalRejected { _, err := kmc.PatchStatus(ctx, r.Client, obj, func(obj client.Object) client.Object {