@@ -169,21 +169,19 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
169169 return ctrl.Result {}, nil
170170 }
171171
172- // Initialize the patch helper
172+ // Initialize the patch helper with the current version of the object.
173173 patchHelper , err := patch .NewHelper (obj , r .Client )
174174 if err != nil {
175175 return ctrl.Result {}, err
176176 }
177177
178- // Result of the sub-reconciliation
178+ // recResult stores the abstracted reconcile result.
179179 var recResult sreconcile.Result
180180
181181 // Always attempt to patch the object after each reconciliation.
182- // NOTE: This deferred block only modifies the named return error. The
183- // result from the reconciliation remains the same. Any requeue attributes
184- // set in the result will continue to be effective.
182+ // NOTE: The final runtime result and error are set in this block.
185183 defer func () {
186- retErr = r .summarizeAndPatch (ctx , obj , patchHelper , recResult , retErr )
184+ result , retErr = r .summarizeAndPatch (ctx , obj , patchHelper , recResult , retErr )
187185
188186 // Always record readiness and duration metrics
189187 r .Metrics .RecordReadiness (ctx , obj )
@@ -195,13 +193,13 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
195193 if ! controllerutil .ContainsFinalizer (obj , sourcev1 .SourceFinalizer ) {
196194 controllerutil .AddFinalizer (obj , sourcev1 .SourceFinalizer )
197195 recResult = sreconcile .ResultRequeue
198- return ctrl. Result { Requeue : true }, nil
196+ return
199197 }
200198
201199 // Examine if the object is under deletion
202200 if ! obj .ObjectMeta .DeletionTimestamp .IsZero () {
203- res , err : = r .reconcileDelete (ctx , obj )
204- return sreconcile . BuildRuntimeResult ( ctx , r . EventRecorder , obj , res , err )
201+ recResult , retErr = r .reconcileDelete (ctx , obj )
202+ return
205203 }
206204
207205 // Reconcile actual object
@@ -210,23 +208,30 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
210208 r .reconcileSource ,
211209 r .reconcileArtifact ,
212210 }
213- recResult , err = r .reconcile (ctx , obj , reconcilers )
214- return sreconcile . BuildRuntimeResult ( ctx , r . EventRecorder , obj , recResult , err )
211+ recResult , retErr = r .reconcile (ctx , obj , reconcilers )
212+ return
215213}
216214
217215// summarizeAndPatch analyzes the object conditions to create a summary of the
218- // status conditions and patches the object with the calculated summary. The
219- // reconciler error type is also used to determine the conditions and the
220- // returned error.
221- func (r * HelmChartReconciler ) summarizeAndPatch (ctx context.Context , obj * sourcev1.HelmChart , patchHelper * patch.Helper , res sreconcile.Result , recErr error ) error {
216+ // status conditions, computes runtime results and patches the object in the K8s
217+ // API server.
218+ func (r * HelmChartReconciler ) summarizeAndPatch (
219+ ctx context.Context ,
220+ obj * sourcev1.HelmChart ,
221+ patchHelper * patch.Helper ,
222+ res sreconcile.Result ,
223+ recErr error ) (ctrl.Result , error ) {
224+ sreconcile .RecordContextualError (ctx , r .EventRecorder , obj , recErr )
225+
222226 // Record the value of the reconciliation request, if any
223227 if v , ok := meta .ReconcileAnnotationValue (obj .GetAnnotations ()); ok {
224228 obj .Status .SetLastHandledReconcileRequest (v )
225229 }
226230
227231 // Compute the reconcile results, obtain patch options and reconcile error.
228232 var patchOpts []patch.Option
229- patchOpts , recErr = sreconcile .ComputeReconcileResult (obj , res , recErr , helmChartOwnedConditions )
233+ var result ctrl.Result
234+ patchOpts , result , recErr = sreconcile .ComputeReconcileResult (obj , obj .GetRequeueAfter (), res , recErr , helmChartOwnedConditions )
230235
231236 // Summarize Ready condition
232237 conditions .SetSummary (obj ,
@@ -247,7 +252,7 @@ func (r *HelmChartReconciler) summarizeAndPatch(ctx context.Context, obj *source
247252 }
248253 recErr = kerrors .NewAggregate ([]error {recErr , err })
249254 }
250- return recErr
255+ return result , recErr
251256}
252257
253258// reconcile steps through the actual reconciliation tasks for the object, it returns early on the first step that
0 commit comments