-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
c8d/list: Fix Total
size calculation
#48330
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,7 @@ func (i *ImageService) imageSummary(ctx context.Context, img images.Image, platf | |
} else { | ||
mfstSummary.Size.Content = contentSize | ||
totalSize += contentSize | ||
mfstSummary.Size.Total = totalSize | ||
mfstSummary.Size.Total += contentSize | ||
} | ||
|
||
isPseudo, err := img.IsPseudoImage(ctx) | ||
|
@@ -322,27 +322,34 @@ func (i *ImageService) imageSummary(ctx context.Context, img images.Image, platf | |
|
||
chainIDs := identity.ChainIDs(dockerImage.RootFS.DiffIDs) | ||
|
||
prevContentSize := contentSize | ||
unpackedSize, contentSize, err := i.singlePlatformSize(ctx, img) | ||
unpackedSize, imgContentSize, err := i.singlePlatformSize(ctx, img) | ||
if err != nil { | ||
logger.WithError(err).Warn("failed to determine platform specific size") | ||
return nil | ||
} | ||
|
||
// If the image-specific content size calculation produces different result | ||
// than the "generic" one, adjust the total size with the difference. | ||
if prevContentSize != contentSize { | ||
// Note: This shouldn't happen unless the implementation changes or the | ||
// content is added/removed during the list operation. | ||
if contentSize != imgContentSize { | ||
logger.WithFields(log.Fields{ | ||
"prevSize": prevContentSize, | ||
"contentSize": contentSize, | ||
}).Debug("content size calculation mismatch") | ||
"contentSize": contentSize, | ||
"imgContentSize": imgContentSize, | ||
}).Warn("content size calculation mismatch") | ||
|
||
totalSize += contentSize - prevContentSize | ||
mfstSummary.Size.Content = contentSize | ||
|
||
// contentSize was already added to total, adjust it by the difference | ||
// between the newly calculated size and the old size. | ||
d := imgContentSize - contentSize | ||
totalSize += d | ||
mfstSummary.Size.Total += d | ||
} | ||
|
||
totalSize += unpackedSize | ||
mfstSummary.Size.Total = totalSize | ||
mfstSummary.ImageData.Size.Unpacked = unpackedSize | ||
mfstSummary.Size.Total += unpackedSize | ||
totalSize += unpackedSize | ||
|
||
allChainsIDs = append(allChainsIDs, chainIDs...) | ||
|
||
|
@@ -467,7 +474,7 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con | |
return nil, err | ||
} | ||
var cfg configLabels | ||
if err := readConfig(ctx, contentStore, cfgDesc, &cfg); err != nil { | ||
if err := readJSON(ctx, contentStore, cfgDesc, &cfg); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -669,7 +676,7 @@ func setupLabelFilter(ctx context.Context, store content.Store, fltrs filters.Ar | |
return nil, nil | ||
} | ||
var cfg configLabels | ||
if err := readConfig(ctx, store, desc, &cfg); err != nil { | ||
if err := readJSON(ctx, store, desc, &cfg); err != nil { | ||
if errdefs.IsNotFound(err) { | ||
return nil, nil | ||
} | ||
|
@@ -744,8 +751,8 @@ func computeSharedSize(chainIDs []digest.Digest, layers map[digest.Digest]int, s | |
return sharedSize, nil | ||
} | ||
|
||
// readConfig reads content pointed by the descriptor and unmarshals it into a specified output. | ||
func readConfig(ctx context.Context, store content.Provider, desc ocispec.Descriptor, out interface{}) error { | ||
// readJSON reads content pointed by the descriptor and unmarshals it into a specified output. | ||
func readJSON(ctx context.Context, store content.Provider, desc ocispec.Descriptor, out interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it could be extracted to the There's already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, except our version also translates the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That problem should probably go away at some point; at least, Derek is working on unifying errdefs to make them interoperable. |
||
data, err := content.ReadBlob(ctx, store, desc) | ||
if err != nil { | ||
err = errors.Wrapf(err, "failed to read config content") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any risk of
contentSize
being larger thanimgContentSize
here (so getting negative values?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, and that's also fine here - if imgContentSize is larger then adding a negative will still adjust the total size correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the exact same thought, and then realized it was fine either way 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Yes, it just crossed my mind, so thought I'd double check. Thanks both!