Skip to content

Commit

Permalink
fix: remote.Referrers: Resolve panic in returned index by setting rem…
Browse files Browse the repository at this point in the history
…ote ref field
  • Loading branch information
bmoylan committed Sep 14, 2024
1 parent a07d1ca commit 9c445f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/v1/remote/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (f *fetcher) fetchReferrers(ctx context.Context, filter map[string]string,
}
idx := &remoteIndex{
fetcher: *f,
ref: d.Context().Digest(h.String()),
ctx: ctx,
manifest: b,
mediaType: types.OCIImageIndex,
Expand Down
16 changes: 16 additions & 0 deletions pkg/v1/remote/referrers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/google/go-containerregistry/pkg/registry"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/partial"
"github.com/google/go-containerregistry/pkg/v1/random"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/types"
Expand Down Expand Up @@ -186,6 +187,21 @@ func TestReferrers(t *testing.T) {
if d := cmp.Diff([]v1.Descriptor{leafDesc}, m3.Manifests); d != "" {
t.Fatalf("referrers diff after second push (-want,+got): %s", d)
}
// Verify we can get the underlying manifests.
indexManifests, err := partial.Manifests(index)
if err != nil {
t.Fatal(err)
}

for _, manifest := range indexManifests {
if wrm, ok := manifest.(partial.WithRawManifest); ok {
if _, err := wrm.RawManifest(); err != nil {
t.Fatal(err)
}
} else {
t.Fatalf("expected WithRawManifest, got %T", manifest)
}
}

// Try applying filters and verify number of manifests and and annotations
index, err = remote.Referrers(rootRefDigest,
Expand Down

0 comments on commit 9c445f5

Please sign in to comment.