@@ -179,6 +179,7 @@ func (imageRepositoryPredicate) Update(e event.UpdateEvent) bool {
179179
180180func (r * ImagePolicyReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (result ctrl.Result , retErr error ) {
181181 start := time .Now ()
182+ log := ctrl .LoggerFrom (ctx )
182183
183184 // Fetch the ImagePolicy.
184185 obj := & imagev1.ImagePolicy {}
@@ -191,6 +192,13 @@ func (r *ImagePolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
191192
192193 // Always attempt to patch the object after each reconciliation.
193194 defer func () {
195+ // If the reconcile request annotation was set, consider it
196+ // handled (NB it doesn't matter here if it was changed since last
197+ // time)
198+ if token , ok := meta .ReconcileAnnotationValue (obj .GetAnnotations ()); ok {
199+ obj .Status .SetLastHandledReconcileRequest (token )
200+ }
201+
194202 // Create patch options for patching the object.
195203 patchOpts := pkgreconcile .AddPatchOptions (obj , r .patchOptions , imagePolicyOwnedConditions , r .ControllerName )
196204 if err := serialPatcher .Patch (ctx , obj , patchOpts ... ); err != nil {
@@ -219,6 +227,12 @@ func (r *ImagePolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
219227 return ctrl.Result {Requeue : true }, nil
220228 }
221229
230+ // Return if the object is suspended.
231+ if obj .Spec .Suspend {
232+ log .Info ("reconciliation is suspended for this object" )
233+ return ctrl.Result {}, nil
234+ }
235+
222236 // Call subreconciler.
223237 result , retErr = r .reconcile (ctx , serialPatcher , obj )
224238 return
@@ -245,9 +259,12 @@ func composeImagePolicyReadyMessage(obj *imagev1.ImagePolicy) string {
245259func (r * ImagePolicyReconciler ) reconcile (ctx context.Context , sp * patch.SerialPatcher , obj * imagev1.ImagePolicy ) (result ctrl.Result , retErr error ) {
246260 oldObj := obj .DeepCopy ()
247261
262+ // Set a default next reconcile time before processing the object.
263+ nextReconcileTime := obj .GetInterval ()
264+
248265 // If there's no error and no requeue is requested, it's a success.
249266 isSuccess := func (res ctrl.Result , err error ) bool {
250- if err != nil || res .Requeue {
267+ if err != nil || res .RequeueAfter != nextReconcileTime {
251268 return false
252269 }
253270 return true
@@ -365,7 +382,8 @@ func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialP
365382 // Let result finalizer compute the Ready condition.
366383 conditions .Delete (obj , meta .ReadyCondition )
367384
368- result , retErr = ctrl.Result {RequeueAfter : obj .GetInterval ()}, nil
385+ // Set the next reconcile time in the result based on the interval.
386+ result , retErr = ctrl.Result {RequeueAfter : nextReconcileTime }, nil
369387 return
370388}
371389
0 commit comments