Catalog content resolution
When you specify the cluster extension you want to install in a custom resource (CR), Operator Lifecycle Manager (OLM) v1 uses catalog selection to resolve what content is installed.
You can perform the following actions to control the selection of catalog content:
- Specify labels to select the catalog.
- Use match expressions to perform complex filtering across catalogs.
- Set catalog priority.
If you do not specify any catalog selection criteria, Operator Lifecycle Manager (OLM) v1 selects an extension from any available catalog on the cluster that provides the requested package.
During resolution, bundles that are not deprecated are preferred over deprecated bundles by default.
Catalog selection by name
When a catalog is added to a cluster, a label is created by using the value of the metadata.name field of the catalog custom resource (CR). In the CR of an extension, you can specify the catalog name by using the spec.source.catalog.selector.matchLabels field.
The value of the matchLabels field uses the following format:
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
labels:
olm.operatorframework.io/metadata.name: <example_extension>
...The <example_extension> value is the label derived from the metadata.name field and automatically added when the catalog is applied.
The following example resolves the <example_extension>-operator package from a catalog with the openshift-redhat-operators label:
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
spec:
namespace: <example_namespace>
serviceAccount:
name: <example_extension>-installer
source:
sourceType: Catalog
catalog:
packageName: <example_extension>-operator
selector:
matchLabels:
olm.operatorframework.io/metadata.name: openshift-redhat-operatorsCatalog selection by labels or expressions
You can add metadata to a catalog by using labels in the custom resource (CR) of a cluster catalog. You can then filter catalog selection by specifying the assigned labels or using expressions in the CR of the cluster extension.
The following cluster catalog CR adds the example.com/support label with the value of true to the catalog-a cluster catalog:
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: catalog-a
labels:
example.com/support: "true"
spec:
source:
type: Image
image:
ref: quay.io/example/content-management-a:latestThe following cluster extension CR uses the matchLabels selector to select catalogs with the example.com/support label and the value of true:
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
spec:
namespace: <example_namespace>
serviceAccount:
name: <example_extension>-installer
source:
sourceType: Catalog
catalog:
packageName: <example_extension>-operator
selector:
matchLabels:
example.com/support: "true"You can use the matchExpressions field to perform more complex filtering for labels. The following cluster extension CR selects catalogs with the example.com/support label and a value of production or supported:
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
spec:
namespace: <example_namespace>
serviceAccount:
name: <example_extension>-installer
source:
sourceType: Catalog
catalog:
packageName: <example_extension>-operator
selector:
matchExpressions:
- key: example.com/support
operator: In
values:
- "production"
- "supported"If you use both the matchLabels and matchExpressions fields, the selected catalog must satisfy all specified criteria.
Catalog exclusion by labels or expressions
You can exclude catalogs by using match expressions on metadata with the NotIn or DoesNotExist operators.
The following custom resources (CRs) add an example.com/testing label to the unwanted-catalog-1 and unwanted-catalog-2 cluster catalogs:
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: unwanted-catalog-1
labels:
example.com/testing: "true"
spec:
source:
type: Image
image:
ref: quay.io/example/content-management-a:latestapiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: unwanted-catalog-2
labels:
example.com/testing: "true"
spec:
source:
type: Image
image:
ref: quay.io/example/content-management-b:latestThe following cluster extension CR excludes selection from the unwanted-catalog-1 catalog:
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
spec:
namespace: <example_namespace>
serviceAccount:
name: <example_extension>-installer
source:
sourceType: Catalog
catalog:
packageName: <example_extension>-operator
selector:
matchExpressions:
- key: olm.operatorframework.io/metadata.name
operator: NotIn
values:
- unwanted-catalog-1The following cluster extension CR selects from catalogs that do not have the example.com/testing label. As a result, both unwanted-catalog-1 and unwanted-catalog-2 are excluded from catalog selection.
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: <example_extension>
spec:
namespace: <example_namespace>
serviceAccount:
name: <example_extension>-installer
source:
sourceType: Catalog
catalog:
packageName: <example_extension>-operator
selector:
matchExpressions:
- key: example.com/testing
operator: DoesNotExistCatalog selection by priority
When multiple catalogs provide the same package, you can resolve ambiguities by specifying the priority in the custom resource (CR) of each catalog. If unspecified, catalogs have a default priority value of 0. The priority can be any positive or negative 32-bit integer.
- During bundle resolution, catalogs with higher priority values are selected over catalogs with lower priority values.
- Bundles that are not deprecated are prioritized over bundles that are deprecated.
- If multiple bundles exist in catalogs with the same priority and the catalog selection is ambiguous, an error is printed.
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: high-priority-catalog
spec:
priority: 1000
source:
type: Image
image:
ref: quay.io/example/higher-priority-catalog:latestapiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: lower-priority-catalog
spec:
priority: 10
source:
type: Image
image:
ref: quay.io/example/lower-priority-catalog:latestTroubleshooting catalog selection errors
If bundle resolution fails because of ambiguity or because no catalog is selected, an error message is printed in the status.conditions field of the cluster extension.
Perform the following actions to troubleshoot catalog selection errors:
- Refine your selection criteria using labels or expressions.
- Adjust your catalog priorities.
- Ensure that only one bundle matches your package name and version requirements.