Skip to content

Commit

Permalink
copy/single: wrap arguments in copySingleImageOptions
Browse files Browse the repository at this point in the history
Create a wrapper around arguments of `copySingleImage`

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Aug 4, 2023
1 parent d86b8db commit 63deaa7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ func Image(ctx context.Context, policyContext *signature.PolicyContext, destRef,

if !multiImage {
// The simple case: just copy a single image.
single, err := c.copySingleImage(ctx, c.unparsedToplevel, nil, false)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
single, err := c.copySingleImage(ctx, c.unparsedToplevel, nil, singleImageOpts)
if err != nil {
return nil, err
}
Expand All @@ -273,8 +274,8 @@ func Image(ctx context.Context, policyContext *signature.PolicyContext, destRef,
}
logrus.Debugf("Source is a manifest list; copying (only) instance %s for current system", instanceDigest)
unparsedInstance := image.UnparsedInstance(rawSource, &instanceDigest)

single, err := c.copySingleImage(ctx, unparsedInstance, nil, false)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
single, err := c.copySingleImage(ctx, unparsedInstance, nil, singleImageOpts)
if err != nil {
return nil, fmt.Errorf("copying system image from manifest list: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion copy/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func (c *copier) copyMultipleImages(ctx context.Context) (copiedManifest []byte,
logrus.Debugf("Copying instance %s (%d/%d)", instance.sourceDigest, i+1, len(instanceCopyList))
c.Printf("Copying image %s (%d/%d)\n", instance.sourceDigest, i+1, len(instanceCopyList))
unparsedInstance := image.UnparsedInstance(c.rawSource, &instanceCopyList[i].sourceDigest)
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, false)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, singleImageOpts)
if err != nil {
return nil, fmt.Errorf("copying image %d/%d from manifest list: %w", i+1, len(instanceCopyList), err)
}
Expand Down
10 changes: 7 additions & 3 deletions copy/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type imageCopier struct {
requireCompressionFormatMatch bool
}

type copySingleImageOptions struct {
requireCompressionFormatMatch bool
}

// copySingleImageResult carries data produced by copySingleImage
type copySingleImageResult struct {
manifest []byte
Expand All @@ -50,7 +54,7 @@ type copySingleImageResult struct {

// copySingleImage copies a single (non-manifest-list) image unparsedImage, using c.policyContext to validate
// source image admissibility.
func (c *copier) copySingleImage(ctx context.Context, unparsedImage *image.UnparsedImage, targetInstance *digest.Digest, requireCompressionFormatMatch bool) (copySingleImageResult, error) {
func (c *copier) copySingleImage(ctx context.Context, unparsedImage *image.UnparsedImage, targetInstance *digest.Digest, opts copySingleImageOptions) (copySingleImageResult, error) {
// The caller is handling manifest lists; this could happen only if a manifest list contains a manifest list.
// Make sure we fail cleanly in such cases.
multiImage, err := isMultiImage(ctx, unparsedImage)
Expand Down Expand Up @@ -131,7 +135,7 @@ func (c *copier) copySingleImage(ctx context.Context, unparsedImage *image.Unpar
src: src,
// diffIDsAreNeeded is computed later
cannotModifyManifestReason: cannotModifyManifestReason,
requireCompressionFormatMatch: requireCompressionFormatMatch,
requireCompressionFormatMatch: opts.requireCompressionFormatMatch,
}
if c.options.DestinationCtx != nil {
// Note that compressionFormat and compressionLevel can be nil.
Expand Down Expand Up @@ -180,7 +184,7 @@ func (c *copier) copySingleImage(ctx context.Context, unparsedImage *image.Unpar
shouldUpdateSigs := len(sigs) > 0 || len(c.signers) != 0 // TODO: Consider allowing signatures updates only and skipping the image's layers/manifest copy if possible
noPendingManifestUpdates := ic.noPendingManifestUpdates()

logrus.Debugf("Checking if we can skip copying: has signatures=%t, OCI encryption=%t, no manifest updates=%t, compression match required for resuing blobs=%t", shouldUpdateSigs, destRequiresOciEncryption, noPendingManifestUpdates, requireCompressionFormatMatch)
logrus.Debugf("Checking if we can skip copying: has signatures=%t, OCI encryption=%t, no manifest updates=%t, compression match required for resuing blobs=%t", shouldUpdateSigs, destRequiresOciEncryption, noPendingManifestUpdates, opts.requireCompressionFormatMatch)
if !shouldUpdateSigs && !destRequiresOciEncryption && noPendingManifestUpdates && !ic.requireCompressionFormatMatch {
matchedResult, err := ic.compareImageDestinationManifestEqual(ctx, targetInstance)
if err != nil {
Expand Down

0 comments on commit 63deaa7

Please sign in to comment.