Skip to content

Commit 5cb5231

Browse files
committed
1 parent 230b7f8 commit 5cb5231

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

internal/resolve/catalog.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -232,52 +232,33 @@ func isDeprecated(bundle declcfg.Bundle, deprecation *declcfg.Deprecation) bool
232232

233233
type CatalogWalkFunc func(context.Context, *catalogd.ClusterCatalog, *declcfg.DeclarativeConfig, error) error
234234

235-
func CatalogWalker(listCatalogs func(context.Context, ...client.ListOption) ([]catalogd.ClusterCatalog, error), getPackage func(context.Context, *catalogd.ClusterCatalog, string) (*declcfg.DeclarativeConfig, error)) func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error {
235+
func CatalogWalker(
236+
listCatalogs func(context.Context, ...client.ListOption) ([]catalogd.ClusterCatalog, error),
237+
getPackage func(context.Context, *catalogd.ClusterCatalog, string) (*declcfg.DeclarativeConfig, error),
238+
) func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error {
236239
return func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error {
237240
l := log.FromContext(ctx)
238241
catalogs, err := listCatalogs(ctx, catalogListOpts...)
239242
if err != nil {
240243
return fmt.Errorf("error listing catalogs: %w", err)
241244
}
242245

243-
// Track if at least one catalog was processed (not disabled)
244-
processedCatalogs := false
245-
bundleFound := false
246-
247246
for i := range catalogs {
248247
cat := &catalogs[i]
249248

250249
// skip catalogs with Availability set to "Disabled"
251-
if cat.Spec.Availability == "" || cat.Spec.Availability == "Enabled" {
252-
// Continue processing the catalog as it is enabled
253-
} else if cat.Spec.Availability == "Disabled" {
250+
if cat.Spec.Availability == "Disabled" {
254251
l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", cat.Name)
255252
continue
256253
}
257254

258-
// Mark that we processed at least one catalog
259-
processedCatalogs = true
260-
261255
fbc, fbcErr := getPackage(ctx, cat, packageName)
262-
if fbcErr == nil && fbc != nil {
263-
bundleFound = true
264-
}
265256

266257
if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil {
267258
return walkErr
268259
}
269260
}
270261

271-
// If no catalogs were processed at all, return a 'no catalogs' error
272-
if !processedCatalogs {
273-
return fmt.Errorf("no enabled catalogs found")
274-
}
275-
276-
// Return an error if no valid bundle was found in any processed catalog
277-
if !bundleFound {
278-
return fmt.Errorf("no bundles found for package: %s", packageName)
279-
}
280-
281262
return nil
282263
}
283264
}

internal/resolve/catalog_test.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ func TestAllCatalogsDisabled(t *testing.T) {
982982
}
983983

984984
getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) {
985-
return genPackage(pkgName), nil
985+
panic("getPackage should never be called when all catalogs are disabled")
986986
}
987987

988988
r := CatalogResolver{
@@ -992,7 +992,7 @@ func TestAllCatalogsDisabled(t *testing.T) {
992992
ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
993993
_, _, _, err := r.Resolve(context.Background(), ce, nil)
994994
require.Error(t, err)
995-
assert.Contains(t, err.Error(), "no enabled catalogs found")
995+
assert.Contains(t, err.Error(), "no bundles found for package")
996996
}
997997

998998
func TestSomeCatalogsDisabled(t *testing.T) {
@@ -1032,33 +1032,58 @@ func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) {
10321032
listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) {
10331033
return []catalogd.ClusterCatalog{
10341034
{
1035+
ObjectMeta: metav1.ObjectMeta{
1036+
Name: "enabledCatalog",
1037+
},
10351038
Spec: catalogd.ClusterCatalogSpec{
1036-
Priority: 1,
1039+
Priority: 0, // Lower priority
10371040
Availability: "Enabled",
10381041
},
10391042
},
10401043
{
1044+
ObjectMeta: metav1.ObjectMeta{
1045+
Name: "disabledCatalog",
1046+
},
10411047
Spec: catalogd.ClusterCatalogSpec{
1042-
Priority: 0,
1048+
Priority: 1, // Higher priority
10431049
Availability: "Disabled",
10441050
},
10451051
},
10461052
}, nil
10471053
}
10481054

10491055
getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) {
1050-
return genPackage(pkgName), nil
1056+
if cat.Spec.Availability == "Disabled" {
1057+
panic("getPackage should not be called for disabled catalogs")
1058+
}
1059+
// Enabled catalog returns a lower version
1060+
return &declcfg.DeclarativeConfig{
1061+
Packages: []declcfg.Package{{Name: pkgName}},
1062+
Channels: []declcfg.Channel{
1063+
{
1064+
Package: pkgName,
1065+
Name: "alpha",
1066+
Entries: []declcfg.ChannelEntry{
1067+
{Name: bundleName(pkgName, "1.0.0")},
1068+
},
1069+
},
1070+
},
1071+
Bundles: []declcfg.Bundle{
1072+
genBundle(pkgName, "1.0.0"),
1073+
},
1074+
}, nil
10511075
}
10521076

10531077
r := CatalogResolver{
10541078
WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage),
10551079
}
10561080

1057-
ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
1081+
ce := buildFooClusterExtension(pkgName, []string{}, "", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
10581082
gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil)
10591083
require.NoError(t, err)
10601084
require.NotNil(t, gotBundle)
1061-
require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion)
1085+
require.Equal(t, genBundle(pkgName, "1.0.0"), *gotBundle)
1086+
require.Equal(t, bsemver.MustParse("1.0.0"), *gotVersion)
10621087
}
10631088

10641089
func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) {

0 commit comments

Comments
 (0)