diff --git a/pkg/imgpkg/bundle/bundle.go b/pkg/imgpkg/bundle/bundle.go index 5049843ca..27d366f1e 100644 --- a/pkg/imgpkg/bundle/bundle.go +++ b/pkg/imgpkg/bundle/bundle.go @@ -126,20 +126,25 @@ func (o *Bundle) NoteCopy(processedImages *imageset.ProcessedImages, reg ImagesM APIVersion: LocationAPIVersion, Kind: ImageLocationsKind, } + foundImages := map[string]bool{} var bundleProcessedImage imageset.ProcessedImage for _, image := range processedImages.All() { - ref, found := o.findCachedImageRef(image.UnprocessedImageRef.DigestRef) - if found { - locationsCfg.Images = append(locationsCfg.Images, ImageLocation{ - Image: ref.Image, - IsBundle: *ref.IsBundle, - }) - } imgDigest, err := regname.NewDigest(image.UnprocessedImageRef.DigestRef) if err != nil { panic(fmt.Sprintf("Internal inconsistency: Image '%s' is not a valid Digest Reference", err)) } + ref, found := o.findCachedImageRef(image.UnprocessedImageRef.DigestRef) + if found { + if _, ok := foundImages[imgDigest.DigestStr()]; !ok { + locationsCfg.Images = append(locationsCfg.Images, ImageLocation{ + Image: ref.Image, + IsBundle: *ref.IsBundle, + }) + foundImages[imgDigest.DigestStr()] = true + } + } + if imgDigest.DigestStr() == o.Digest() { bundleProcessedImage = image } diff --git a/pkg/imgpkg/imageset/unprocessed_image_refs.go b/pkg/imgpkg/imageset/unprocessed_image_refs.go index d0ba7353b..cb5c5d482 100644 --- a/pkg/imgpkg/imageset/unprocessed_image_refs.go +++ b/pkg/imgpkg/imageset/unprocessed_image_refs.go @@ -18,7 +18,14 @@ type UnprocessedImageRef struct { OrigRef string } +// Key that uniquely identify a ImageRef func (u UnprocessedImageRef) Key() string { + // With this definition of key if one image is shared by 2 bundles + // but it is referred in the ImagesLock using a different Registry/Repository + // while the SHA is the same, we consider them to be different images, which they are not. + // This will lead to duplication of the image in the UnprocessedImageRef that needs to be + // address by whoever is using it. This should impact performance of copy because ggcr + // will dedupe the Image/Layers based on the SHA. return u.DigestRef + ":" + u.Tag }