Skip to content

Set annotations on descriptors created by referrers API #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm in this test that we see those values in the descriptor?

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
Loading