Skip to content
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

Set annotations on descriptors created by referrers API #2068

Open
wants to merge 4 commits 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
13 changes: 12 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 All @@ -139,6 +145,11 @@ func TestReferrers(t *testing.T) {
t.Fatalf("referrers diff (-want,+got): %s", d)
}

// Verify the annotations are present in the descriptor
if got := m2.Manifests[0].Annotations["annotation-key"]; got != "annotation-value" {
t.Errorf("expected annotation 'annotation-key' to be 'annotation-value', got %q", got)
}

if leg.tryFallback {
// Get the referrers by querying the root image's fallback tag directly.
tag, err := name.ParseReference(fmt.Sprintf("%s/repo:sha256-%s", u.Host, rootDesc.Digest.Hex))
Expand Down Expand Up @@ -187,7 +198,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