Skip to content

Commit

Permalink
Set annotations on descriptors created by referrers API
Browse files Browse the repository at this point in the history
Implement the behavior described by the OCI 1.1 specification at
https://github.com/opencontainers/distribution-spec/blob/main/spec.md#listing-referrers
for annotations for descriptors in the ImageIndex returned by the referrers API.

Addresses google#1997
  • Loading branch information
nmiyake committed Aug 13, 2024
1 parent b8e87ed commit b091e40
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,15 @@ func (m *manifests) handleReferrers(resp http.ResponseWriter, req *http.Request)
Config struct {
MediaType string `json:"mediaType"`
} `json:"config"`
Annotations map[string]string `json:"annotations,omitempty"`
}
json.Unmarshal(manifest.blob, &imageAsArtifact)
im.Manifests = append(im.Manifests, v1.Descriptor{
MediaType: types.MediaType(manifest.contentType),
Size: int64(len(manifest.blob)),
Digest: h,
ArtifactType: imageAsArtifact.Config.MediaType,
Annotations: imageAsArtifact.Annotations,
})
}
msg, _ := json.Marshal(&im)
Expand Down
8 changes: 7 additions & 1 deletion pkg/v1/remote/referrers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ func TestReferrers(t *testing.T) {
if err != nil {
t.Fatal(err)
}
mf, err := img.Manifest()
if err != nil {
t.Fatal(err)
}
return v1.Descriptor{
Digest: d,
Size: sz,
MediaType: mt,
ArtifactType: "application/testing123",
Annotations: mf.Annotations,
}
}

Expand Down Expand Up @@ -118,6 +123,7 @@ func TestReferrers(t *testing.T) {
t.Fatal(err)
}
leafImg = mutate.ConfigMediaType(leafImg, types.MediaType("application/testing123"))
leafImg = mutate.Annotations(leafImg, map[string]string{"annotation-key": "annotation-value"}).(v1.Image)
leafImg = mutate.Subject(leafImg, rootDesc).(v1.Image)
if err := remote.Write(leafRef, leafImg); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -187,7 +193,7 @@ func TestReferrers(t *testing.T) {
t.Fatalf("referrers diff after second push (-want,+got): %s", d)
}

// Try applying filters and verify number of manifests and and annotations
// Try applying filters and verify number of manifests and annotations
index, err = remote.Referrers(rootRefDigest,
remote.WithFilter("artifactType", "application/testing123"))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ func (w *writer) commitManifest(ctx context.Context, t Taggable, ref name.Refere
Config struct {
MediaType types.MediaType `json:"mediaType"`
} `json:"config"`
Annotations map[string]string `json:"annotations,omitempty"`
}
if err := json.Unmarshal(raw, &mf); err != nil {
return err
Expand Down Expand Up @@ -603,6 +604,7 @@ func (w *writer) commitManifest(ctx context.Context, t Taggable, ref name.Refere
MediaType: mf.MediaType,
Digest: h,
Size: size,
Annotations: mf.Annotations,
}
if err := w.commitSubjectReferrers(ctx,
ref.Context().Digest(mf.Subject.Digest.String()),
Expand Down

0 comments on commit b091e40

Please sign in to comment.