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

Add partial.Descriptor #654

Merged
merged 1 commit into from Jan 15, 2020

Conversation

jonjohnsonjr
Copy link
Collaborator

This consolidates a bit of logic for generating a v1.Descriptor, but
also works around some of the nastiness that the partial package
introduces.

Because partial wraps layers and images with an extra level of
implementation, it shadows any methods that the underlying object
implements, so we can't expose "shortcuts". E.g. for tarball, we may
want to expose the URLs from LayerSources to callers, but the partial
wrapping gets in the way.

This is going to be a useful pattern in general unless we get rid of the
partial package entirely. Accessor methods that can introspect the
(private) partial structs will be necessary if we want to support
"optional" methods like UncompressedSize or Descriptor.

This consolidates a bit of logic for generating a v1.Descriptor, but
also works around some of the nastiness that the partial package
introduces.

Because partial wraps layers and images with an extra level of
implementation, it shadows any methods that the underlying object
implements, so we can't expose "shortcuts". E.g. for tarball, we may
want to expose the URLs from LayerSources to callers, but the partial
wrapping gets in the way.

This is going to be a useful pattern in general unless we get rid of the
partial package entirely. Accessor methods that can introspect the
(private) partial structs will be necessary if we want to support
"optional" methods like UncompressedSize or Descriptor.
@jonjohnsonjr
Copy link
Collaborator Author

cc @smukherj1

@jonjohnsonjr
Copy link
Collaborator Author

We can use this pattern to add a partial.UncompressedSize, which rules_docker could use to solve bazelbuild/rules_docker#1349

Given the unfortunate nature of the tar format, we need to know the size of a layer before we can start writing it, which involves scanning the entire thing. v1.Layer provides a Size (for Compressed bytes) but no UncompressedSize (for Uncompressed bytes). Since we probably don't want to force all layer implementations to add an UncompressedSize (impossible for remote, AFAIK), this has to be "optional".

There is some precedent for doing this in the standard library, e.g. bufio.Reader:

WriteTo implements io.WriterTo. This may make multiple calls to the Read method of the underlying Reader. If the underlying reader supports the WriteTo method, this calls the underlying WriteTo without buffering.

@codecov-io
Copy link

codecov-io commented Jan 13, 2020

Codecov Report

Merging #654 into master will increase coverage by 0.31%.
The diff coverage is 61.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
+ Coverage    77.8%   78.11%   +0.31%     
==========================================
  Files         102      102              
  Lines        4500     4497       -3     
==========================================
+ Hits         3501     3513      +12     
+ Misses        583      567      -16     
- Partials      416      417       +1
Impacted Files Coverage Δ
pkg/v1/partial/compressed.go 80.39% <100%> (ø) ⬆️
pkg/v1/partial/uncompressed.go 79.06% <100%> (+7.64%) ⬆️
pkg/v1/partial/with.go 62.14% <42.3%> (-4.53%) ⬇️
pkg/v1/mutate/image.go 71.2% <87.5%> (+2.45%) ⬆️
pkg/v1/tarball/image.go 80.79% <0%> (+6.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4fb41b...963e76d. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants