@@ -200,7 +200,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
200
200
summarize .WithReconcileError (retErr ),
201
201
summarize .WithIgnoreNotFound (),
202
202
summarize .WithProcessors (
203
- summarize .RecordContextualError ,
203
+ summarize .ErrorActionHandler ,
204
204
summarize .RecordReconcileReq ,
205
205
),
206
206
summarize .WithResultBuilder (sreconcile.AlwaysRequeueResultBuilder {
@@ -268,21 +268,21 @@ func (r *BucketReconciler) reconcile(ctx context.Context, sp *patch.SerialPatche
268
268
rreconcile .ProgressiveStatus (false , obj , meta .ProgressingReason ,
269
269
"processing object: new generation %d -> %d" , obj .Status .ObservedGeneration , obj .Generation )
270
270
if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
271
- return sreconcile .ResultEmpty , err
271
+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
272
272
}
273
273
case recAtVal != obj .Status .GetLastHandledReconcileRequest ():
274
274
if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
275
- return sreconcile .ResultEmpty , err
275
+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
276
276
}
277
277
}
278
278
279
279
// Create temp working dir
280
280
tmpDir , err := os .MkdirTemp ("" , fmt .Sprintf ("%s-%s-%s-" , obj .Kind , obj .Namespace , obj .Name ))
281
281
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
+ )
286
286
conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
287
287
return sreconcile .ResultEmpty , e
288
288
}
@@ -402,7 +402,7 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
402
402
rreconcile .ProgressiveStatus (true , obj , meta .ProgressingReason , msg )
403
403
conditions .Delete (obj , sourcev1 .ArtifactInStorageCondition )
404
404
if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
405
- return sreconcile .ResultEmpty , err
405
+ return sreconcile .ResultEmpty , serror . NewGeneric ( err , sourcev1 . PatchOperationFailedReason )
406
406
}
407
407
return sreconcile .ResultSuccess , nil
408
408
}
@@ -423,7 +423,7 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
423
423
func (r * BucketReconciler ) reconcileSource (ctx context.Context , sp * patch.SerialPatcher , obj * bucketv1.Bucket , index * index.Digester , dir string ) (sreconcile.Result , error ) {
424
424
secret , err := r .getBucketSecret (ctx , obj )
425
425
if err != nil {
426
- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
426
+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
427
427
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
428
428
// Return error as the world as observed may change
429
429
return sreconcile .ResultEmpty , e
@@ -434,42 +434,42 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
434
434
switch obj .Spec .Provider {
435
435
case bucketv1 .GoogleBucketProvider :
436
436
if err = gcp .ValidateSecret (secret ); err != nil {
437
- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
437
+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
438
438
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
439
439
return sreconcile .ResultEmpty , e
440
440
}
441
441
if provider , err = gcp .NewClient (ctx , secret ); err != nil {
442
- e := & serror.Event { Err : err , Reason : "ClientError" }
442
+ e := serror .NewGeneric ( err , "ClientError" )
443
443
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
444
444
return sreconcile .ResultEmpty , e
445
445
}
446
446
case bucketv1 .AzureBucketProvider :
447
447
if err = azure .ValidateSecret (secret ); err != nil {
448
- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
448
+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
449
449
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
450
450
return sreconcile .ResultEmpty , e
451
451
}
452
452
if provider , err = azure .NewClient (obj , secret ); err != nil {
453
- e := & serror.Event { Err : err , Reason : "ClientError" }
453
+ e := serror .NewGeneric ( err , "ClientError" )
454
454
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
455
455
return sreconcile .ResultEmpty , e
456
456
}
457
457
default :
458
458
if err = minio .ValidateSecret (secret ); err != nil {
459
- e := & serror.Event { Err : err , Reason : sourcev1 .AuthenticationFailedReason }
459
+ e := serror .NewGeneric ( err , sourcev1 .AuthenticationFailedReason )
460
460
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
461
461
return sreconcile .ResultEmpty , e
462
462
}
463
463
if provider , err = minio .NewClient (obj , secret ); err != nil {
464
- e := & serror.Event { Err : err , Reason : "ClientError" }
464
+ e := serror .NewGeneric ( err , "ClientError" )
465
465
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
466
466
return sreconcile .ResultEmpty , e
467
467
}
468
468
}
469
469
470
470
// Fetch etag index
471
471
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 )
473
473
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
474
474
return sreconcile .ResultEmpty , e
475
475
}
@@ -501,7 +501,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
501
501
}()
502
502
503
503
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 )
505
505
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
506
506
return sreconcile .ResultEmpty , e
507
507
}
@@ -550,45 +550,45 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
550
550
551
551
// Ensure target path exists and is a directory
552
552
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
+ )
557
557
conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
558
558
return sreconcile .ResultEmpty , e
559
559
} 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
+ )
564
564
conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
565
565
return sreconcile .ResultEmpty , e
566
566
}
567
567
568
568
// Ensure artifact directory exists and acquire lock
569
569
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
+ )
574
574
conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
575
575
return sreconcile .ResultEmpty , e
576
576
}
577
577
unlock , err := r .Storage .Lock (artifact )
578
578
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
+ )
583
583
}
584
584
defer unlock ()
585
585
586
586
// Archive directory to storage
587
587
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
+ )
592
592
conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
593
593
return sreconcile .ResultEmpty , e
594
594
}
@@ -635,10 +635,10 @@ func (r *BucketReconciler) reconcileDelete(ctx context.Context, obj *bucketv1.Bu
635
635
func (r * BucketReconciler ) garbageCollect (ctx context.Context , obj * bucketv1.Bucket ) error {
636
636
if ! obj .DeletionTimestamp .IsZero () {
637
637
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
+ )
642
642
} else if deleted != "" {
643
643
r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
644
644
"garbage collected artifacts for deleted resource" )
@@ -649,10 +649,10 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *bucketv1.Buc
649
649
if obj .GetArtifact () != nil {
650
650
delFiles , err := r .Storage .GarbageCollect (ctx , * obj .GetArtifact (), time .Second * 5 )
651
651
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
+ )
656
656
}
657
657
if len (delFiles ) > 0 {
658
658
r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
0 commit comments