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

When 2 images with same SHA are reference by 2 nested bundles #638

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/imgpkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/imgpkg/imageset/unprocessed_image_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading