From 775fc0eb5bf6e6e422253199bac7234ba16b0fed Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Wed, 9 Oct 2024 17:48:00 -0400 Subject: [PATCH 01/10] Add support for catalogs with Spec.Availability Signed-off-by: Brett Tofel --- go.mod | 4 + internal/resolve/catalog.go | 33 +++++++ internal/resolve/catalog_test.go | 147 +++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) diff --git a/go.mod b/go.mod index f43a9e2a3..01cf3943d 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,10 @@ require ( sigs.k8s.io/yaml v1.4.0 ) +replace ( + github.com/operator-framework/catalogd => ../catalogd +) + require ( carvel.dev/vendir v0.40.0 // indirect dario.cat/mergo v1.0.1 // indirect diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index 0c9dac762..b622ae2a7 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -3,6 +3,7 @@ package resolve import ( "context" "fmt" + "sigs.k8s.io/controller-runtime/pkg/log" "slices" "sort" "strings" @@ -233,18 +234,50 @@ type CatalogWalkFunc func(context.Context, *catalogd.ClusterCatalog, *declcfg.De 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 { return func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error { + l := log.FromContext(ctx) catalogs, err := listCatalogs(ctx, catalogListOpts...) if err != nil { return fmt.Errorf("error listing catalogs: %w", err) } + // Track if at least one catalog was processed (not disabled) + processedCatalogs := false + bundleFound := false + for i := range catalogs { cat := &catalogs[i] + + // skip catalogs with Availability set to "Disabled" + if cat.Spec.Availability == "" || cat.Spec.Availability == "Enabled" { + // Continue processing the catalog as it is enabled + } else if cat.Spec.Availability == "Disabled" { + l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", cat.Name) + continue + } + + // Mark that we processed at least one catalog + processedCatalogs = true + fbc, fbcErr := getPackage(ctx, cat, packageName) + if fbcErr == nil && fbc != nil { + bundleFound = true + } + if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil { return walkErr } } + + // If no catalogs were processed at all, return a 'no catalogs' error + if !processedCatalogs { + return fmt.Errorf("no enabled catalogs found for package: %s", packageName) + } + + // Return an error if no valid bundle was found in any processed catalog + if !bundleFound { + return fmt.Errorf("no bundles found for package: %s", packageName) + } + return nil } } diff --git a/internal/resolve/catalog_test.go b/internal/resolve/catalog_test.go index bce3b5778..27bacf2dd 100644 --- a/internal/resolve/catalog_test.go +++ b/internal/resolve/catalog_test.go @@ -963,3 +963,150 @@ func TestMultipleChannels(t *testing.T) { assert.Equal(t, bsemver.MustParse("2.0.0"), *gotVersion) assert.Equal(t, ptr.To(packageDeprecation(pkgName)), gotDeprecation) } + +func TestAllCatalogsDisabled(t *testing.T) { + pkgName := randPkg() + listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { + return []catalogd.ClusterCatalog{ + { + Spec: catalogd.ClusterCatalogSpec{ + Availability: "Disabled", + }, + }, + { + Spec: catalogd.ClusterCatalogSpec{ + Availability: "Disabled", + }, + }, + }, nil + } + + getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { + return genPackage(pkgName), nil + } + + r := CatalogResolver{ + WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), + } + + ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) + _, _, _, err := r.Resolve(context.Background(), ce, nil) + require.Error(t, err) + assert.Contains(t, err.Error(), "no enabled catalogs found for package") +} + +func TestSomeCatalogsDisabled(t *testing.T) { + pkgName := randPkg() + listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { + return []catalogd.ClusterCatalog{ + { + Spec: catalogd.ClusterCatalogSpec{ + Availability: "Enabled", + }, + }, + { + Spec: catalogd.ClusterCatalogSpec{ + Availability: "Disabled", + }, + }, + }, nil + } + + getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { + return genPackage(pkgName), nil + } + + r := CatalogResolver{ + WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), + } + + ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) + gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) + require.NoError(t, err) + require.NotNil(t, gotBundle) + require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion) +} + +func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) { + pkgName := randPkg() + listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { + return []catalogd.ClusterCatalog{ + { + Spec: catalogd.ClusterCatalogSpec{ + Priority: 1, + Availability: "Enabled", + }, + }, + { + Spec: catalogd.ClusterCatalogSpec{ + Priority: 0, + Availability: "Disabled", + }, + }, + }, nil + } + + getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { + return genPackage(pkgName), nil + } + + r := CatalogResolver{ + WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), + } + + ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) + gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) + require.NoError(t, err) + require.NotNil(t, gotBundle) + require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion) +} + +func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) { + pkgName := randPkg() + listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { + return []catalogd.ClusterCatalog{ + { + Spec: catalogd.ClusterCatalogSpec{ + Priority: 1, // No Availability field set + }, + }, + { + Spec: catalogd.ClusterCatalogSpec{ + Availability: "Disabled", // This should be skipped + Priority: 2, + }, + }, + }, nil + } + + getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { + if cat.Spec.Availability == "" || cat.Spec.Availability == "Enabled" { + return genPackage(pkgName), nil + } + return &declcfg.DeclarativeConfig{ + Packages: []declcfg.Package{{Name: pkgName}}, + Channels: []declcfg.Channel{ + { + Package: pkgName, + Name: "alpha", + Entries: []declcfg.ChannelEntry{ + {Name: bundleName(pkgName, "3.0.0")}, + }, + }, + }, + Bundles: []declcfg.Bundle{ + genBundle(pkgName, "3.0.0"), + }, + }, nil + } + + r := CatalogResolver{ + WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), + } + + ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) + gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) + require.NoError(t, err) + require.NotNil(t, gotBundle) + require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion, "expected version to be 3.0.0, but got %s", gotVersion) +} From 81f642be044e7dd0deeb10fc1b097a174b9e0953 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Wed, 9 Oct 2024 17:49:11 -0400 Subject: [PATCH 02/10] Revert local go.mod change Signed-off-by: Brett Tofel --- go.mod | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.mod b/go.mod index 01cf3943d..f43a9e2a3 100644 --- a/go.mod +++ b/go.mod @@ -37,10 +37,6 @@ require ( sigs.k8s.io/yaml v1.4.0 ) -replace ( - github.com/operator-framework/catalogd => ../catalogd -) - require ( carvel.dev/vendir v0.40.0 // indirect dario.cat/mergo v1.0.1 // indirect From 93eae4f2c5d03dd4cfda9dc2c268c355c55f2d92 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Tue, 15 Oct 2024 09:48:29 -0400 Subject: [PATCH 03/10] Error message change to not be misleading Co-authored-by: Joe Lanford --- internal/resolve/catalog.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index b622ae2a7..ba5e4ebee 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -270,7 +270,7 @@ func CatalogWalker(listCatalogs func(context.Context, ...client.ListOption) ([]c // If no catalogs were processed at all, return a 'no catalogs' error if !processedCatalogs { - return fmt.Errorf("no enabled catalogs found for package: %s", packageName) + return errors.New("no enabled catalogs found") } // Return an error if no valid bundle was found in any processed catalog From 230b7f8da31be3c3804fadf085abec9d27be53b2 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Tue, 15 Oct 2024 15:04:59 -0400 Subject: [PATCH 04/10] Fixups after accepting suggested error changes Signed-off-by: Brett Tofel --- internal/resolve/catalog.go | 2 +- internal/resolve/catalog_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index ba5e4ebee..12f5c0d7e 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -270,7 +270,7 @@ func CatalogWalker(listCatalogs func(context.Context, ...client.ListOption) ([]c // If no catalogs were processed at all, return a 'no catalogs' error if !processedCatalogs { - return errors.New("no enabled catalogs found") + return fmt.Errorf("no enabled catalogs found") } // Return an error if no valid bundle was found in any processed catalog diff --git a/internal/resolve/catalog_test.go b/internal/resolve/catalog_test.go index 27bacf2dd..7fe442013 100644 --- a/internal/resolve/catalog_test.go +++ b/internal/resolve/catalog_test.go @@ -992,7 +992,7 @@ func TestAllCatalogsDisabled(t *testing.T) { ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) _, _, _, err := r.Resolve(context.Background(), ce, nil) require.Error(t, err) - assert.Contains(t, err.Error(), "no enabled catalogs found for package") + assert.Contains(t, err.Error(), "no enabled catalogs found") } func TestSomeCatalogsDisabled(t *testing.T) { From 5cb523120796a612a49b04b6265d7f3d63d41c12 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Wed, 16 Oct 2024 08:50:46 -0400 Subject: [PATCH 05/10] Changes for PR comments... https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801073127 https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801070984 https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801064220 https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801061282 https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801054976 https://github.com/operator-framework/operator-controller/pull/1359#discussion_r1801046747 Signed-off-by: Brett Tofel --- internal/resolve/catalog.go | 29 ++++-------------------- internal/resolve/catalog_test.go | 39 ++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index 12f5c0d7e..3818002d9 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -232,7 +232,10 @@ func isDeprecated(bundle declcfg.Bundle, deprecation *declcfg.Deprecation) bool type CatalogWalkFunc func(context.Context, *catalogd.ClusterCatalog, *declcfg.DeclarativeConfig, error) error -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 { +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 { return func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error { l := log.FromContext(ctx) catalogs, err := listCatalogs(ctx, catalogListOpts...) @@ -240,44 +243,22 @@ func CatalogWalker(listCatalogs func(context.Context, ...client.ListOption) ([]c return fmt.Errorf("error listing catalogs: %w", err) } - // Track if at least one catalog was processed (not disabled) - processedCatalogs := false - bundleFound := false - for i := range catalogs { cat := &catalogs[i] // skip catalogs with Availability set to "Disabled" - if cat.Spec.Availability == "" || cat.Spec.Availability == "Enabled" { - // Continue processing the catalog as it is enabled - } else if cat.Spec.Availability == "Disabled" { + if cat.Spec.Availability == "Disabled" { l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", cat.Name) continue } - // Mark that we processed at least one catalog - processedCatalogs = true - fbc, fbcErr := getPackage(ctx, cat, packageName) - if fbcErr == nil && fbc != nil { - bundleFound = true - } if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil { return walkErr } } - // If no catalogs were processed at all, return a 'no catalogs' error - if !processedCatalogs { - return fmt.Errorf("no enabled catalogs found") - } - - // Return an error if no valid bundle was found in any processed catalog - if !bundleFound { - return fmt.Errorf("no bundles found for package: %s", packageName) - } - return nil } } diff --git a/internal/resolve/catalog_test.go b/internal/resolve/catalog_test.go index 7fe442013..a8db695f9 100644 --- a/internal/resolve/catalog_test.go +++ b/internal/resolve/catalog_test.go @@ -982,7 +982,7 @@ func TestAllCatalogsDisabled(t *testing.T) { } getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { - return genPackage(pkgName), nil + panic("getPackage should never be called when all catalogs are disabled") } r := CatalogResolver{ @@ -992,7 +992,7 @@ func TestAllCatalogsDisabled(t *testing.T) { ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) _, _, _, err := r.Resolve(context.Background(), ce, nil) require.Error(t, err) - assert.Contains(t, err.Error(), "no enabled catalogs found") + assert.Contains(t, err.Error(), "no bundles found for package") } func TestSomeCatalogsDisabled(t *testing.T) { @@ -1032,14 +1032,20 @@ func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) { listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { return []catalogd.ClusterCatalog{ { + ObjectMeta: metav1.ObjectMeta{ + Name: "enabledCatalog", + }, Spec: catalogd.ClusterCatalogSpec{ - Priority: 1, + Priority: 0, // Lower priority Availability: "Enabled", }, }, { + ObjectMeta: metav1.ObjectMeta{ + Name: "disabledCatalog", + }, Spec: catalogd.ClusterCatalogSpec{ - Priority: 0, + Priority: 1, // Higher priority Availability: "Disabled", }, }, @@ -1047,18 +1053,37 @@ func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) { } getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { - return genPackage(pkgName), nil + if cat.Spec.Availability == "Disabled" { + panic("getPackage should not be called for disabled catalogs") + } + // Enabled catalog returns a lower version + return &declcfg.DeclarativeConfig{ + Packages: []declcfg.Package{{Name: pkgName}}, + Channels: []declcfg.Channel{ + { + Package: pkgName, + Name: "alpha", + Entries: []declcfg.ChannelEntry{ + {Name: bundleName(pkgName, "1.0.0")}, + }, + }, + }, + Bundles: []declcfg.Bundle{ + genBundle(pkgName, "1.0.0"), + }, + }, nil } r := CatalogResolver{ WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), } - ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) + ce := buildFooClusterExtension(pkgName, []string{}, "", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) require.NoError(t, err) require.NotNil(t, gotBundle) - require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion) + require.Equal(t, genBundle(pkgName, "1.0.0"), *gotBundle) + require.Equal(t, bsemver.MustParse("1.0.0"), *gotVersion) } func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) { From 13abfed5500f01f6da5bbd2b2e206c0658da06aa Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Wed, 16 Oct 2024 10:07:07 -0400 Subject: [PATCH 06/10] Change to preprocess catalogs for enabled... And delete unneeded test for mixed case priority+disablement Signed-off-by: Brett Tofel --- internal/resolve/catalog.go | 16 +++++---- internal/resolve/catalog_test.go | 59 -------------------------------- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index 3818002d9..c9d55d664 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -243,15 +243,19 @@ func CatalogWalker( return fmt.Errorf("error listing catalogs: %w", err) } + // Remove disabled catalogs from consideration + catalogs = slices.DeleteFunc(catalogs, func(c catalogd.ClusterCatalog) bool { + if c.Spec.Availability == "Disabled" { + l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", c.Name) + return true + } + return false + }) + for i := range catalogs { cat := &catalogs[i] - // skip catalogs with Availability set to "Disabled" - if cat.Spec.Availability == "Disabled" { - l.Info("excluding ClusterCatalog from resolution process since it is disabled", "catalog", cat.Name) - continue - } - + // process enabled catalogs fbc, fbcErr := getPackage(ctx, cat, packageName) if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil { diff --git a/internal/resolve/catalog_test.go b/internal/resolve/catalog_test.go index a8db695f9..e6672cb8d 100644 --- a/internal/resolve/catalog_test.go +++ b/internal/resolve/catalog_test.go @@ -1027,65 +1027,6 @@ func TestSomeCatalogsDisabled(t *testing.T) { require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion) } -func TestPriorityRespectedWithDisabledCatalogs(t *testing.T) { - pkgName := randPkg() - listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { - return []catalogd.ClusterCatalog{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "enabledCatalog", - }, - Spec: catalogd.ClusterCatalogSpec{ - Priority: 0, // Lower priority - Availability: "Enabled", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "disabledCatalog", - }, - Spec: catalogd.ClusterCatalogSpec{ - Priority: 1, // Higher priority - Availability: "Disabled", - }, - }, - }, nil - } - - getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { - if cat.Spec.Availability == "Disabled" { - panic("getPackage should not be called for disabled catalogs") - } - // Enabled catalog returns a lower version - return &declcfg.DeclarativeConfig{ - Packages: []declcfg.Package{{Name: pkgName}}, - Channels: []declcfg.Channel{ - { - Package: pkgName, - Name: "alpha", - Entries: []declcfg.ChannelEntry{ - {Name: bundleName(pkgName, "1.0.0")}, - }, - }, - }, - Bundles: []declcfg.Bundle{ - genBundle(pkgName, "1.0.0"), - }, - }, nil - } - - r := CatalogResolver{ - WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), - } - - ce := buildFooClusterExtension(pkgName, []string{}, "", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) - gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) - require.NoError(t, err) - require.NotNil(t, gotBundle) - require.Equal(t, genBundle(pkgName, "1.0.0"), *gotBundle) - require.Equal(t, bsemver.MustParse("1.0.0"), *gotVersion) -} - func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) { pkgName := randPkg() listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { From e851bcdc872cfca5efa0dd8b5347fe78640637da Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Wed, 16 Oct 2024 10:26:14 -0400 Subject: [PATCH 07/10] Remove TestCatalogWithoutAvailabilityIsEnabled Signed-off-by: Brett Tofel --- internal/resolve/catalog_test.go | 59 +++++--------------------------- 1 file changed, 9 insertions(+), 50 deletions(-) diff --git a/internal/resolve/catalog_test.go b/internal/resolve/catalog_test.go index e6672cb8d..4856efc7e 100644 --- a/internal/resolve/catalog_test.go +++ b/internal/resolve/catalog_test.go @@ -1000,12 +1000,20 @@ func TestSomeCatalogsDisabled(t *testing.T) { listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { return []catalogd.ClusterCatalog{ { + ObjectMeta: metav1.ObjectMeta{ + Name: "enabledCatalog", + }, Spec: catalogd.ClusterCatalogSpec{ + Priority: 1, // Higher priority Availability: "Enabled", }, }, { + ObjectMeta: metav1.ObjectMeta{ + Name: "disabledCatalog", + }, Spec: catalogd.ClusterCatalogSpec{ + Priority: 0, // Lower priority (but disabled) Availability: "Disabled", }, }, @@ -1013,6 +1021,7 @@ func TestSomeCatalogsDisabled(t *testing.T) { } getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { + // Only enabled catalog should be processed return genPackage(pkgName), nil } @@ -1026,53 +1035,3 @@ func TestSomeCatalogsDisabled(t *testing.T) { require.NotNil(t, gotBundle) require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion) } - -func TestCatalogWithoutAvailabilityIsEnabled(t *testing.T) { - pkgName := randPkg() - listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) { - return []catalogd.ClusterCatalog{ - { - Spec: catalogd.ClusterCatalogSpec{ - Priority: 1, // No Availability field set - }, - }, - { - Spec: catalogd.ClusterCatalogSpec{ - Availability: "Disabled", // This should be skipped - Priority: 2, - }, - }, - }, nil - } - - getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) { - if cat.Spec.Availability == "" || cat.Spec.Availability == "Enabled" { - return genPackage(pkgName), nil - } - return &declcfg.DeclarativeConfig{ - Packages: []declcfg.Package{{Name: pkgName}}, - Channels: []declcfg.Channel{ - { - Package: pkgName, - Name: "alpha", - Entries: []declcfg.ChannelEntry{ - {Name: bundleName(pkgName, "3.0.0")}, - }, - }, - }, - Bundles: []declcfg.Bundle{ - genBundle(pkgName, "3.0.0"), - }, - }, nil - } - - r := CatalogResolver{ - WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage), - } - - ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided) - gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil) - require.NoError(t, err) - require.NotNil(t, gotBundle) - require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion, "expected version to be 3.0.0, but got %s", gotVersion) -} From f397f8c660e8d0c903eb905dabfddd5568c62bbb Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Thu, 17 Oct 2024 10:10:40 -0400 Subject: [PATCH 08/10] Bump catalogd dep to v0.33.0 (and rebase) Signed-off-by: Brett Tofel --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f43a9e2a3..ebd0d93b8 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/onsi/gomega v1.34.2 github.com/opencontainers/go-digest v1.0.0 github.com/operator-framework/api v0.27.0 - github.com/operator-framework/catalogd v0.32.0 + github.com/operator-framework/catalogd v0.33.0 github.com/operator-framework/helm-operator-plugins v0.5.0 github.com/operator-framework/operator-registry v1.47.0 github.com/spf13/pflag v1.0.5 @@ -179,7 +179,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/proglottis/gpgme v0.1.3 // indirect - github.com/prometheus/client_golang v1.20.4 // indirect + github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect diff --git a/go.sum b/go.sum index bbc6afea6..ae3144963 100644 --- a/go.sum +++ b/go.sum @@ -535,8 +535,8 @@ github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11 h1:eT github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11/go.mod h1:EmVJt97N+pfWFsli/ipXTBZqSG5F5KGQhm3c3IsGq1o= github.com/operator-framework/api v0.27.0 h1:OrVaGKZJvbZo58HTv2guz7aURkhVKYhFqZ/6VpifiXI= github.com/operator-framework/api v0.27.0/go.mod h1:lg2Xx+S8NQWGYlEOvFwQvH46E5EK5IrAIL7HWfAhciM= -github.com/operator-framework/catalogd v0.32.0 h1:VKD+7wfEF6CnJgR4aUYyT85KP2Te7zjhaPvgvWy25Uw= -github.com/operator-framework/catalogd v0.32.0/go.mod h1:FrFSCwRXr4aPslcXIv48dan5AdM37k/B9tK/RpdvZCU= +github.com/operator-framework/catalogd v0.33.0 h1:hnLIFykO1FkjOAUFRPuYRIHQTE0oBF9jkGmWjKhxniQ= +github.com/operator-framework/catalogd v0.33.0/go.mod h1:anZurjcFMBvbkuyqlJ98v9z+yjniPKqmhlyitk9DuBQ= github.com/operator-framework/helm-operator-plugins v0.5.0 h1:qph2OoECcI9mpuUBtOsWOMgvpx52mPTTSvzVxICsT04= github.com/operator-framework/helm-operator-plugins v0.5.0/go.mod h1:yVncrZ/FJNqedMil+055fk6sw8aMKRrget/AqGM0ig0= github.com/operator-framework/operator-lib v0.15.0 h1:0QeRM4PMtThqINpcFGCEBnIV3Z8u7/8fYLEx6mUtdcM= @@ -569,8 +569,8 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= -github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= -github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= From 33c19e4c346a92f7f7e224d53f046a8914f5d847 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Thu, 17 Oct 2024 12:17:58 -0400 Subject: [PATCH 09/10] After make crd-ref-docs Signed-off-by: Brett Tofel --- docs/api-reference/catalogd-api-reference.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api-reference/catalogd-api-reference.md b/docs/api-reference/catalogd-api-reference.md index f29bd21d4..fa52fbc00 100644 --- a/docs/api-reference/catalogd-api-reference.md +++ b/docs/api-reference/catalogd-api-reference.md @@ -98,6 +98,7 @@ _Appears in:_ | --- | --- | --- | --- | | `source` _[CatalogSource](#catalogsource)_ | source is a required field that allows the user to define the source of a Catalog that contains catalog metadata in the File-Based Catalog (FBC) format.

Below is a minimal example of a ClusterCatalogSpec that sources a catalog from an image:

source:
type: Image
image:
ref: quay.io/operatorhubio/catalog:latest

For more information on FBC, see https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs | | | | `priority` _integer_ | priority is an optional field that allows the user to define a priority for a ClusterCatalog.
A ClusterCatalog's priority is used by clients as a tie-breaker between ClusterCatalogs that meet the client's requirements.
For example, in the case where multiple ClusterCatalogs provide the same bundle.
A higher number means higher priority. Negative numbers are also accepted.
When omitted, the default priority is 0. | 0 | | +| `availability` _string_ | Availability is an optional field that allows users to define whether the ClusterCatalog is utilized by the operator-controller.

Allowed values are : ["Enabled", "Disabled"].
If set to "Enabled", the catalog will be used for updates, serving contents, and package installations.

If set to "Disabled", catalogd will stop serving the catalog and the cached data will be removed.

If unspecified, the default value is "Enabled" | Enabled | Enum: [Disabled Enabled]
| #### ClusterCatalogStatus From b0601015d4f2d76def43f35781052aed39cd3ba5 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Thu, 17 Oct 2024 13:29:14 -0400 Subject: [PATCH 10/10] After gci run Signed-off-by: Brett Tofel --- internal/resolve/catalog.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/resolve/catalog.go b/internal/resolve/catalog.go index c9d55d664..de210fe3c 100644 --- a/internal/resolve/catalog.go +++ b/internal/resolve/catalog.go @@ -3,7 +3,6 @@ package resolve import ( "context" "fmt" - "sigs.k8s.io/controller-runtime/pkg/log" "slices" "sort" "strings" @@ -14,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/sets" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" "github.com/operator-framework/operator-registry/alpha/declcfg"