-
Notifications
You must be signed in to change notification settings - Fork 395
WIP RFC: internal/external interface separation/adapters #1439
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f115637
Improve documentation of PutBlobOptions and TryReusingBlobOptions
mtrmac f334dd0
Introduce internal/private/ImageDestinationInternalOnly
mtrmac 36d4ab3
Add internal/imagedestination.impl, and use it in storageImageDestina…
mtrmac 3903aab
Use internal/imagedestination/impl in dockerImageDestination
mtrmac 1498d01
Use BlobInfoCache2 instead of types.BlobInfoCache in internal/types
mtrmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package impl | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
|
|
||
| "github.com/containers/image/v5/internal/blobinfocache" | ||
| "github.com/containers/image/v5/internal/private" | ||
| "github.com/containers/image/v5/types" | ||
| ) | ||
|
|
||
| // Compat implements the obsolete parts of types.ImageDestination | ||
| // for implementations of private.ImageDestination. | ||
| // See AddCompat below. | ||
| type Compat struct { | ||
| dest private.ImageDestinationInternalOnly | ||
| } | ||
|
|
||
| // AddCompat initializes Compat to implement the obsolete parts of types.ImageDestination | ||
| // for implementations of private.ImageDestination. | ||
| // | ||
| // Use it like this: | ||
| // type yourDestination struct { | ||
| // impl.Compat | ||
| // … | ||
| // } | ||
| // dest := &yourDestination{…} | ||
| // dest.Compat = impl.AddCompat(dest) | ||
| // | ||
| func AddCompat(dest private.ImageDestinationInternalOnly) Compat { | ||
| return Compat{dest} | ||
| } | ||
|
|
||
| // PutBlob writes contents of stream and returns data representing the result. | ||
| // inputInfo.Digest can be optionally provided if known; if provided, and stream is read to the end without error, the digest MUST match the stream contents. | ||
| // inputInfo.Size is the expected length of stream, if known. | ||
| // inputInfo.MediaType describes the blob format, if known. | ||
| // May update cache. | ||
| // WARNING: The contents of stream are being verified on the fly. Until stream.Read() returns io.EOF, the contents of the data SHOULD NOT be available | ||
| // to any other readers for download using the supplied digest. | ||
| // If stream.Read() at any time, ESPECIALLY at end of input, returns an error, PutBlob MUST 1) fail, and 2) delete any data stored so far. | ||
| func (c *Compat) PutBlob(ctx context.Context, stream io.Reader, inputInfo types.BlobInfo, cache types.BlobInfoCache, isConfig bool) (types.BlobInfo, error) { | ||
| return c.dest.PutBlobWithOptions(ctx, stream, inputInfo, private.PutBlobOptions{ | ||
| Cache: blobinfocache.FromBlobInfoCache(cache), | ||
| IsConfig: isConfig, | ||
| }) | ||
| } | ||
|
|
||
| // TryReusingBlob checks whether the transport already contains, or can efficiently reuse, a blob, and if so, applies it to the current destination | ||
| // (e.g. if the blob is a filesystem layer, this signifies that the changes it describes need to be applied again when composing a filesystem tree). | ||
| // info.Digest must not be empty. | ||
| // If canSubstitute, TryReusingBlob can use an equivalent equivalent of the desired blob; in that case the returned info may not match the input. | ||
| // If the blob has been successfully reused, returns (true, info, nil); info must contain at least a digest and size, and may | ||
| // include CompressionOperation and CompressionAlgorithm fields to indicate that a change to the compression type should be | ||
| // reflected in the manifest that will be written. | ||
| // If the transport can not reuse the requested blob, TryReusingBlob returns (false, {}, nil); it returns a non-nil error only on an unexpected failure. | ||
| // May use and/or update cache. | ||
| func (c *Compat) TryReusingBlob(ctx context.Context, info types.BlobInfo, cache types.BlobInfoCache, canSubstitute bool) (bool, types.BlobInfo, error) { | ||
| return c.dest.TryReusingBlobWithOptions(ctx, info, private.TryReusingBlobOptions{ | ||
| Cache: blobinfocache.FromBlobInfoCache(cache), | ||
| CanSubstitute: canSubstitute, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
It makes no sense to have a separate
imagedestination/implpackage; a transport is a fully-connected graph of transport/reference/(source+destination), so importing any part of it is going to drag in all of that once we add new features to all most of these interfaces.So we need something like
internal/transport/compat, withcompat.Implement{Source,Reference,Destination}(…)(many ways to name this…).(OTOH the other adapter,
imagedestination.FromPublic, does conceptually make more sense to have split granularly, one subpackage per interface, because not every caller is going to use every interface — especially if we ever made this public, for callers likeskopeo inspectthat only need one of the read/write directions.)