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

update calculation for the expected bytes during image layer pulls #1489

Merged
merged 3 commits into from
Mar 27, 2023
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
17 changes: 14 additions & 3 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (i *ImgConfig) PullAll() error {
}

totalBytes := int64(0)
processedLayers := make(map[string]bool)
for src, img := range imageMap {
tag, err := name.NewTag(src, name.WeakValidation)
if err != nil {
Expand All @@ -82,11 +83,21 @@ func (i *ImgConfig) PullAll() error {
return fmt.Errorf("unable to get layers for image %s: %w", src, err)
}
for _, layer := range layers {
size, err := layer.Size()
layerDigest, err := layer.Digest()
if err != nil {
return fmt.Errorf("unable to get size of layer: %w", err)
return fmt.Errorf("unable to get digest for image layer: %w", err)
}
totalBytes += size

// Only calculate this layer size if we haven't already looked at it
if !processedLayers[layerDigest.Hex] {
size, err := layer.Size()
if err != nil {
return fmt.Errorf("unable to get size of layer: %w", err)
}
totalBytes += size
processedLayers[layerDigest.Hex] = true
}

}
}
spinner.Updatef("Preparing image sources and cache for image pulling")
Expand Down
7 changes: 6 additions & 1 deletion src/pkg/packager/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,13 @@ func getOCIPackageSize(src *utils.OrasRemote, ref registry.Reference) (int64, er
layers = manifest.Layers
}

processedLayers := make(map[string]bool)
for _, layer := range layers {
total += layer.Size
// Only include this layer's size if we haven't already processed it
if !processedLayers[layer.Digest.String()] {
total += layer.Size
processedLayers[layer.Digest.String()] = true
}
}

return total, nil
Expand Down