@@ -22,7 +22,6 @@ import (
2222 "crypto/x509"
2323 "errors"
2424 "fmt"
25- "github.com/fluxcd/pkg/git"
2625 "io"
2726 "net/http"
2827 "os"
@@ -390,7 +389,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
390389 return sreconcile .ResultEmpty , e
391390 }
392391
393- // Get the upstream revision from the artifact revision
392+ // Get the upstream revision from the artifact digest
394393 revision , err := r .getRevision (url , opts .craneOpts )
395394 if err != nil {
396395 e := serror .NewGeneric (
@@ -405,7 +404,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
405404
406405 // Mark observations about the revision on the object
407406 defer func () {
408- if obj .GetArtifact () == nil || git . TransformRevision ( obj . GetArtifact (). Revision ) != git . TransformRevision (revision ) {
407+ if ! obj .GetArtifact (). HasRevision (revision ) {
409408 message := fmt .Sprintf ("new revision '%s' for '%s'" , revision , url )
410409 if obj .GetArtifact () != nil {
411410 conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "NewRevision" , message )
@@ -425,7 +424,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
425424 if obj .Spec .Verify == nil {
426425 // Remove old observations if verification was disabled
427426 conditions .Delete (obj , sourcev1 .SourceVerifiedCondition )
428- } else if ( obj .GetArtifact () == nil || git . TransformRevision ( obj . GetArtifact (). Revision ) != git . TransformRevision ( revision ) ) ||
427+ } else if ! obj .GetArtifact (). HasRevision ( revision ) ||
429428 conditions .GetObservedGeneration (obj , sourcev1 .SourceVerifiedCondition ) != obj .Generation ||
430429 conditions .IsFalse (obj , sourcev1 .SourceVerifiedCondition ) {
431430
@@ -458,9 +457,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
458457
459458 // Skip pulling if the artifact revision and the source configuration has
460459 // not changed.
461- if (obj .GetArtifact () != nil &&
462- git .TransformRevision (obj .GetArtifact ().Revision ) == git .TransformRevision (revision )) &&
463- ! ociContentConfigChanged (obj ) {
460+ if obj .GetArtifact ().HasRevision (revision ) && ! ociContentConfigChanged (obj ) {
464461 conditions .Delete (obj , sourcev1 .FetchFailedCondition )
465462 return sreconcile .ResultSuccess , nil
466463 }
@@ -584,7 +581,8 @@ func (r *OCIRepositoryReconciler) selectLayer(obj *sourcev1.OCIRepository, image
584581 return blob , nil
585582}
586583
587- // getRevision fetches the upstream revision and returns the revision in the format `<tag>/<revision>`
584+ // getRevision fetches the upstream digest, returning the revision in the
585+ // format '<tag>@<digest>'.
588586func (r * OCIRepositoryReconciler ) getRevision (url string , options []crane.Option ) (string , error ) {
589587 ref , err := name .ParseReference (url )
590588 if err != nil {
@@ -618,14 +616,15 @@ func (r *OCIRepositoryReconciler) getRevision(url string, options []crane.Option
618616 return revision , nil
619617}
620618
621- // digestFromRevision extract the revision from the revision string
619+ // digestFromRevision extracts the digest from the revision string.
622620func (r * OCIRepositoryReconciler ) digestFromRevision (revision string ) string {
623621 parts := strings .Split (revision , "@" )
624622 return parts [len (parts )- 1 ]
625623}
626624
627- // verifySignature verifies the authenticity of the given image reference url. First, it tries using a key
628- // if a secret with a valid public key is provided. If not, it falls back to a keyless approach for verification.
625+ // verifySignature verifies the authenticity of the given image reference URL.
626+ // First, it tries to use a key if a Secret with a valid public key is provided.
627+ // If not, it falls back to a keyless approach for verification.
629628func (r * OCIRepositoryReconciler ) verifySignature (ctx context.Context , obj * sourcev1.OCIRepository , url string , opt ... remote.Option ) error {
630629 ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
631630 defer cancel ()
@@ -953,11 +952,9 @@ func (r *OCIRepositoryReconciler) reconcileStorage(ctx context.Context, sp *patc
953952// and the symlink in the Storage is updated to its path.
954953func (r * OCIRepositoryReconciler ) reconcileArtifact (ctx context.Context , sp * patch.SerialPatcher ,
955954 obj * sourcev1.OCIRepository , metadata * sourcev1.Artifact , dir string ) (sreconcile.Result , error ) {
956- revision := metadata .Revision
957-
958955 // Create artifact
959- artifact := r .Storage .NewArtifactFor (obj .Kind , obj , revision ,
960- fmt .Sprintf ("%s.tar.gz" , r .digestFromRevision (revision )))
956+ artifact := r .Storage .NewArtifactFor (obj .Kind , obj , metadata . Revision ,
957+ fmt .Sprintf ("%s.tar.gz" , r .digestFromRevision (metadata . Revision )))
961958
962959 // Set the ArtifactInStorageCondition if there's no drift.
963960 defer func () {
@@ -969,9 +966,7 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, sp *pat
969966 }()
970967
971968 // The artifact is up-to-date
972- if (obj .GetArtifact () != nil &&
973- git .TransformRevision (obj .GetArtifact ().Revision ) == git .TransformRevision (revision )) &&
974- ! ociContentConfigChanged (obj ) {
969+ if obj .GetArtifact ().HasRevision (artifact .Revision ) && ! ociContentConfigChanged (obj ) {
975970 r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , sourcev1 .ArtifactUpToDateReason ,
976971 "artifact up-to-date with remote revision: '%s'" , artifact .Revision )
977972 return sreconcile .ResultSuccess , nil
0 commit comments