Skip to content

Commit 8ae6ca0

Browse files
bentitojoelanford
andauthored
🌱 Use catalog availability (#1359)
* Add support for catalogs with Spec.Availability Signed-off-by: Brett Tofel <[email protected]> * Revert local go.mod change Signed-off-by: Brett Tofel <[email protected]> * Error message change to not be misleading Co-authored-by: Joe Lanford <[email protected]> * Fixups after accepting suggested error changes Signed-off-by: Brett Tofel <[email protected]> * Changes for PR comments... #1359 (comment) #1359 (comment) #1359 (comment) #1359 (comment) #1359 (comment) #1359 (comment) Signed-off-by: Brett Tofel <[email protected]> * Change to preprocess catalogs for enabled... And delete unneeded test for mixed case priority+disablement Signed-off-by: Brett Tofel <[email protected]> * Remove TestCatalogWithoutAvailabilityIsEnabled Signed-off-by: Brett Tofel <[email protected]> * Bump catalogd dep to v0.33.0 (and rebase) Signed-off-by: Brett Tofel <[email protected]> * After make crd-ref-docs Signed-off-by: Brett Tofel <[email protected]> * After gci run Signed-off-by: Brett Tofel <[email protected]> --------- Signed-off-by: Brett Tofel <[email protected]> Co-authored-by: Joe Lanford <[email protected]>
1 parent 79f42d5 commit 8ae6ca0

File tree

5 files changed

+98
-7
lines changed

5 files changed

+98
-7
lines changed

docs/api-reference/catalogd-api-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ _Appears in:_
9898
| --- | --- | --- | --- |
9999
| `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.<br /><br />Below is a minimal example of a ClusterCatalogSpec that sources a catalog from an image:<br /><br /> source:<br /> type: Image<br /> image:<br /> ref: quay.io/operatorhubio/catalog:latest<br /><br />For more information on FBC, see https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs | | |
100100
| `priority` _integer_ | priority is an optional field that allows the user to define a priority for a ClusterCatalog.<br />A ClusterCatalog's priority is used by clients as a tie-breaker between ClusterCatalogs that meet the client's requirements.<br />For example, in the case where multiple ClusterCatalogs provide the same bundle.<br />A higher number means higher priority. Negative numbers are also accepted.<br />When omitted, the default priority is 0. | 0 | |
101+
| `availability` _string_ | Availability is an optional field that allows users to define whether the ClusterCatalog is utilized by the operator-controller.<br /><br />Allowed values are : ["Enabled", "Disabled"].<br />If set to "Enabled", the catalog will be used for updates, serving contents, and package installations.<br /><br />If set to "Disabled", catalogd will stop serving the catalog and the cached data will be removed.<br /><br />If unspecified, the default value is "Enabled" | Enabled | Enum: [Disabled Enabled] <br /> |
101102

102103

103104
#### ClusterCatalogStatus

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/onsi/gomega v1.34.2
1818
github.com/opencontainers/go-digest v1.0.0
1919
github.com/operator-framework/api v0.27.0
20-
github.com/operator-framework/catalogd v0.32.0
20+
github.com/operator-framework/catalogd v0.33.0
2121
github.com/operator-framework/helm-operator-plugins v0.5.0
2222
github.com/operator-framework/operator-registry v1.47.0
2323
github.com/spf13/pflag v1.0.5
@@ -179,7 +179,7 @@ require (
179179
github.com/pkg/errors v0.9.1 // indirect
180180
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
181181
github.com/proglottis/gpgme v0.1.3 // indirect
182-
github.com/prometheus/client_golang v1.20.4 // indirect
182+
github.com/prometheus/client_golang v1.20.5 // indirect
183183
github.com/prometheus/client_model v0.6.1 // indirect
184184
github.com/prometheus/common v0.55.0 // indirect
185185
github.com/prometheus/procfs v0.15.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11 h1:eT
535535
github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11/go.mod h1:EmVJt97N+pfWFsli/ipXTBZqSG5F5KGQhm3c3IsGq1o=
536536
github.com/operator-framework/api v0.27.0 h1:OrVaGKZJvbZo58HTv2guz7aURkhVKYhFqZ/6VpifiXI=
537537
github.com/operator-framework/api v0.27.0/go.mod h1:lg2Xx+S8NQWGYlEOvFwQvH46E5EK5IrAIL7HWfAhciM=
538-
github.com/operator-framework/catalogd v0.32.0 h1:VKD+7wfEF6CnJgR4aUYyT85KP2Te7zjhaPvgvWy25Uw=
539-
github.com/operator-framework/catalogd v0.32.0/go.mod h1:FrFSCwRXr4aPslcXIv48dan5AdM37k/B9tK/RpdvZCU=
538+
github.com/operator-framework/catalogd v0.33.0 h1:hnLIFykO1FkjOAUFRPuYRIHQTE0oBF9jkGmWjKhxniQ=
539+
github.com/operator-framework/catalogd v0.33.0/go.mod h1:anZurjcFMBvbkuyqlJ98v9z+yjniPKqmhlyitk9DuBQ=
540540
github.com/operator-framework/helm-operator-plugins v0.5.0 h1:qph2OoECcI9mpuUBtOsWOMgvpx52mPTTSvzVxICsT04=
541541
github.com/operator-framework/helm-operator-plugins v0.5.0/go.mod h1:yVncrZ/FJNqedMil+055fk6sw8aMKRrget/AqGM0ig0=
542542
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
569569
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
570570
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
571571
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
572-
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
573-
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
572+
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
573+
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
574574
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
575575
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
576576
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=

internal/resolve/catalog.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/apimachinery/pkg/labels"
1414
"k8s.io/apimachinery/pkg/util/sets"
1515
"sigs.k8s.io/controller-runtime/pkg/client"
16+
"sigs.k8s.io/controller-runtime/pkg/log"
1617

1718
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
1819
"github.com/operator-framework/operator-registry/alpha/declcfg"
@@ -231,20 +232,37 @@ func isDeprecated(bundle declcfg.Bundle, deprecation *declcfg.Deprecation) bool
231232

232233
type CatalogWalkFunc func(context.Context, *catalogd.ClusterCatalog, *declcfg.DeclarativeConfig, error) error
233234

234-
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 {
235239
return func(ctx context.Context, packageName string, f CatalogWalkFunc, catalogListOpts ...client.ListOption) error {
240+
l := log.FromContext(ctx)
236241
catalogs, err := listCatalogs(ctx, catalogListOpts...)
237242
if err != nil {
238243
return fmt.Errorf("error listing catalogs: %w", err)
239244
}
240245

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+
241255
for i := range catalogs {
242256
cat := &catalogs[i]
257+
258+
// process enabled catalogs
243259
fbc, fbcErr := getPackage(ctx, cat, packageName)
260+
244261
if walkErr := f(ctx, cat, fbc, fbcErr); walkErr != nil {
245262
return walkErr
246263
}
247264
}
265+
248266
return nil
249267
}
250268
}

internal/resolve/catalog_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,75 @@ func TestMultipleChannels(t *testing.T) {
963963
assert.Equal(t, bsemver.MustParse("2.0.0"), *gotVersion)
964964
assert.Equal(t, ptr.To(packageDeprecation(pkgName)), gotDeprecation)
965965
}
966+
967+
func TestAllCatalogsDisabled(t *testing.T) {
968+
pkgName := randPkg()
969+
listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) {
970+
return []catalogd.ClusterCatalog{
971+
{
972+
Spec: catalogd.ClusterCatalogSpec{
973+
Availability: "Disabled",
974+
},
975+
},
976+
{
977+
Spec: catalogd.ClusterCatalogSpec{
978+
Availability: "Disabled",
979+
},
980+
},
981+
}, nil
982+
}
983+
984+
getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) {
985+
panic("getPackage should never be called when all catalogs are disabled")
986+
}
987+
988+
r := CatalogResolver{
989+
WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage),
990+
}
991+
992+
ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
993+
_, _, _, err := r.Resolve(context.Background(), ce, nil)
994+
require.Error(t, err)
995+
assert.Contains(t, err.Error(), "no bundles found for package")
996+
}
997+
998+
func TestSomeCatalogsDisabled(t *testing.T) {
999+
pkgName := randPkg()
1000+
listCatalogs := func(ctx context.Context, options ...client.ListOption) ([]catalogd.ClusterCatalog, error) {
1001+
return []catalogd.ClusterCatalog{
1002+
{
1003+
ObjectMeta: metav1.ObjectMeta{
1004+
Name: "enabledCatalog",
1005+
},
1006+
Spec: catalogd.ClusterCatalogSpec{
1007+
Priority: 1, // Higher priority
1008+
Availability: "Enabled",
1009+
},
1010+
},
1011+
{
1012+
ObjectMeta: metav1.ObjectMeta{
1013+
Name: "disabledCatalog",
1014+
},
1015+
Spec: catalogd.ClusterCatalogSpec{
1016+
Priority: 0, // Lower priority (but disabled)
1017+
Availability: "Disabled",
1018+
},
1019+
},
1020+
}, nil
1021+
}
1022+
1023+
getPackage := func(ctx context.Context, cat *catalogd.ClusterCatalog, packageName string) (*declcfg.DeclarativeConfig, error) {
1024+
// Only enabled catalog should be processed
1025+
return genPackage(pkgName), nil
1026+
}
1027+
1028+
r := CatalogResolver{
1029+
WalkCatalogsFunc: CatalogWalker(listCatalogs, getPackage),
1030+
}
1031+
1032+
ce := buildFooClusterExtension(pkgName, []string{}, ">=1.0.0", ocv1alpha1.UpgradeConstraintPolicyCatalogProvided)
1033+
gotBundle, gotVersion, _, err := r.Resolve(context.Background(), ce, nil)
1034+
require.NoError(t, err)
1035+
require.NotNil(t, gotBundle)
1036+
require.Equal(t, bsemver.MustParse("3.0.0"), *gotVersion)
1037+
}

0 commit comments

Comments
 (0)