Skip to content
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
9 changes: 6 additions & 3 deletions internal/memorypullcache/memorypullcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ func (c *MemoryPullCache) Fetch(ctx context.Context, ref string) (io.ReadCloser,

img, err := remote.Image(parsedRef, remoteOptions...)
if err != nil {
return nil, fmt.Errorf("in remote.Image: %w", err)
slog.WarnContext(ctx, "Image pull failed", slog.String("ref", ref), slog.Any("error", err))
return nil, fmt.Errorf("while pulling image %q: %w", ref, err)
}

size, err := img.Size()
if err != nil {
return nil, fmt.Errorf("in img.Size(): %w", err)
slog.WarnContext(ctx, "Image size lookup failed", slog.String("ref", ref), slog.Any("error", err))
return nil, fmt.Errorf("while reading size of image %q: %w", ref, err)
}
if size > 100*1024*1024 {
slog.InfoContext(ctx,
Expand All @@ -156,7 +158,8 @@ func (c *MemoryPullCache) Fetch(ctx context.Context, ref string) (io.ReadCloser,

memData, err := io.ReadAll(tarData)
if err != nil {
return nil, fmt.Errorf("while reading image: %w", err)
slog.WarnContext(ctx, "Image read failed", slog.String("ref", ref), slog.Any("error", err))
return nil, fmt.Errorf("while reading image %q: %w", ref, err)
}

if digestWasIncluded {
Expand Down
21 changes: 21 additions & 0 deletions internal/memorypullcache/memorypullcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package memorypullcache

import (
"context"
"strings"
"testing"
)

Expand Down Expand Up @@ -82,3 +84,22 @@ func TestRewriteLocalRegistry(t *testing.T) {
})
}
}

// TestFetchErrorIncludesRef checks that pull failures wrap the error with the
// requested image ref, so operators can identify which image failed from the
// error chain alone (without having to correlate trace IDs across systems).
func TestFetchErrorIncludesRef(t *testing.T) {
// A registry that refuses connection so remote.Image returns an error.
const ref = "127.0.0.1:1/missing/image:nope"
c, err := NewMemoryPullCache(context.Background(), nil, "")
if err != nil {
t.Fatalf("NewMemoryPullCache: %v", err)
}
_, err = c.Fetch(context.Background(), ref)
if err == nil {
t.Fatal("Fetch on an unreachable registry returned nil error")
}
if !strings.Contains(err.Error(), ref) {
t.Errorf("Fetch error %q does not contain ref %q", err, ref)
}
}
Loading