@@ -454,35 +454,10 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
454454 return sreconcile .ResultSuccess , nil
455455 }
456456
457- // Pull artifact from the remote container registry
458- img , err := remote .Image (ref , opts ... )
459- if err != nil {
460- e := serror .NewGeneric (
461- fmt .Errorf ("failed to pull artifact from '%s': %w" , obj .Spec .URL , err ),
462- ociv1 .OCIPullFailedReason ,
463- )
464- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
465- return sreconcile .ResultEmpty , e
466- }
467-
468- // Copy the OCI annotations to the internal artifact metadata
469- manifest , err := img .Manifest ()
470- if err != nil {
471- e := serror .NewGeneric (
472- fmt .Errorf ("failed to parse artifact manifest: %w" , err ),
473- ociv1 .OCILayerOperationFailedReason ,
474- )
475- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
476- return sreconcile .ResultEmpty , e
477- }
478- metadata .Metadata = manifest .Annotations
479-
480- // Extract the compressed content from the selected layer
481- blob , err := r .selectLayer (obj , img )
482- if err != nil {
483- e := serror .NewGeneric (err , ociv1 .OCILayerOperationFailedReason )
484- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
485- return sreconcile .ResultEmpty , e
457+ blob , serr := r .fetchArtifact (obj , metadata , ref , opts )
458+ if serr != nil {
459+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , serr .Reason , serr .Err .Error ())
460+ return sreconcile .ResultEmpty , serr
486461 }
487462
488463 // Persist layer content to storage using the specified operation
@@ -583,6 +558,37 @@ func (r *OCIRepositoryReconciler) selectLayer(obj *ociv1.OCIRepository, image gc
583558 return blob , nil
584559}
585560
561+ func (r * OCIRepositoryReconciler ) fetchArtifact (obj * ociv1.OCIRepository , metadata * sourcev1.Artifact , ref name.Reference , options remoteOptions ) (io.ReadCloser , * serror.Generic ) {
562+ // Pull artifact from the remote container registry
563+ img , err := remote .Image (ref , options ... )
564+ if err != nil {
565+ e := serror .NewGeneric (
566+ fmt .Errorf ("failed to pull artifact from '%s': %w" , obj .Spec .URL , err ),
567+ ociv1 .OCIPullFailedReason ,
568+ )
569+ return nil , e
570+ }
571+
572+ // Copy the OCI annotations to the internal artifact metadata
573+ manifest , err := img .Manifest ()
574+ if err != nil {
575+ e := serror .NewGeneric (
576+ fmt .Errorf ("failed to parse artifact manifest: %w" , err ),
577+ ociv1 .OCILayerOperationFailedReason ,
578+ )
579+ return nil , e
580+ }
581+ metadata .Metadata = manifest .Annotations
582+
583+ // Extract the compressed content from the selected layer
584+ blob , err := r .selectLayer (obj , img )
585+ if err != nil {
586+ e := serror .NewGeneric (err , ociv1 .OCILayerOperationFailedReason )
587+ return nil , e
588+ }
589+ return blob , nil
590+ }
591+
586592// getRevision fetches the upstream digest, returning the revision in the
587593// format '<tag>@<digest>'.
588594func (r * OCIRepositoryReconciler ) getRevision (ref name.Reference , options []remote.Option ) (string , error ) {
0 commit comments