@@ -200,7 +200,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
200200 summarize .WithReconcileError (retErr ),
201201 summarize .WithIgnoreNotFound (),
202202 summarize .WithProcessors (
203- summarize .RecordContextualError ,
203+ summarize .ErrorActionHandler ,
204204 summarize .RecordReconcileReq ,
205205 ),
206206 summarize .WithResultBuilder (sreconcile.AlwaysRequeueResultBuilder {
@@ -268,21 +268,21 @@ func (r *BucketReconciler) reconcile(ctx context.Context, sp *patch.SerialPatche
268268 rreconcile .ProgressiveStatus (false , obj , meta .ProgressingReason ,
269269 "processing object: new generation %d -> %d" , obj .Status .ObservedGeneration , obj .Generation )
270270 if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
271- return sreconcile .ResultEmpty , err
271+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
272272 }
273273 case recAtVal != obj .Status .GetLastHandledReconcileRequest ():
274274 if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
275- return sreconcile .ResultEmpty , err
275+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
276276 }
277277 }
278278
279279 // Create temp working dir
280280 tmpDir , err := os .MkdirTemp ("" , fmt .Sprintf ("%s-%s-%s-" , obj .Kind , obj .Namespace , obj .Name ))
281281 if err != nil {
282- e := & serror.Event {
283- Err : fmt .Errorf ("failed to create temporary working directory: %w" , err ),
284- Reason : sourcev1 .DirCreationFailedReason ,
285- }
282+ e := serror .NewGeneric (
283+ fmt .Errorf ("failed to create temporary working directory: %w" , err ),
284+ sourcev1 .DirCreationFailedReason ,
285+ )
286286 conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
287287 return sreconcile .ResultEmpty , e
288288 }
@@ -402,7 +402,7 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
402402 rreconcile .ProgressiveStatus (true , obj , meta .ProgressingReason , msg )
403403 conditions .Delete (obj , sourcev1 .ArtifactInStorageCondition )
404404 if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
405- return sreconcile .ResultEmpty , err
405+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
406406 }
407407 return sreconcile .ResultSuccess , nil
408408 }
@@ -423,7 +423,7 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
423423func (r * BucketReconciler ) reconcileSource (ctx context.Context , sp * patch.SerialPatcher , obj * bucketv1.Bucket , index * index.Digester , dir string ) (sreconcile.Result , error ) {
424424 secret , err := r .getBucketSecret (ctx , obj )
425425 if err != nil {
426- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
426+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
427427 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
428428 // Return error as the world as observed may change
429429 return sreconcile .ResultEmpty , e
@@ -434,42 +434,42 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
434434 switch obj .Spec .Provider {
435435 case bucketv1 .GoogleBucketProvider :
436436 if err = gcp .ValidateSecret (secret ); err != nil {
437- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
437+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
438438 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
439439 return sreconcile .ResultEmpty , e
440440 }
441441 if provider , err = gcp .NewClient (ctx , secret ); err != nil {
442- e := & serror.Event { Err : err , Reason : "ClientError" }
442+ e := serror .NewGeneric ( err , "ClientError" )
443443 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
444444 return sreconcile .ResultEmpty , e
445445 }
446446 case bucketv1 .AzureBucketProvider :
447447 if err = azure .ValidateSecret (secret ); err != nil {
448- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
448+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
449449 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
450450 return sreconcile .ResultEmpty , e
451451 }
452452 if provider , err = azure .NewClient (obj , secret ); err != nil {
453- e := & serror.Event { Err : err , Reason : "ClientError" }
453+ e := serror .NewGeneric ( err , "ClientError" )
454454 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
455455 return sreconcile .ResultEmpty , e
456456 }
457457 default :
458458 if err = minio .ValidateSecret (secret ); err != nil {
459- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
459+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
460460 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
461461 return sreconcile .ResultEmpty , e
462462 }
463463 if provider , err = minio .NewClient (obj , secret ); err != nil {
464- e := & serror.Event { Err : err , Reason : "ClientError" }
464+ e := serror .NewGeneric ( err , "ClientError" )
465465 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
466466 return sreconcile .ResultEmpty , e
467467 }
468468 }
469469
470470 // Fetch etag index
471471 if err = fetchEtagIndex (ctx , provider , obj , index , dir ); err != nil {
472- e := & serror.Event { Err : err , Reason : bucketv1 .BucketOperationFailedReason }
472+ e := serror .NewGeneric ( err , bucketv1 .BucketOperationFailedReason )
473473 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
474474 return sreconcile .ResultEmpty , e
475475 }
@@ -501,7 +501,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
501501 }()
502502
503503 if err = fetchIndexFiles (ctx , provider , obj , index , dir ); err != nil {
504- e := & serror.Event { Err : err , Reason : bucketv1 .BucketOperationFailedReason }
504+ e := serror .NewGeneric ( err , bucketv1 .BucketOperationFailedReason )
505505 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
506506 return sreconcile .ResultEmpty , e
507507 }
@@ -550,45 +550,45 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
550550
551551 // Ensure target path exists and is a directory
552552 if f , err := os .Stat (dir ); err != nil {
553- e := & serror.Event {
554- Err : fmt .Errorf ("failed to stat source path: %w" , err ),
555- Reason : sourcev1 .StatOperationFailedReason ,
556- }
553+ e := serror .NewGeneric (
554+ fmt .Errorf ("failed to stat source path: %w" , err ),
555+ sourcev1 .StatOperationFailedReason ,
556+ )
557557 conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
558558 return sreconcile .ResultEmpty , e
559559 } else if ! f .IsDir () {
560- e := & serror.Event {
561- Err : fmt .Errorf ("source path '%s' is not a directory" , dir ),
562- Reason : sourcev1 .InvalidPathReason ,
563- }
560+ e := serror .NewGeneric (
561+ fmt .Errorf ("source path '%s' is not a directory" , dir ),
562+ sourcev1 .InvalidPathReason ,
563+ )
564564 conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
565565 return sreconcile .ResultEmpty , e
566566 }
567567
568568 // Ensure artifact directory exists and acquire lock
569569 if err := r .Storage .MkdirAll (artifact ); err != nil {
570- e := & serror.Event {
571- Err : fmt .Errorf ("failed to create artifact directory: %w" , err ),
572- Reason : sourcev1 .DirCreationFailedReason ,
573- }
570+ e := serror .NewGeneric (
571+ fmt .Errorf ("failed to create artifact directory: %w" , err ),
572+ sourcev1 .DirCreationFailedReason ,
573+ )
574574 conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
575575 return sreconcile .ResultEmpty , e
576576 }
577577 unlock , err := r .Storage .Lock (artifact )
578578 if err != nil {
579- return sreconcile .ResultEmpty , & serror.Event {
580- Err : fmt .Errorf ("failed to acquire lock for artifact: %w" , err ),
581- Reason : meta .FailedReason ,
582- }
579+ return sreconcile .ResultEmpty , serror .NewGeneric (
580+ fmt .Errorf ("failed to acquire lock for artifact: %w" , err ),
581+ meta .FailedReason ,
582+ )
583583 }
584584 defer unlock ()
585585
586586 // Archive directory to storage
587587 if err := r .Storage .Archive (& artifact , dir , nil ); err != nil {
588- e := & serror.Event {
589- Err : fmt .Errorf ("unable to archive artifact to storage: %s" , err ),
590- Reason : sourcev1 .ArchiveOperationFailedReason ,
591- }
588+ e := serror .NewGeneric (
589+ fmt .Errorf ("unable to archive artifact to storage: %s" , err ),
590+ sourcev1 .ArchiveOperationFailedReason ,
591+ )
592592 conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
593593 return sreconcile .ResultEmpty , e
594594 }
@@ -635,10 +635,10 @@ func (r *BucketReconciler) reconcileDelete(ctx context.Context, obj *bucketv1.Bu
635635func (r * BucketReconciler ) garbageCollect (ctx context.Context , obj * bucketv1.Bucket ) error {
636636 if ! obj .DeletionTimestamp .IsZero () {
637637 if deleted , err := r .Storage .RemoveAll (r .Storage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), "" , "*" )); err != nil {
638- return & serror.Event {
639- Err : fmt .Errorf ("garbage collection for deleted resource failed: %s" , err ),
640- Reason : "GarbageCollectionFailed" ,
641- }
638+ return serror .NewGeneric (
639+ fmt .Errorf ("garbage collection for deleted resource failed: %s" , err ),
640+ "GarbageCollectionFailed" ,
641+ )
642642 } else if deleted != "" {
643643 r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
644644 "garbage collected artifacts for deleted resource" )
@@ -649,10 +649,10 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *bucketv1.Buc
649649 if obj .GetArtifact () != nil {
650650 delFiles , err := r .Storage .GarbageCollect (ctx , * obj .GetArtifact (), time .Second * 5 )
651651 if err != nil {
652- return & serror.Event {
653- Err : fmt .Errorf ("garbage collection of artifacts failed: %w" , err ),
654- Reason : "GarbageCollectionFailed" ,
655- }
652+ return serror .NewGeneric (
653+ fmt .Errorf ("garbage collection of artifacts failed: %w" , err ),
654+ "GarbageCollectionFailed" ,
655+ )
656656 }
657657 if len (delFiles ) > 0 {
658658 r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
0 commit comments