Skip to content

Commit 13abfed

Browse files
committed
Change to preprocess catalogs for enabled...
And delete unneeded test for mixed case priority+disablement Signed-off-by: Brett Tofel <[email protected]>
1 parent 5cb5231 commit 13abfed

File tree

2 files changed

+10
-65
lines changed

2 files changed

+10
-65
lines changed

internal/resolve/catalog.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,19 @@ func CatalogWalker(
243243
return fmt.Errorf("error listing catalogs: %w", err)
244244
}
245245

246+
// Remove disabled catalogs from consideration
247+
catalogs = slices.DeleteFunc(catalogs, func(c catalogd.ClusterCatalog) bool {
248+
if c.Spec.Availability == "Disabled" {
249+
l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", c.Name)
250+
return true
251+
}
252+
return false
253+
})
254+
246255
for i := range catalogs {
247256
cat := &catalogs[i]
248257

249-
// skip catalogs with Availability set to "Disabled"
250-
if cat.Spec.Availability == "Disabled" {
251-
l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", cat.Name)
252-
continue
253-
}
254-
258+
// process enabled catalogs
255259
fbc, fbcErr := getPackage(ctx, cat, packageName)
256260

257261
if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil {

internal/resolve/catalog_test.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,65 +1027,6 @@ func TestSomeCatalogsDisabled(t *testing.T) {
10271027
require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion)
10281028
}
10291029

1030-
func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) {
1031-
pkgName := randPkg()
1032-
listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) {
1033-
return []catalogd.ClusterCatalog{
1034-
{
1035-
ObjectMeta: metav1.ObjectMeta{
1036-
Name: "enabledCatalog",
1037-
},
1038-
Spec: catalogd.ClusterCatalogSpec{
1039-
Priority: 0, // Lower priority
1040-
Availability: "Enabled",
1041-
},
1042-
},
1043-
{
1044-
ObjectMeta: metav1.ObjectMeta{
1045-
Name: "disabledCatalog",
1046-
},
1047-
Spec: catalogd.ClusterCatalogSpec{
1048-
Priority: 1, // Higher priority
1049-
Availability: "Disabled",
1050-
},
1051-
},
1052-
}, nil
1053-
}
1054-
1055-
getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) {
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
1075-
}
1076-
1077-
r := CatalogResolver{
1078-
WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage),
1079-
}
1080-
1081-
ce := buildFooClusterExtension(pkgName, []string{}, "", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
1082-
gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil)
1083-
require.NoError(t, err)
1084-
require.NotNil(t, gotBundle)
1085-
require.Equal(t, genBundle(pkgName, "1.0.0"), *gotBundle)
1086-
require.Equal(t, bsemver.MustParse("1.0.0"), *gotVersion)
1087-
}
1088-
10891030
func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) {
10901031
pkgName := randPkg()
10911032
listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) {

0 commit comments

Comments
 (0)