Skip to content

Commit

Permalink
Add MaintenanceWork trigger when cert deadline is reached (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <[email protected]>
  • Loading branch information
raihankhan authored Nov 8, 2024
1 parent 439962b commit e52d837
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pkg/controllers/supervisor/recommendation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e52d837

Please sign in to comment.