Skip to content

Commit 3f7d463

Browse files
committed
Use the OCI artifact revision in status and events
Signed-off-by: Stefan Prodan <[email protected]>
1 parent aae9d91 commit 3f7d463

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed

controllers/ocirepository_controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
385385
// Mark observations about the revision on the object
386386
defer func() {
387387
if !obj.GetArtifact().HasRevision(revision) {
388-
message := fmt.Sprintf("new digest '%s' for '%s'", revision, url)
388+
message := fmt.Sprintf("new revision '%s' for '%s'", revision, url)
389389
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", message)
390390
conditions.MarkReconciling(obj, "NewRevision", message)
391391
}
@@ -415,7 +415,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
415415
return sreconcile.ResultEmpty, e
416416
}
417417

418-
conditions.MarkTrue(obj, sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of digest %s", revision)
418+
conditions.MarkTrue(obj, sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of revision %s", revision)
419419
}
420420

421421
// Skip pulling if the artifact revision hasn't changes
@@ -448,7 +448,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
448448
metadata.Metadata = manifest.Annotations
449449

450450
// Extract the compressed content from the selected layer
451-
blob, err := r.getLayerCompressed(obj, img)
451+
blob, err := r.selectLayer(obj, img)
452452
if err != nil {
453453
e := serror.NewGeneric(err, sourcev1.OCILayerOperationFailedReason)
454454
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
@@ -501,8 +501,9 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
501501
return sreconcile.ResultSuccess, nil
502502
}
503503

504-
// getLayerCompressed finds the matching layer and returns its compress contents
505-
func (r *OCIRepositoryReconciler) getLayerCompressed(obj *sourcev1.OCIRepository, image gcrv1.Image) (io.ReadCloser, error) {
504+
// selectLayer finds the matching layer and returns its compressed contents.
505+
// If no layer selector was provided, we pick the first layer from the OCI artifact.
506+
func (r *OCIRepositoryReconciler) selectLayer(obj *sourcev1.OCIRepository, image gcrv1.Image) (io.ReadCloser, error) {
506507
layers, err := image.Layers()
507508
if err != nil {
508509
return nil, fmt.Errorf("failed to parse artifact layers: %w", err)
@@ -933,7 +934,7 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
933934
// The artifact is up-to-date
934935
if obj.GetArtifact().HasRevision(artifact.Revision) {
935936
r.eventLogf(ctx, obj, events.EventTypeTrace, sourcev1.ArtifactUpToDateReason,
936-
"artifact up-to-date with remote digest: '%s'", artifact.Revision)
937+
"artifact up-to-date with remote revision: '%s'", artifact.Revision)
937938
return sreconcile.ResultSuccess, nil
938939
}
939940

@@ -1094,7 +1095,7 @@ func (r *OCIRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *so
10941095
oldChecksum = oldObj.GetArtifact().Checksum
10951096
}
10961097

1097-
message := fmt.Sprintf("stored artifact with digest '%s' from '%s'", newObj.Status.Artifact.Revision, newObj.Spec.URL)
1098+
message := fmt.Sprintf("stored artifact with revision '%s' from '%s'", newObj.Status.Artifact.Revision, newObj.Spec.URL)
10981099

10991100
// enrich message with upstream annotations if found
11001101
if info := newObj.GetArtifact().Metadata; info != nil {

controllers/ocirepository_controller_test.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
390390
name: "HTTP without basic auth",
391391
want: sreconcile.ResultSuccess,
392392
assertConditions: []metav1.Condition{
393-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
394-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
393+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
394+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
395395
},
396396
},
397397
{
@@ -411,8 +411,8 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
411411
includeSecret: true,
412412
},
413413
assertConditions: []metav1.Condition{
414-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
415-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
414+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
415+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
416416
},
417417
},
418418
{
@@ -432,8 +432,8 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
432432
includeSA: true,
433433
},
434434
assertConditions: []metav1.Condition{
435-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
436-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
435+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
436+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
437437
},
438438
},
439439
{
@@ -515,8 +515,8 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
515515
},
516516
},
517517
assertConditions: []metav1.Condition{
518-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
519-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
518+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
519+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
520520
},
521521
},
522522
{
@@ -587,8 +587,8 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
587587
},
588588
provider: "azure",
589589
assertConditions: []metav1.Condition{
590-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
591-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
590+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
591+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
592592
},
593593
},
594594
}
@@ -873,8 +873,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
873873
want: sreconcile.ResultSuccess,
874874
wantRevision: fmt.Sprintf("latest/%s", img6.digest.Hex),
875875
assertConditions: []metav1.Condition{
876-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
877-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
876+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
877+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
878878
},
879879
},
880880
{
@@ -885,8 +885,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
885885
want: sreconcile.ResultSuccess,
886886
wantRevision: fmt.Sprintf("%s/%s", img6.tag, img6.digest.Hex),
887887
assertConditions: []metav1.Condition{
888-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
889-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
888+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
889+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
890890
},
891891
},
892892
{
@@ -897,8 +897,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
897897
want: sreconcile.ResultSuccess,
898898
wantRevision: fmt.Sprintf("%s/%s", img6.tag, img6.digest.Hex),
899899
assertConditions: []metav1.Condition{
900-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
901-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
900+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
901+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
902902
},
903903
},
904904
{
@@ -909,8 +909,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
909909
wantRevision: img6.digest.Hex,
910910
want: sreconcile.ResultSuccess,
911911
assertConditions: []metav1.Condition{
912-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
913-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
912+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
913+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
914914
},
915915
},
916916
{
@@ -955,8 +955,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
955955
want: sreconcile.ResultSuccess,
956956
wantRevision: fmt.Sprintf("%s/%s", img6.tag, img6.digest.Hex),
957957
assertConditions: []metav1.Condition{
958-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
959-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
958+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
959+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
960960
},
961961
},
962962
{
@@ -969,8 +969,8 @@ func TestOCIRepository_reconcileSource_remoteReference(t *testing.T) {
969969
want: sreconcile.ResultSuccess,
970970
wantRevision: img5.digest.Hex,
971971
assertConditions: []metav1.Condition{
972-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest"),
973-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
972+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision"),
973+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision"),
974974
},
975975
},
976976
}
@@ -1049,9 +1049,9 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
10491049
shouldSign: true,
10501050
want: sreconcile.ResultSuccess,
10511051
assertConditions: []metav1.Condition{
1052-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1053-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1054-
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of digest <digest>"),
1052+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
1053+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
1054+
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of revision <digest>"),
10551055
},
10561056
},
10571057
{
@@ -1064,8 +1064,8 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
10641064
wantErrMsg: "failed to verify the signature using provider 'cosign': no matching signatures were found for '<url>'",
10651065
want: sreconcile.ResultEmpty,
10661066
assertConditions: []metav1.Condition{
1067-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1068-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1067+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
1068+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
10691069
*conditions.FalseCondition(sourcev1.SourceVerifiedCondition, sourcev1.VerificationError, "failed to verify the signature using provider '<provider>': no matching signatures were found for '<url>'"),
10701070
},
10711071
},
@@ -1079,8 +1079,8 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
10791079
want: sreconcile.ResultEmpty,
10801080
keyless: true,
10811081
assertConditions: []metav1.Condition{
1082-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1083-
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest '<digest>' for '<url>'"),
1082+
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
1083+
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision '<digest>' for '<url>'"),
10841084
*conditions.FalseCondition(sourcev1.SourceVerifiedCondition, sourcev1.VerificationError, "failed to verify the signature using provider '<provider> keyless': no matching signatures"),
10851085
},
10861086
},
@@ -1109,7 +1109,7 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignature(t *testing.T) {
11091109
},
11101110
want: sreconcile.ResultSuccess,
11111111
assertConditions: []metav1.Condition{
1112-
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of digest <digest>"),
1112+
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of revision <digest>"),
11131113
},
11141114
},
11151115
{
@@ -1258,7 +1258,7 @@ func TestOCIRepository_reconcileArtifact(t *testing.T) {
12581258
Revision: "revision",
12591259
},
12601260
beforeFunc: func(obj *sourcev1.OCIRepository) {
1261-
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest")
1261+
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", "new revision")
12621262
},
12631263
want: sreconcile.ResultSuccess,
12641264
assertPaths: []string{
@@ -1698,7 +1698,7 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
16981698
},
16991699
}
17001700
},
1701-
wantEvent: "Normal NewArtifact stored artifact with digest 'xxx' from 'oci://newurl.io', origin source 'https://github.com/stefanprodan/podinfo', origin revision '6.1.8/b3b00fe35424a45d373bf4c7214178bc36fd7872'",
1701+
wantEvent: "Normal NewArtifact stored artifact with revision 'xxx' from 'oci://newurl.io', origin source 'https://github.com/stefanprodan/podinfo', origin revision '6.1.8/b3b00fe35424a45d373bf4c7214178bc36fd7872'",
17021702
},
17031703
{
17041704
name: "recovery from failure",
@@ -1714,7 +1714,7 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
17141714
obj.Status.Artifact = &sourcev1.Artifact{Revision: "xxx", Checksum: "yyy"}
17151715
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "ready")
17161716
},
1717-
wantEvent: "Normal Succeeded stored artifact with digest 'xxx' from 'oci://newurl.io'",
1717+
wantEvent: "Normal Succeeded stored artifact with revision 'xxx' from 'oci://newurl.io'",
17181718
},
17191719
{
17201720
name: "recovery and new artifact",
@@ -1730,7 +1730,7 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
17301730
obj.Status.Artifact = &sourcev1.Artifact{Revision: "aaa", Checksum: "bbb"}
17311731
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "ready")
17321732
},
1733-
wantEvent: "Normal NewArtifact stored artifact with digest 'aaa' from 'oci://newurl.io'",
1733+
wantEvent: "Normal NewArtifact stored artifact with revision 'aaa' from 'oci://newurl.io'",
17341734
},
17351735
{
17361736
name: "no updates",

0 commit comments

Comments
 (0)