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

Fix fetching referrers error handling #1648

Merged
Merged
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
11 changes: 6 additions & 5 deletions pkg/v1/remote/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,14 @@ func (f *fetcher) fetchReferrers(ctx context.Context, filter map[string]string,
// The registry doesn't support the Referrers API endpoint, so we'll use the fallback tag scheme.
b, _, err := f.fetchManifest(ctx, fallbackTag(d), []types.MediaType{types.OCIImageIndex})
if err != nil {
var terr *transport.Error
if ok := errors.As(err, &terr); ok && terr.StatusCode == http.StatusNotFound {
// Not found just means there are no attachments yet. Start with an empty manifest.
return &v1.IndexManifest{MediaType: types.OCIImageIndex}, nil
}

return nil, err
}
var terr *transport.Error
if ok := errors.As(err, &terr); ok && terr.StatusCode == http.StatusNotFound {
// Not found just means there are no attachments yet. Start with an empty manifest.
return &v1.IndexManifest{MediaType: types.OCIImageIndex}, nil
}

var im v1.IndexManifest
if err := json.Unmarshal(b, &im); err != nil {
Expand Down
13 changes: 11 additions & 2 deletions pkg/v1/remote/referrers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func TestReferrers(t *testing.T) {
rootDesc := descriptor(rootImg)
t.Logf("root image is %s", rootDesc.Digest)

// Before pushing referrers, try to get the referrers of the root image.
rootRefDigest := rootRef.Context().Digest(rootDesc.Digest.String())
index, err := remote.Referrers(rootRefDigest)
if err != nil {
t.Fatal(err)
}
if numManifests := len(index.Manifests); numManifests != 0 {
t.Fatalf("expected index to contain 0 manifests, but had %d", numManifests)
}

// Push an image that refers to the root image as its subject.
leafRef, err := name.ParseReference(fmt.Sprintf("%s/repo:leaf", u.Host))
if err != nil {
Expand All @@ -112,8 +122,7 @@ func TestReferrers(t *testing.T) {
t.Logf("leaf image is %s", leafDesc.Digest)

// Get the referrers of the root image, by digest.
rootRefDigest := rootRef.Context().Digest(rootDesc.Digest.String())
index, err := remote.Referrers(rootRefDigest)
index, err = remote.Referrers(rootRefDigest)
if err != nil {
t.Fatal(err)
}
Expand Down