@@ -22,8 +22,11 @@ import (
22
22
"crypto/x509"
23
23
"errors"
24
24
"fmt"
25
+ "github.com/fluxcd/pkg/untar"
26
+ "io"
25
27
"net/http"
26
28
"os"
29
+ "path/filepath"
27
30
"sort"
28
31
"strings"
29
32
"time"
@@ -58,7 +61,6 @@ import (
58
61
"github.com/fluxcd/pkg/runtime/events"
59
62
"github.com/fluxcd/pkg/runtime/patch"
60
63
"github.com/fluxcd/pkg/runtime/predicates"
61
- "github.com/fluxcd/pkg/untar"
62
64
"github.com/fluxcd/pkg/version"
63
65
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
64
66
serror "github.com/fluxcd/source-controller/internal/error"
@@ -499,6 +501,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
499
501
layer = layers [0 ]
500
502
}
501
503
504
+ // Extract the compressed content from the selected layer
502
505
blob , err := layer .Compressed ()
503
506
if err != nil {
504
507
e := serror .NewGeneric (
@@ -509,9 +512,42 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
509
512
return sreconcile .ResultEmpty , e
510
513
}
511
514
512
- if _ , err = untar .Untar (blob , dir ); err != nil {
515
+ // Persist layer content to storage using the specified operation
516
+ switch obj .GetLayerOperation () {
517
+ case sourcev1 .OCILayerExtract :
518
+ if _ , err = untar .Untar (blob , dir ); err != nil {
519
+ e := serror .NewGeneric (
520
+ fmt .Errorf ("failed to untar the layer from artifact: %w" , err ),
521
+ sourcev1 .OCILayerOperationFailedReason ,
522
+ )
523
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
524
+ return sreconcile .ResultEmpty , e
525
+ }
526
+ case sourcev1 .OCILayerCopy :
527
+ metadata .Path = fmt .Sprintf ("%s.tgz" , metadata .Revision )
528
+ file , err := os .Create (filepath .Join (dir , metadata .Path ))
529
+ if err != nil {
530
+ e := serror .NewGeneric (
531
+ fmt .Errorf ("failed to create file: %w" , err ),
532
+ sourcev1 .OCILayerOperationFailedReason ,
533
+ )
534
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
535
+ return sreconcile .ResultEmpty , e
536
+ }
537
+ defer file .Close ()
538
+
539
+ _ , err = io .Copy (file , blob )
540
+ if err != nil {
541
+ e := serror .NewGeneric (
542
+ fmt .Errorf ("failed to copy layer from artifact: %w" , err ),
543
+ sourcev1 .OCILayerOperationFailedReason ,
544
+ )
545
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
546
+ return sreconcile .ResultEmpty , e
547
+ }
548
+ default :
513
549
e := serror .NewGeneric (
514
- fmt .Errorf ("failed to untar the first layer from artifact : %w " , err ),
550
+ fmt .Errorf ("unsupported layer operation : %s " , obj . GetLayerOperation () ),
515
551
sourcev1 .OCILayerOperationFailedReason ,
516
552
)
517
553
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
@@ -915,14 +951,25 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context,
915
951
}
916
952
defer unlock ()
917
953
918
- // Archive directory to storage
919
- if err := r .Storage .Archive (& artifact , dir , nil ); err != nil {
920
- e := serror .NewGeneric (
921
- fmt .Errorf ("unable to archive artifact to storage: %s" , err ),
922
- sourcev1 .ArchiveOperationFailedReason ,
923
- )
924
- conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
925
- return sreconcile .ResultEmpty , e
954
+ switch obj .GetLayerOperation () {
955
+ case sourcev1 .OCILayerCopy :
956
+ if err = r .Storage .CopyFromPath (& artifact , filepath .Join (dir , metadata .Path )); err != nil {
957
+ e := serror .NewGeneric (
958
+ fmt .Errorf ("unable to copy artifact to storage: %w" , err ),
959
+ sourcev1 .ArchiveOperationFailedReason ,
960
+ )
961
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
962
+ return sreconcile .ResultEmpty , e
963
+ }
964
+ default :
965
+ if err := r .Storage .Archive (& artifact , dir , nil ); err != nil {
966
+ e := serror .NewGeneric (
967
+ fmt .Errorf ("unable to archive artifact to storage: %s" , err ),
968
+ sourcev1 .ArchiveOperationFailedReason ,
969
+ )
970
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
971
+ return sreconcile .ResultEmpty , e
972
+ }
926
973
}
927
974
928
975
// Record it on the object
0 commit comments