Skip to content

Commit 0478f25

Browse files
authored
ocpbugs-60999: fix issue when using full true in m2m (#1256)
Before this fix during m2m when using full: true, the dispatch func was trying to retrieve a rebuilt catalog image from cache. This behavior was wrong since full: true does not rebuild the catalog. This PR fixes this behavior, it gets the original catalog image in case no RebuiltTag was found for the catalog image.
1 parent 3dff800 commit 0478f25

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

v2/internal/pkg/api/v2alpha1/type_internal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ type RelatedImage struct {
195195
//Used to identify if a related image is from an operator catalog on disk (oci:// on ImageSetConfiguration)
196196
//TODO remove me when the migration from oc-mirror v1 to v2 ends
197197
OriginFromOperatorCatalogOnDisk bool
198+
// Used to identify if it is a full catalog (full: true && zero packages)
199+
FullCatalog bool
198200
}
199201

200202
type CollectorSchema struct {

v2/internal/pkg/operator/common.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,13 @@ func (d CatalogImageDispatcher) dispatch(img v2alpha1.RelatedImage) ([]v2alpha1.
467467
if err != nil {
468468
return []v2alpha1.CopyImageSchema{}, err
469469
}
470-
var toCacheImage, fromRebuiltImage, toDestImage string
470+
var toCacheImage, from, toDestImage string
471+
// OCPBUGS-60999 - if full: true with zero packages, it gets the original catalog image otherwise get the rebuilt catalog image from cache
472+
from = imgSpec.ReferenceWithTransport
473+
if !img.FullCatalog {
474+
from = rebuiltCtlgRef(imgSpec, img, d.cacheRegistry)
475+
}
471476
toCacheImage = saveCtlgToCacheRef(imgSpec, img, d.cacheRegistry)
472-
fromRebuiltImage = rebuiltCtlgRef(imgSpec, img, d.cacheRegistry)
473477
toDestImage = destCtlgRef(imgSpec, img, d.destinationRegistry)
474478
cacheCopy := v2alpha1.CopyImageSchema{
475479
Source: imgSpec.ReferenceWithTransport,
@@ -479,7 +483,7 @@ func (d CatalogImageDispatcher) dispatch(img v2alpha1.RelatedImage) ([]v2alpha1.
479483
Type: img.Type,
480484
}
481485
destCopy := v2alpha1.CopyImageSchema{
482-
Source: fromRebuiltImage,
486+
Source: from,
483487
Destination: toDestImage,
484488
Origin: imgSpec.ReferenceWithTransport,
485489
RebuiltTag: img.RebuiltTag,
@@ -535,7 +539,6 @@ func rebuiltCtlgRef(spec image.ImageSpec, img v2alpha1.RelatedImage, cacheRegist
535539
// applies only to catalogs
536540
case img.RebuiltTag != "":
537541
rebuiltCtlgSrc = rebuiltCtlgSrc + ":" + img.RebuiltTag
538-
case len(img.TargetTag) > 0:
539542
case img.Type == v2alpha1.TypeOperatorCatalog && len(img.TargetTag) > 0:
540543
rebuiltCtlgSrc = rebuiltCtlgSrc + ":" + img.TargetTag
541544
case spec.Tag == "" && spec.Transport == ociProtocol:

v2/internal/pkg/operator/filtered_collector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func (o FilterCollector) collectOperator( //nolint:cyclop // TODO: this needs fu
267267
TargetTag: targetTag,
268268
TargetCatalog: op.TargetCatalog,
269269
RebuiltTag: rebuiltTag,
270+
FullCatalog: isFullCatalog(op),
270271
},
271272
}
272273
return result, nil

v2/internal/pkg/operator/filtered_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ func TestFilterCollectorM2M(t *testing.T) {
705705
Type: v2alpha1.TypeOperatorCatalog,
706706
},
707707
{
708-
Source: "docker://localhost:9999/redhat/community-operator-index:v4.18",
708+
Source: "docker://registry.redhat.io/redhat/community-operator-index:v4.18",
709709
Destination: "docker://localhost:5000/test/redhat/community-operator-index:v4.18",
710710
Origin: "docker://registry.redhat.io/redhat/community-operator-index:v4.18",
711711
Type: v2alpha1.TypeOperatorCatalog,

0 commit comments

Comments
 (0)