Skip to content
Merged
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
40 changes: 21 additions & 19 deletions pkg/lib/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,37 @@ func populate(ctx context.Context, loader registry.Load, graphLoader registry.Gr
if err != nil {
return err
}
cleanups := make(chan func(), 1)
errs := make(chan error, 1)
type unpackedImage struct {
to image.Reference
from string
cleanup func()
err error
}
unpacked := make(chan unpackedImage)
for bundle := range bundles {
if _, ok := overwriteImageMap[img.Bundle.Package]; !ok {
overwriteImageMap[img.Bundle.Package] = make(map[image.Reference]string, 0)
}
// parallelize image pulls
go func(bundle registry.BundleKey, img *registry.ImageInput) {
if bundle.CsvName != img.Bundle.Name {
to, from, cleanup, err := unpackImage(ctx, reg, image.SimpleReference(bundle.BundlePath))
if err != nil {
errs <- err
}
cleanups <- cleanup
overwriteImageMap[img.Bundle.Package][to] = from
unpacked <- unpackedImage{to: to, from: from, cleanup: cleanup, err: err}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if unpackImage were updated to return an unpackedImage, this whole goroutine could just be:

go func(bundle registry.BundleKey, img *registry.ImageInput) {
  unpacked <- unpackImage(ctx, reg, image.SimpleReference(bundle.BundlePath))
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to skip the one we already unpacked

} else {
overwriteImageMap[img.Bundle.Package][to] = from
delete(unpackedImageMap, to)
unpacked <- unpackedImage{to: to, from: from, cleanup: func() { return }, err: nil}
}
}(bundle, img)
}
for i := 0; i < len(bundles)-1; i++ {
select {
case err := <-errs:
return err
default:
cleanup := <-cleanups
defer cleanup()
if _, ok := overwriteImageMap[img.Bundle.Package]; !ok {
overwriteImageMap[img.Bundle.Package] = make(map[image.Reference]string, 0)
}
for i := 0; i < len(bundles); i++ {
unpack := <-unpacked
if unpack.err != nil {
return unpack.err
}
overwriteImageMap[img.Bundle.Package][unpack.to] = unpack.from
if _, ok := unpackedImageMap[unpack.to]; ok {
delete(unpackedImageMap, unpack.to)
}
defer unpack.cleanup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we cleanup bundles if they have errors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally yes but it depends on the error if there is anything to clean up

}
} else {
return fmt.Errorf("index add --overwrite-latest is only supported when using bundle images")
Expand Down