@@ -22,7 +22,6 @@ import (
22
22
"crypto/x509"
23
23
"errors"
24
24
"fmt"
25
- "github.com/fluxcd/pkg/git"
26
25
"io"
27
26
"net/http"
28
27
"os"
@@ -390,7 +389,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
390
389
return sreconcile .ResultEmpty , e
391
390
}
392
391
393
- // Get the upstream revision from the artifact revision
392
+ // Get the upstream revision from the artifact digest
394
393
revision , err := r .getRevision (url , opts .craneOpts )
395
394
if err != nil {
396
395
e := serror .NewGeneric (
@@ -405,7 +404,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
405
404
406
405
// Mark observations about the revision on the object
407
406
defer func () {
408
- if obj .GetArtifact () == nil || git . TransformRevision ( obj . GetArtifact (). Revision ) != git . TransformRevision (revision ) {
407
+ if ! obj .GetArtifact (). HasRevision (revision ) {
409
408
message := fmt .Sprintf ("new revision '%s' for '%s'" , revision , url )
410
409
if obj .GetArtifact () != nil {
411
410
conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "NewRevision" , message )
@@ -425,7 +424,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
425
424
if obj .Spec .Verify == nil {
426
425
// Remove old observations if verification was disabled
427
426
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 ) ||
429
428
conditions .GetObservedGeneration (obj , sourcev1 .SourceVerifiedCondition ) != obj .Generation ||
430
429
conditions .IsFalse (obj , sourcev1 .SourceVerifiedCondition ) {
431
430
@@ -458,9 +457,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
458
457
459
458
// Skip pulling if the artifact revision and the source configuration has
460
459
// 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 ) {
464
461
conditions .Delete (obj , sourcev1 .FetchFailedCondition )
465
462
return sreconcile .ResultSuccess , nil
466
463
}
@@ -584,7 +581,8 @@ func (r *OCIRepositoryReconciler) selectLayer(obj *sourcev1.OCIRepository, image
584
581
return blob , nil
585
582
}
586
583
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>'.
588
586
func (r * OCIRepositoryReconciler ) getRevision (url string , options []crane.Option ) (string , error ) {
589
587
ref , err := name .ParseReference (url )
590
588
if err != nil {
@@ -618,14 +616,15 @@ func (r *OCIRepositoryReconciler) getRevision(url string, options []crane.Option
618
616
return revision , nil
619
617
}
620
618
621
- // digestFromRevision extract the revision from the revision string
619
+ // digestFromRevision extracts the digest from the revision string.
622
620
func (r * OCIRepositoryReconciler ) digestFromRevision (revision string ) string {
623
621
parts := strings .Split (revision , "@" )
624
622
return parts [len (parts )- 1 ]
625
623
}
626
624
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.
629
628
func (r * OCIRepositoryReconciler ) verifySignature (ctx context.Context , obj * sourcev1.OCIRepository , url string , opt ... remote.Option ) error {
630
629
ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
631
630
defer cancel ()
@@ -953,11 +952,9 @@ func (r *OCIRepositoryReconciler) reconcileStorage(ctx context.Context, sp *patc
953
952
// and the symlink in the Storage is updated to its path.
954
953
func (r * OCIRepositoryReconciler ) reconcileArtifact (ctx context.Context , sp * patch.SerialPatcher ,
955
954
obj * sourcev1.OCIRepository , metadata * sourcev1.Artifact , dir string ) (sreconcile.Result , error ) {
956
- revision := metadata .Revision
957
-
958
955
// 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 )))
961
958
962
959
// Set the ArtifactInStorageCondition if there's no drift.
963
960
defer func () {
@@ -969,9 +966,7 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, sp *pat
969
966
}()
970
967
971
968
// 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 ) {
975
970
r .eventLogf (ctx , obj , eventv1 .EventTypeTrace , sourcev1 .ArtifactUpToDateReason ,
976
971
"artifact up-to-date with remote revision: '%s'" , artifact .Revision )
977
972
return sreconcile .ResultSuccess , nil
0 commit comments