Skip to content

Commit bb33ba1

Browse files
authored
Merge pull request #2066 from immanuwell/fix/oci-blob-leak-and-error-wrapping
fix: close OCI blob reader and wrap errors consistently across controllers
2 parents 524cf24 + 44548b7 commit bb33ba1

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

internal/controller/bucket_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
568568
// Archive directory to storage
569569
if err := r.Storage.Archive(&artifact, dir, nil); err != nil {
570570
e := serror.NewGeneric(
571-
fmt.Errorf("unable to archive artifact to storage: %s", err),
571+
fmt.Errorf("unable to archive artifact to storage: %w", err),
572572
sourcev1.ArchiveOperationFailedReason,
573573
)
574574
conditions.MarkTrue(obj, sourcev1.StorageOperationFailedCondition, e.Reason, "%s", e)
@@ -622,7 +622,7 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *sourcev1.Buc
622622
if !obj.DeletionTimestamp.IsZero() {
623623
if deleted, err := r.Storage.RemoveAll(r.Storage.NewArtifactFor(obj.Kind, obj.GetObjectMeta(), "", "*")); err != nil {
624624
return serror.NewGeneric(
625-
fmt.Errorf("garbage collection for deleted resource failed: %s", err),
625+
fmt.Errorf("garbage collection for deleted resource failed: %w", err),
626626
"GarbageCollectionFailed",
627627
)
628628
} else if deleted != "" {

internal/controller/gitrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
559559
// Check if the content config contributing to the artifact has changed.
560560
if !gitContentConfigChanged(obj, includes) {
561561
ge := serror.NewGeneric(
562-
fmt.Errorf("no changes since last reconcilation: observed revision '%s'",
562+
fmt.Errorf("no changes since last reconciliation: observed revision '%s'",
563563
commitReference(obj, commit)), sourcev1.GitOperationSucceedReason,
564564
)
565565
ge.Notification = false

internal/controller/ocirepository_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
537537
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
538538
return sreconcile.ResultEmpty, e
539539
}
540+
defer blob.Close()
540541

541542
// Persist layer content to storage using the specified operation
542543
switch obj.GetLayerOperation() {
@@ -1201,7 +1202,7 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, sp *pat
12011202

12021203
if err := r.Storage.Archive(&artifact, dir, storage.SourceIgnoreFilter(ps, ignoreDomain)); err != nil {
12031204
e := serror.NewGeneric(
1204-
fmt.Errorf("unable to archive artifact to storage: %s", err),
1205+
fmt.Errorf("unable to archive artifact to storage: %w", err),
12051206
sourcev1.ArchiveOperationFailedReason,
12061207
)
12071208
conditions.MarkTrue(obj, sourcev1.StorageOperationFailedCondition, e.Reason, "%s", e)

0 commit comments

Comments
 (0)