Skip to content

Commit 208961a

Browse files
authored
Merge pull request #2127 from ruslan-shaydullin/feat/oci-origin-revision-events
Expose OCI origin revision in events
2 parents 99d894d + dd0a04c commit 208961a

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

docs/spec/v1/ocirepositories.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,13 @@ LAST SEEN TYPE REASON OBJECT
953953
94s Warning OCIOperationFailed ocirepository/<repository-name> failed to pull artifact from 'oci://ghcr.io/stefanprodan/manifests/podinfo': couldn't find tag "0.0.1"
954954
```
955955

956+
When `.status.artifact.metadata` contains a non-empty
957+
`org.opencontainers.image.revision` annotation, the controller forwards its
958+
value in `NewArtifact` and recovery `Succeeded` Events using the
959+
`source.toolkit.fluxcd.io/originRevision` annotation. The
960+
notification-controller exposes this value as `originRevision` in the Event
961+
metadata sent to notification consumers.
962+
956963
Besides being reported in Events, the reconciliation errors are also logged by
957964
the controller. The Flux CLI offer commands for filtering the logs for a
958965
specific OCIRepository, e.g.

internal/controller/ocirepository_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,9 @@ func (r *OCIRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *so
13361336
if val, ok := info[oci.RevisionAnnotation]; ok {
13371337
revision = val
13381338
}
1339+
if revision != "" {
1340+
annotations[fmt.Sprintf("%s/%s", sourcev1.GroupVersion.Group, eventv1.MetaOriginRevisionKey)] = revision
1341+
}
13391342
if source != "" && revision != "" {
13401343
message = fmt.Sprintf("%s, origin source '%s', origin revision '%s'", message, source, revision)
13411344
}

internal/controller/ocirepository_controller_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
6161

6262
kstatus "github.com/fluxcd/cli-utils/pkg/kstatus/status"
63+
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
6364
"github.com/fluxcd/pkg/apis/meta"
6465
intdigest "github.com/fluxcd/pkg/artifact/digest"
6566
"github.com/fluxcd/pkg/artifact/storage"
@@ -3413,13 +3414,14 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
34133414
noopErr.Ignore = true
34143415

34153416
tests := []struct {
3416-
name string
3417-
res sreconcile.Result
3418-
resErr error
3419-
oldObjBeforeFunc func(obj *sourcev1.OCIRepository)
3420-
newObjBeforeFunc func(obj *sourcev1.OCIRepository)
3421-
commit git.Commit
3422-
wantEvent string
3417+
name string
3418+
res sreconcile.Result
3419+
resErr error
3420+
oldObjBeforeFunc func(obj *sourcev1.OCIRepository)
3421+
newObjBeforeFunc func(obj *sourcev1.OCIRepository)
3422+
commit git.Commit
3423+
wantEvent string
3424+
wantOriginRevision string
34233425
}{
34243426
{
34253427
name: "error - no event",
@@ -3441,7 +3443,8 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
34413443
},
34423444
}
34433445
},
3444-
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'",
3446+
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'",
3447+
wantOriginRevision: "6.1.8/b3b00fe35424a45d373bf4c7214178bc36fd7872",
34453448
},
34463449
{
34473450
name: "recovery from failure",
@@ -3454,10 +3457,17 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
34543457
},
34553458
newObjBeforeFunc: func(obj *sourcev1.OCIRepository) {
34563459
obj.Spec.URL = "oci://newurl.io"
3457-
obj.Status.Artifact = &meta.Artifact{Revision: "xxx", Digest: "yyy"}
3460+
obj.Status.Artifact = &meta.Artifact{
3461+
Revision: "xxx",
3462+
Digest: "yyy",
3463+
Metadata: map[string]string{
3464+
oci.RevisionAnnotation: "6.1.8/b3b00fe35424a45d373bf4c7214178bc36fd7872",
3465+
},
3466+
}
34583467
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "ready")
34593468
},
3460-
wantEvent: "Normal Succeeded stored artifact with revision 'xxx' from 'oci://newurl.io'",
3469+
wantEvent: "Normal Succeeded stored artifact with revision 'xxx' from 'oci://newurl.io'",
3470+
wantOriginRevision: "6.1.8/b3b00fe35424a45d373bf4c7214178bc36fd7872",
34613471
},
34623472
{
34633473
name: "recovery and new artifact",
@@ -3525,6 +3535,12 @@ func TestOCIRepositoryReconciler_notify(t *testing.T) {
35253535
g.Expect(ok).To(Equal(tt.wantEvent != ""), "unexpected event received")
35263536
if tt.wantEvent != "" {
35273537
g.Expect(x).To(ContainSubstring(tt.wantEvent))
3538+
originRevisionKey := fmt.Sprintf("%s/%s", sourcev1.GroupVersion.Group, eventv1.MetaOriginRevisionKey)
3539+
if tt.wantOriginRevision != "" {
3540+
g.Expect(x).To(ContainSubstring(fmt.Sprintf("%s:%s", originRevisionKey, tt.wantOriginRevision)))
3541+
} else {
3542+
g.Expect(x).NotTo(ContainSubstring(originRevisionKey))
3543+
}
35283544
}
35293545
default:
35303546
if tt.wantEvent != "" {

0 commit comments

Comments
 (0)