4.4. 目录内容解析


当您指定要在自定义资源(CR)中安装的集群扩展时,Operator Lifecycle Manager (OLM) v1 使用目录选择来解析安装的内容。

您可以执行以下操作来控制目录内容的选择:

  • 指定标签以选择目录。
  • 使用匹配表达式在目录之间执行复杂的过滤。
  • 设置目录优先级。

如果没有指定任何目录选择条件,Operator Lifecycle Manager (OLM) v1 从提供所需软件包的集群上任何可用目录选择一个扩展。

在解析过程中,默认情况下没有弃用的捆绑包优先于已弃用的捆绑包。

4.4.1. 按名称选择目录

当目录添加到集群中时,会使用目录自定义资源(CR)的 metadata.name 字段的值来创建标签。在扩展的 CR 中,您可以使用 spec.source.catalog.selector.matchLabels 字段指定目录名称。matchLabels 字段的值使用以下格式:

metadata.name 字段派生的标签示例

apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
  name: <example_extension>
  labels:
    olm.operatorframework.io/metadata.name: <example_extension> 
1

...
Copy to Clipboard Toggle word wrap

1
metadata.name 字段派生的标签,并在应用目录时自动添加。

以下示例从具有 openshift-redhat-operators 标签的目录解析 <example_extension>-operator 软件包:

扩展 CR 示例

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-operators
Copy to Clipboard Toggle word wrap

4.4.2. 根据标签或表达式选择目录

您可以使用集群目录的自定义资源(CR)中的标签将元数据添加到目录中。然后,您可以通过指定分配的标签或使用集群扩展 CR 中的表达式来过滤目录选择。

以下集群目录 CR 将值为 trueexample.com/support 标签添加到 catalog-a 集群目录中:

带有标签的集群目录 CR 示例

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:latest
Copy to Clipboard Toggle word wrap

以下集群扩展 CR 使用 matchLabels 选择器来选择带有 example.com/support 标签的目录,值为 true

使用 matchLabels 选择器的集群扩展 CR 示例

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"
Copy to Clipboard Toggle word wrap

您可以使用 matchExpressions 字段为标签执行更复杂的过滤。以下集群扩展 CR 选择带有 example.com/support 标签的目录,以及 productionsupported 的值:

带有 matchExpression 选择器的集群扩展 CR 示例

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"
Copy to Clipboard Toggle word wrap

注意

如果同时使用 matchLabelsmatchExpressions 字段,则所选目录必须满足所有指定标准。

4.4.3. 按标签或表达式进行目录排除

您可以在带有 NotInDoesNotExist 操作的元数据上使用 match 表达式来排除目录。

以下 CR 将 example.com/testing 标签添加到 unwanted-catalog-1unwanted-catalog-2 集群目录中:

集群池 CR 示例

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:latest
Copy to Clipboard Toggle word wrap

集群池 CR 示例

apiVersion: 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:latest
Copy to Clipboard Toggle word wrap

以下集群扩展 CR 从 unwanted-catalog-1 目录中排除选择:

排除一个特定目录的集群扩展 CR 示例

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-1
Copy to Clipboard Toggle word wrap

以下集群扩展 CR 从没有 example.com/testing 标签的目录中进行选择。因此,unwanted-catalog-1unwanted-catalog-2 都将重目录选择中排除。

使用特定标签排除目录的集群扩展 CR 示例

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: DoesNotExist
Copy to Clipboard Toggle word wrap

4.4.4. 根据优先级选择目录

当多个目录提供相同的软件包时,您可以通过在每个目录的自定义资源(CR)中指定优先级来解决不确定性。如果未指定,则目录的默认优先级值为 0。优先级可以是任意正或负 32 位整数。

注意
  • 在捆绑包解析过程中,将选择具有更高优先级值的目录,而不是优先级较低的目录。
  • 未弃用的捆绑包优先于已弃用的捆绑包。
  • 如果目录中存在多个具有相同优先级的捆绑包,并且目录选择是模糊的,则会打印错误。

具有较高优先级的集群目录 CR 示例

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:latest
Copy to Clipboard Toggle word wrap

具有较低优先级的集群目录 CR 示例

apiVersion: 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:latest
Copy to Clipboard Toggle word wrap

4.4.5. 目录选择错误故障排除

如果因为模糊或未选择目录而导致捆绑包解析失败,则会在集群扩展的 status.conditions 字段中输出错误消息。

执行以下操作排除目录选择错误:

  • 使用标签或表达式重新定义您的选择标准。
  • 调整目录优先级。
  • 确保只有一个捆绑包与您的软件包名称和版本要求匹配。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat