搜索

7.3. 从 OLM 1.0 中的目录安装 Operator (技术预览)

download PDF

集群管理员可向其集群添加 目录、或策展 Operator 和 Kubernetes 扩展集合。Operator 作者将其产品发布到这些目录中。当您向集群添加目录时,您可以访问发布到目录中的 Operator 和扩展的版本、补丁和无线更新。

在 Operator Lifecycle Manager (OLM) 1.0 的当前技术预览版本中,您可以使用自定义资源(CR)从 CLI 以声明性方式管理目录和 Operator。

重要

OLM 1.0 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

7.3.1. 先决条件

  • 使用具有 cluster-admin 权限的账户访问 OpenShift Container Platform 集群

    注意

    对于 OpenShift Container Platform 4.15,适用于 OLM 1.0 的流程都是基于 CLI 的。另外,管理员也可以使用普通方法(如 Import YAMLSearch 页面)在 web 控制台中创建和查看相关对象。但是,现有的 OperatorHubInstalled Operators 页面还不会显示 OLM 1.0 组件。

  • 在集群中启用 TechPreviewNoUpgrade 功能集

    警告

    启用 TechPreviewNoUpgrade 功能集将无法撤消,并防止次版本更新。不建议在生产环境集群中使用这些功能集。

  • 在您的工作站上安装的 OpenShift CLI (oc)

7.3.2. 关于 OLM 1.0 中的目录

您可以使用 catalogd 组件查询 Kubernetes 扩展的目录,如 Operator 和控制器,从而发现可安装的内容。Catalogd 是一个 Kubernetes 扩展,为集群客户端解包目录内容,并是微服务的 Operator Lifecycle Manager (OLM) 1.0 套件的一部分。目前,catalogd 解包要打包并分发为容器镜像的目录内容。

重要

如果您尝试安装没有唯一名称的 Operator 或扩展,则安装可能会失败,或者导致无法预计的结果。这是因为以下原因:

  • 如果在集群中安装了 mulitple 目录,OLM 1.0 不包括在安装 Operator 或扩展时指定目录的机制。
  • Operator Lifecycle Manager (OLM) 1.0 中的依赖项解析需要集群中用于安装的所有 Operator 和扩展都使用其捆绑包和软件包的唯一名称。

其他资源

7.3.3. OLM 1.0 中红帽提供的 Operator 目录

Operator Lifecycle Manager (OLM) 1.0 默认不包括红帽提供的 Operator 目录。如果要在集群中添加红帽提供的目录,请为目录创建一个自定义资源 (CR),并将其应用到集群。以下自定义资源 (CR) 示例演示了如何为 OLM 1.0 创建目录资源。

重要

如果要使用托管在安全 registry 上的目录,如来自 registry.redhat.io 的红帽提供的 Operator 目录,则必须有一个范围到 openshift-catalogd 命名空间的 pull secret。如需更多信息,请参阅"为在安全 registry 上托管的目录创建 pull secret"。

Red Hat Operator 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: redhat-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/redhat-operator-index:v4.15
      pullSecret: <pull_secret_name>
      pollInterval: <poll_interval_duration> 1

1
指定轮询远程 registry 以获取较新的镜像摘要的时间间隔。默认值为 24h。有效单位包括秒 (s)、分钟 (m) 和小时 (h)。要禁用轮询,请设置零值,如 0s

认证的 Operator 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: certified-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/certified-operator-index:v4.15
      pullSecret: <pull_secret_name>
      pollInterval: 24h

Community Operators 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: community-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/community-operator-index:v4.15
      pullSecret: <pull_secret_name>
      pollInterval: 24h

以下命令在集群中添加目录:

命令语法

$ oc apply -f <catalog_name>.yaml 1

1
指定目录 CR,如 redhat-operators.yaml

7.3.4. 为托管在安全 registry 上的目录创建 pull secret

如果要使用托管在安全 registry 上的目录,如来自 registry.redhat.io 的红帽提供的 Operator 目录,则必须有一个范围到 openshift-catalogd 命名空间的 pull secret。

注意

目前,catalogd 无法从 OpenShift Container Platform 集群中读取全局 pull secret。Catalogd 只能读取对部署它的命名空间中的 secret 的引用。

先决条件

  • 安全 registry 的登录凭证
  • 工作站上安装的 Docker 或 Podman

流程

  • 如果您已经有一个带有安全 registry 的登录凭证的 .dockercfg 文件,请运行以下命令创建一个 pull secret:

    $ oc create secret generic <pull_secret_name> \
        --from-file=.dockercfg=<file_path>/.dockercfg \
        --type=kubernetes.io/dockercfg \
        --namespace=openshift-catalogd

    例 7.1. 示例命令

    $ oc create secret generic redhat-cred \
        --from-file=.dockercfg=/home/<username>/.dockercfg \
        --type=kubernetes.io/dockercfg \
        --namespace=openshift-catalogd
  • 如果您已经有一个带有安全 registry 的登录凭证的 $HOME/.docker/config.json 文件,请运行以下命令创建一个 pull secret:

    $ oc create secret generic <pull_secret_name> \
        --from-file=.dockerconfigjson=<file_path>/.docker/config.json \
        --type=kubernetes.io/dockerconfigjson \
        --namespace=openshift-catalogd

    例 7.2. 示例命令

    $ oc create secret generic redhat-cred \
        --from-file=.dockerconfigjson=/home/<username>/.docker/config.json \
        --type=kubernetes.io/dockerconfigjson \
        --namespace=openshift-catalogd
  • 如果您没有安全 registry 的登录凭证的 Docker 配置文件,请运行以下命令来创建 pull secret:

    $ oc create secret docker-registry <pull_secret_name> \
        --docker-server=<registry_server> \
        --docker-username=<username> \
        --docker-password=<password> \
        --docker-email=<email> \
        --namespace=openshift-catalogd

    例 7.3. 示例命令

    $ oc create secret docker-registry redhat-cred \
        --docker-server=registry.redhat.io \
        --docker-username=username \
        --docker-password=password \
        --docker-email=user@example.com \
        --namespace=openshift-catalogd

7.3.5. 在集群中添加目录

要在集群中添加目录,请创建一个目录自定义资源(CR)并将其应用到集群。

先决条件

  • 如果要使用托管在安全 registry 上的目录,如来自 registry.redhat.io 的红帽提供的 Operator 目录,则必须有一个范围到 openshift-catalogd 命名空间的 pull secret。如需更多信息,请参阅"为在安全 registry 上托管的目录创建 pull secret"。

流程

  1. 创建目录自定义资源(CR),如下例所示:

    redhat-operators.yaml 示例

    apiVersion: catalogd.operatorframework.io/v1alpha1
    kind: Catalog
    metadata:
      name: redhat-operators
    spec:
      source:
        type: image
        image:
          ref: registry.redhat.io/redhat/redhat-operator-index:v4.15 1
          pullSecret: <pull_secret_name> 2
          pollInterval: <poll_interval_duration> 3

    1
    spec.source.image 字段中指定目录的镜像。
    2
    如果您的目录托管在安全 registry 上,如 registry.redhat.io,您必须创建一个范围到 openshift-catalog 命名空间的 pull secret。
    3
    指定轮询远程 registry 以获取较新的镜像摘要的时间间隔。默认值为 24h。有效单位包括秒 (s)、分钟 (m) 和小时 (h)。要禁用轮询,请设置零值,如 0s
  2. 运行以下命令在集群中添加目录:

    $ oc apply -f redhat-operators.yaml

    输出示例

    catalog.catalogd.operatorframework.io/redhat-operators created

验证

  • 运行以下命令以验证目录的状态:

    1. 运行以下命令检查目录是否可用:

      $ oc get catalog

      输出示例

      NAME                  AGE
      redhat-operators      20s

    2. 运行以下命令,检查目录的状态:

      $ oc describe catalog

      输出示例

      Name:         redhat-operators
      Namespace:
      Labels:       <none>
      Annotations:  <none>
      API Version:  catalogd.operatorframework.io/v1alpha1
      Kind:         Catalog
      Metadata:
        Creation Timestamp:  2024-01-10T16:18:38Z
        Finalizers:
          catalogd.operatorframework.io/delete-server-cache
        Generation:        1
        Resource Version:  57057
        UID:               128db204-49b3-45ee-bfea-a2e6fc8e34ea
      Spec:
        Source:
          Image:
            Pull Secret:  redhat-cred
            Ref:          registry.redhat.io/redhat/redhat-operator-index:v4.15
          Type:           image
      Status: 1
        Conditions:
          Last Transition Time:  2024-01-10T16:18:55Z
          Message:
          Reason:                UnpackSuccessful 2
          Status:                True
          Type:                  Unpacked
        Content URL:             http://catalogd-catalogserver.openshift-catalogd.svc/catalogs/redhat-operators/all.json
        Observed Generation:     1
        Phase:                   Unpacked 3
        Resolved Source:
          Image:
            Last Poll Attempt:  2024-01-10T16:18:51Z
            Ref:                registry.redhat.io/redhat/redhat-operator-index:v4.15
            Resolved Ref:       registry.redhat.io/redhat/redhat-operator-index@sha256:7b536ae19b8e9f74bb521c4a61e5818e036ac1865a932f2157c6c9a766b2eea5 4
          Type:                 image
      Events:                   <none>

      1
      描述目录的状态。
      2
      显示目录处于当前状态的原因。
      3
      显示安装过程的阶段。
      4
      显示目录的镜像引用。

7.3.6. 从目录查找 Operator

在集群中添加目录后,您可以查询目录以查找要安装的 Operator 和扩展。在查询目录前,您必须端口转发目录服务器服务。

前提条件

  • 您已在集群中添加目录。
  • 已安装 jq CLI 工具。

流程

  1. 运行以下命令,在 openshift-catalogd 命名空间中转发目录服务器服务:

    $ oc -n openshift-catalogd port-forward svc/catalogd-catalogserver 8080:80
  2. 运行以下命令,在本地下载目录的 JSON 文件:

    $ curl -L http://localhost:8080/catalogs/<catalog_name>/all.json \
      -C - -o /<path>/<catalog_name>.json

    例 7.4. 示例命令

    $ curl -L http://localhost:8080/catalogs/redhat-operators/all.json \
      -C - -o /home/username/catalogs/rhoc.json
  3. 运行以下命令之一返回目录中的 Operator 和扩展列表。

    重要

    目前,Operator Lifecycle Manager (OLM) 1.0 支持不使用 Webhook 的扩展,并配置为使用 AllNamespaces 安装模式。使用 webhook 或针对单个或指定命名空间集的扩展无法安装。

    • 运行以下命令,从本地目录文件获取 Operator 和扩展列表:

      $ jq -s '.[] | select(.schema == "olm.package") | .name' \
        /<path>/<filename>.json

      例 7.5. 示例命令

      $ jq -s '.[] | select(.schema == "olm.package") | .name' \
        /home/username/catalogs/rhoc.json

      例 7.6. 输出示例

      NAME                                                        AGE
      "3scale-operator"
      "advanced-cluster-management"
      "amq-broker-rhel8"
      "amq-online"
      "amq-streams"
      "amq7-interconnect-operator"
      "ansible-automation-platform-operator"
      "ansible-cloud-addons-operator"
      "apicast-operator"
      "aws-efs-csi-driver-operator"
      "aws-load-balancer-operator"
      "bamoe-businessautomation-operator"
      "bamoe-kogito-operator"
      "bare-metal-event-relay"
      "businessautomation-operator"
      ...
    • 运行以下命令,获取支持 AllNamespaces 安装模式的软件包列表,且不从本地目录文件中使用 webhook:

      $ jq -c 'select(.schema == "olm.bundle") | \
        {"package":.package, "version":.properties[] | \
        select(.type == "olm.bundle.object").value.data | @base64d | fromjson | \
        select(.kind == "ClusterServiceVersion" and (.spec.installModes[] | \
        select(.type == "AllNamespaces" and .supported == true) != null) \
        and .spec.webhookdefinitions == null).spec.version}' \
        /<path>/<catalog_name>.json

      例 7.7. 输出示例

      {"package":"3scale-operator","version":"0.10.0-mas"}
      {"package":"3scale-operator","version":"0.10.5"}
      {"package":"3scale-operator","version":"0.11.0-mas"}
      {"package":"3scale-operator","version":"0.11.1-mas"}
      {"package":"3scale-operator","version":"0.11.2-mas"}
      {"package":"3scale-operator","version":"0.11.3-mas"}
      {"package":"3scale-operator","version":"0.11.5-mas"}
      {"package":"3scale-operator","version":"0.11.6-mas"}
      {"package":"3scale-operator","version":"0.11.7-mas"}
      {"package":"3scale-operator","version":"0.11.8-mas"}
      {"package":"amq-broker-rhel8","version":"7.10.0-opr-1"}
      {"package":"amq-broker-rhel8","version":"7.10.0-opr-2"}
      {"package":"amq-broker-rhel8","version":"7.10.0-opr-3"}
      {"package":"amq-broker-rhel8","version":"7.10.0-opr-4"}
      {"package":"amq-broker-rhel8","version":"7.10.1-opr-1"}
      {"package":"amq-broker-rhel8","version":"7.10.1-opr-2"}
      {"package":"amq-broker-rhel8","version":"7.10.2-opr-1"}
      {"package":"amq-broker-rhel8","version":"7.10.2-opr-2"}
      ...
  4. 运行以下命令,检查 Operator 或扩展的元数据的内容:

    $ jq -s '.[] | select( .schema == "olm.package") | \
      select( .name == "<package_name>")' /<path>/<catalog_name>.json

    例 7.8. 示例命令

    $ jq -s '.[] | select( .schema == "olm.package") | \
      select( .name == "openshift-pipelines-operator-rh")' \
      /home/username/rhoc.json

    例 7.9. 输出示例

    {
      "defaultChannel": "stable",
      "icon": {
        "base64data": "PHN2ZyB4bWxu..."
        "mediatype": "image/png"
      },
      "name": "openshift-pipelines-operator-rh",
      "schema": "olm.package"
    }

7.3.6.1. 常见目录查询

您可以使用 jq CLI 工具查询目录。

表 7.1. 常见软件包查询
查询Request(请求)

目录中的可用软件包

$ jq -s '.[] | select( .schema == "olm.package") | \
  .name' <catalog_name>.json

支持 AllNamespaces 安装模式且不使用 Webhook 的软件包

$ jq -c 'select(.schema == "olm.bundle") | \
  {"package":.package, "version":.properties[] | \
  select(.type == "olm.bundle.object").value.data | \
  @base64d | fromjson | \
  select(.kind == "ClusterServiceVersion" and (.spec.installModes[] | \
  select(.type == "AllNamespaces" and .supported == true) != null) \
  and .spec.webhookdefinitions == null).spec.version}' \
  <catalog_name>.json

软件包元数据

$ jq -s '.[] | select( .schema == "olm.package") | \
  select( .name == "<package_name>")' <catalog_name>.json

软件包中的目录 Blob

$ jq -s '.[] | select( .package == "<package_name>")' \
  <catalog_name>.json
表 7.2. 常见频道查询
查询Request(请求)

软件包中的频道

$ jq -s '.[] | select( .schema == "olm.channel" ) | \
  select( .package == "<package_name>") | .name' \
  <catalog_name>.json

频道中的版本

$ jq -s '.[] | select( .package == "<package_name>" ) | \
  select( .schema == "olm.channel" ) | \
  select( .name == "<channel_name>" ) | \
  .entries | .[] | .name' <catalog_name>.json
  • 频道中的最新版本
  • 升级路径
$ jq -s '.[] | select( .schema == "olm.channel" ) | \
  select ( .name == "<channel>") | \
  select( .package == "<package_name>")' \
  <catalog_name>.json
表 7.3. 常见捆绑包查询
查询Request(请求)

软件包中的捆绑包

$ jq -s '.[] | select( .schema == "olm.bundle" ) | \
  select( .package == "<package_name>") | .name' \
  <catalog_name>.json
  • 捆绑包依赖项
  • 可用的 API
$ jq -s '.[] | select( .schema == "olm.bundle" ) | \
  select ( .name == "<bundle_name>") | \
  select( .package == "<package_name>")' \
  <catalog_name>.json

7.3.7. 从目录安装 Operator

Operator Lifecycle Manager (OLM) 1.0 支持将 Operator 和扩展范围安装到集群中。您可以通过创建自定义资源(CR)并将其应用到集群来从目录中安装 Operator 或扩展。

重要

目前,OLM 1.0 支持符合以下条件的安装 Operator 和扩展:

  • Operator 或扩展必须使用 AllNamespaces 安装模式。
  • Operator 或扩展不能使用 Webhook。

使用 Webhook 或指定命名空间集的 Operator 和扩展无法安装。

前提条件

  • 您已在集群中添加目录。
  • 您已下载了目录文件的本地副本。
  • 已安装 jq CLI 工具。

流程

  1. 通过完成以下步骤,检查目录文件本地副本中的频道和版本信息:

    1. 运行以下命令,从所选软件包中获取频道列表:

      $ jq -s '.[] | select( .schema == "olm.channel" ) | \
        select( .package == "<package_name>") | \
        .name' /<path>/<catalog_name>.json

      例 7.10. 示例命令

      $ jq -s '.[] | select( .schema == "olm.channel" ) | \
        select( .package == "openshift-pipelines-operator-rh") | \
        .name' /home/username/rhoc.json

      例 7.11. 输出示例

      "latest"
      "pipelines-1.11"
      "pipelines-1.12"
      "pipelines-1.13"
    2. 运行以下命令,获取频道中发布的版本列表:

      $ jq -s '.[] | select( .package == "<package_name>" ) | \
        select( .schema == "olm.channel" ) | \
        select( .name == "<channel_name>" ) | .entries | \
        .[] | .name' /<path>/<catalog_name>.json

      例 7.12. 示例命令

      $ jq -s '.[] | select( .package == "openshift-pipelines-operator-rh" ) | \
      select( .schema == "olm.channel" ) | select( .name == "latest" ) | \
      .entries | .[] | .name' /home/username/rhoc.json

      例 7.13. 输出示例

      "openshift-pipelines-operator-rh.v1.11.1"
      "openshift-pipelines-operator-rh.v1.12.0"
      "openshift-pipelines-operator-rh.v1.12.1"
      "openshift-pipelines-operator-rh.v1.12.2"
      "openshift-pipelines-operator-rh.v1.13.0"
      "openshift-pipelines-operator-rh.v1.13.1"
  2. 创建一个类似以下示例的 CR:

    pipelines-operator.yaml CR 示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      name: pipelines-operator
    spec:
      packageName: openshift-pipelines-operator-rh
      channel: <channel>
      version: "<version>"

    其中:

    <channel>
    可选:为您要安装或更新的软件包指定频道,如 pipelines-1.11latest
    <version>

    可选:指定您要安装或更新的软件包的版本或版本范围,如 1.11.11.12.x>=1.12.1。如需更多信息,请参阅"示例自定义资源(CR)指定目标版本"和"支持版本范围"。

    重要

    如果您尝试安装没有唯一名称的 Operator 或扩展,则安装可能会失败,或者导致无法预计的结果。这是因为以下原因:

    • 如果在集群中安装了 mulitple 目录,OLM 1.0 不包括在安装 Operator 或扩展时指定目录的机制。
    • Operator Lifecycle Manager (OLM) 1.0 中的依赖项解析需要集群中用于安装的所有 Operator 和扩展都使用其捆绑包和软件包的唯一名称。
  3. 运行以下命令,将 CR 应用到集群:

    $ oc apply -f pipeline-operator.yaml

    输出示例

    operator.operators.operatorframework.io/pipelines-operator created

验证

  1. 运行以下命令,以 YAML 格式查看 Operator 或扩展 CR:

    $ oc get operator.operators.operatorframework.io pipelines-operator -o yaml
    注意

    如果您在 Operator 或扩展的 CR 中指定频道或定义版本范围,OLM 1.0 不会显示集群中安装的解析版本。仅会显示 CR 中指定的版本和频道信息。

    如果要查找安装的特定版本,您必须将 spec.source.image.ref 字段镜像的 SHA 与目录中的镜像引用进行比较。

    例 7.14. 输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"pipelines-operator"},"spec":{"channel":"latest","packageName":"openshift-pipelines-operator-rh","version":"1.11.x"}}
      creationTimestamp: "2024-01-30T20:06:09Z"
      generation: 1
      name: pipelines-operator
      resourceVersion: "44362"
      uid: 4272d228-22e1-419e-b9a7-986f982ee588
    spec:
      channel: latest
      packageName: openshift-pipelines-operator-rh
      upgradeConstraintPolicy: Enforce
      version: 1.11.x
    status:
      conditions:
      - lastTransitionTime: "2024-01-30T20:06:15Z"
        message: resolved to "registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280"
        observedGeneration: 1
        reason: Success
        status: "True"
        type: Resolved
      - lastTransitionTime: "2024-01-30T20:06:31Z"
        message: installed from "registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280"
        observedGeneration: 1
        reason: Success
        status: "True"
        type: Installed
      installedBundleResource: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280
      resolvedBundleResource: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280
  2. 运行以下命令,获取有关捆绑包部署的信息:

    $ oc get bundleDeployment pipelines-operator -o yaml

    例 7.15. 输出示例

    apiVersion: core.rukpak.io/v1alpha1
    kind: BundleDeployment
    metadata:
      creationTimestamp: "2024-01-30T20:06:15Z"
      generation: 2
      name: pipelines-operator
      ownerReferences:
      - apiVersion: operators.operatorframework.io/v1alpha1
        blockOwnerDeletion: true
        controller: true
        kind: Operator
        name: pipelines-operator
        uid: 4272d228-22e1-419e-b9a7-986f982ee588
      resourceVersion: "44464"
      uid: 0a0c3525-27e2-4c93-bf57-55920a7707c0
    spec:
      provisionerClassName: core-rukpak-io-plain
      template:
        metadata: {}
        spec:
          provisionerClassName: core-rukpak-io-registry
          source:
            image:
              ref: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280
            type: image
    status:
      activeBundle: pipelines-operator-29x720cjzx8yiowf13a3j75fil2zs3mfw
      conditions:
      - lastTransitionTime: "2024-01-30T20:06:15Z"
        message: Successfully unpacked the pipelines-operator-29x720cjzx8yiowf13a3j75fil2zs3mfw
          Bundle
        reason: UnpackSuccessful
        status: "True"
        type: HasValidBundle
      - lastTransitionTime: "2024-01-30T20:06:28Z"
        message: Instantiated bundle pipelines-operator-29x720cjzx8yiowf13a3j75fil2zs3mfw
          successfully
        reason: InstallationSucceeded
        status: "True"
        type: Installed
      - lastTransitionTime: "2024-01-30T20:06:40Z"
        message: BundleDeployment is healthy
        reason: Healthy
        status: "True"
        type: Healthy
      observedGeneration: 2

7.3.8. 更新 Operator

您可以通过手动编辑自定义资源(CR)并应用更改来更新 Operator 或扩展。

先决条件

  • 已安装目录。
  • 您已下载了目录文件的本地副本。
  • 已安装 Operator 或扩展。
  • 已安装 jq CLI 工具。

流程

  1. 通过完成以下步骤,检查目录文件本地副本中的频道和版本信息:

    1. 运行以下命令,从所选软件包中获取频道列表:

      $ jq -s '.[] | select( .schema == "olm.channel" ) | \
        select( .package == "<package_name>") | \
        .name' /<path>/<catalog_name>.json

      例 7.16. 示例命令

      $ jq -s '.[] | select( .schema == "olm.channel" ) | \
        select( .package == "openshift-pipelines-operator-rh") | \
        .name' /home/username/rhoc.json

      例 7.17. 输出示例

      "latest"
      "pipelines-1.11"
      "pipelines-1.12"
      "pipelines-1.13"
    2. 运行以下命令,获取频道中发布的版本列表:

      $ jq -s '.[] | select( .package == "<package_name>" ) | \
        select( .schema == "olm.channel" ) | \
        select( .name == "<channel_name>" ) | .entries | \
        .[] | .name' /<path>/<catalog_name>.json

      例 7.18. 示例命令

      $ jq -s '.[] | select( .package == "openshift-pipelines-operator-rh" ) | \
      select( .schema == "olm.channel" ) | select( .name == "latest" ) | \
      .entries | .[] | .name' /home/username/rhoc.json

      例 7.19. 输出示例

      "openshift-pipelines-operator-rh.v1.11.1"
      "openshift-pipelines-operator-rh.v1.12.0"
      "openshift-pipelines-operator-rh.v1.12.1"
      "openshift-pipelines-operator-rh.v1.12.2"
      "openshift-pipelines-operator-rh.v1.13.0"
      "openshift-pipelines-operator-rh.v1.13.1"
  2. 运行以下命令,查找在 Operator 或扩展 CR 中指定哪个版本或频道:

    $ oc get operator.operators.operatorframework.io <operator_name> -o yaml

    示例命令

    $ oc get operator.operators.operatorframework.io pipelines-operator -o yaml

    例 7.20. 输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |  {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"pipelines-operator"},"spec":{"channel":"latest","packageName":"openshift-pipelines-operator-rh","version":"1.11.1"}}
      creationTimestamp: "2024-02-06T17:47:15Z"
      generation: 2
      name: pipelines-operator
      resourceVersion: "84528"
      uid: dffe2c89-b9c4-427e-b694-ada0b37fc0a9
    spec:
      channel: latest 1
      packageName: openshift-pipelines-operator-rh
      upgradeConstraintPolicy: Enforce
      version: 1.11.1 2
    status:
      conditions:
      - lastTransitionTime: "2024-02-06T17:47:21Z"
        message: bundledeployment status is unknown
        observedGeneration: 2
        reason: InstallationStatusUnknown
        status: Unknown
        type: Installed
      - lastTransitionTime: "2024-02-06T17:50:58Z"
        message: resolved to "registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280"
        observedGeneration: 2
        reason: Success
        status: "True"
        type: Resolved
      resolvedBundleResource: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:e09d37bb1e754db42324fd18c1cb3e7ce77e7b7fcbf4932d0535391579938280
    1
    指定 Operator 或扩展的频道。
    2
    指定 Operator 或扩展名的版本或版本范围。
    注意

    如果您在 Operator 或扩展的 CR 中指定频道或定义版本范围,OLM 1.0 不会显示集群中安装的解析版本。仅会显示 CR 中指定的版本和频道信息。

    如果要查找安装的特定版本,您必须将 spec.source.image.ref 字段镜像的 SHA 与目录中的镜像引用进行比较。

  3. 使用以下方法之一编辑 CR:

    • 如果要将 Operator 或扩展固定到特定版本,如 1.12.1,请编辑类似以下示例的 CR:

      pipelines-operator.yaml CR 示例

      apiVersion: operators.operatorframework.io/v1alpha1
      kind: Operator
      metadata:
        name: pipelines-operator
      spec:
        packageName: openshift-pipelines-operator-rh
        version: 1.12.1 1

      1
      将版本从 1.11.1 更新至 1.12.1
    • 如果要定义可接受的更新版本范围,请编辑类似以下示例的 CR:

      指定了版本范围的 CR 示例

      apiVersion: operators.operatorframework.io/v1alpha1
      kind: Operator
      metadata:
        name: pipelines-operator
      spec:
        packageName: openshift-pipelines-operator-rh
        version: ">1.11.1, <1.13" 1

      1
      指定所需的版本范围大于 1.11.1 版本,且小于 1.13。如需更多信息,请参阅"支持版本范围"和"Version 比较字符串"。
    • 如果要更新到可以从频道解析的最新版本,请编辑类似以下示例的 CR:

      带有指定频道的 CR 示例

      apiVersion: operators.operatorframework.io/v1alpha1
      kind: Operator
      metadata:
        name: pipelines-operator
      spec:
        packageName: openshift-pipelines-operator-rh
        channel: pipelines-1.13 1

      1
      安装可从指定频道解析的最新版本。对频道的更新会自动安装。
    • 如果要指定频道和版本范围,请编辑类似以下示例的 CR:

      带有指定频道和版本范围的 CR 示例

      apiVersion: operators.operatorframework.io/v1alpha1
      kind: Operator
      metadata:
        name: pipelines-operator
      spec:
        packageName: openshift-pipelines-operator-rh
        channel: latest
        version: "<1.13"

      如需更多信息,请参阅"指定目标版本的示例自定义资源(CR) "。

  4. 运行以下命令,将更新应用到集群:

    $ oc apply -f pipelines-operator.yaml

    输出示例

    operator.operators.operatorframework.io/pipelines-operator configured

    提示

    您可以运行以下命令来通过 CLI 对 CR 进行补丁并应用更改:

    $ oc patch operator.operators.operatorframework.io/pipelines-operator -p \
      '{"spec":{"version":"1.12.1"}}' \
      --type=merge

    输出示例

    operator.operators.operatorframework.io/pipelines-operator patched

验证

  • 运行以下命令验证频道和版本更新是否已应用:

    $ oc get operator.operators.operatorframework.io pipelines-operator -o yaml

    例 7.21. 输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"pipelines-operator"},"spec":{"channel":"latest","packageName":"openshift-pipelines-operator-rh","version":"1.12.1"}}
      creationTimestamp: "2024-02-06T19:16:12Z"
      generation: 4
      name: pipelines-operator
      resourceVersion: "58122"
      uid: 886bbf73-604f-4484-9f87-af6ce0f86914
    spec:
      channel: latest
      packageName: openshift-pipelines-operator-rh
      upgradeConstraintPolicy: Enforce
      version: 1.12.1 1
    status:
      conditions:
      - lastTransitionTime: "2024-02-06T19:30:57Z"
        message: installed from "registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:2f1b8ef0fd741d1d686489475423dabc07c55633a4dfebc45e1d533183179f6a"
        observedGeneration: 3
        reason: Success
        status: "True"
        type: Installed
      - lastTransitionTime: "2024-02-06T19:30:57Z"
        message: resolved to "registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:2f1b8ef0fd741d1d686489475423dabc07c55633a4dfebc45e1d533183179f6a"
        observedGeneration: 3
        reason: Success
        status: "True"
        type: Resolved
      installedBundleResource: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:2f1b8ef0fd741d1d686489475423dabc07c55633a4dfebc45e1d533183179f6a
      resolvedBundleResource: registry.redhat.io/openshift-pipelines/pipelines-operator-bundle@sha256:2f1b8ef0fd741d1d686489475423dabc07c55633a4dfebc45e1d533183179f6a
    1
    验证版本是否已更新至 1.12.1

故障排除

  • 如果指定了不存在的目标版本或频道,您可以运行以下命令来检查 Operator 或扩展的状态:

    $ oc get operator.operators.operatorframework.io <operator_name> -o yaml

    例 7.22. 输出示例

    oc get operator.operators.operatorframework.io pipelines-operator -o yaml
    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"pipelines-operator"},"spec":{"channel":"latest","packageName":"openshift-pipelines-operator-rh","version":"2.0.0"}}
      creationTimestamp: "2024-02-06T17:47:15Z"
      generation: 1
      name: pipelines-operator
      resourceVersion: "82667"
      uid: dffe2c89-b9c4-427e-b694-ada0b37fc0a9
    spec:
      channel: latest
      packageName: openshift-pipelines-operator-rh
      upgradeConstraintPolicy: Enforce
      version: 2.0.0
    status:
      conditions:
      - lastTransitionTime: "2024-02-06T17:47:21Z"
        message: installation has not been attempted due to failure to gather data for
          resolution
        observedGeneration: 1
        reason: InstallationStatusUnknown
        status: Unknown
        type: Installed
      - lastTransitionTime: "2024-02-06T17:47:21Z"
        message: no package "openshift-pipelines-operator-rh" matching version "2.0.0"
          found in channel "latest"
        observedGeneration: 1
        reason: ResolutionFailed
        status: "False"
        type: Resolved

7.3.8.1. 支持语义版本

在 OLM 1.0 中默认启用 语义版本(semver)。Operator 扩展作者可以使用 semver 标准来定义兼容的更新。

Operator Lifecycle Manager (OLM) 1.0 可以使用 Operator 或扩展版本号来确定更新是否可以成功解决。

集群管理员可以定义一系列可接受的版本来安装和自动管理更新。对于遵循 semver 标准的 Operator 和扩展,您可以使用比较字符串来定义指定所需的版本范围。

注意

OLM 1.0 不支持对下一个主要版本的自动更新。如果要执行主版本更新,则必须手动验证并应用更新。如需更多信息,请参阅"设置更新或回滚"。

7.3.8.1.1. 主发行版本零发行版本

semver 标准指定为初始开发保留主要版本为零版本 (O.y.z)。在初始开发阶段,API 不稳定,并可能会在任何发布的版本中引入破坏更改。因此,主发行版本为零版本会应用一组特殊的更新条件。

更新主版本零发行版本的条件

  • 当主版本和次版本都为零时,您无法应用自动更新,如 0.0.*。例如,不允许版本范围为 >=0.0.1 <0.1.0 的自动更新。
  • 您不能在一个主版本的零版本中应用从一个次版本到另外一个次版本的自动更新。例如,OLM 1.0 不会自动应用从 0.1.00.2.0 的更新。
  • 您可以从补丁版本应用自动更新,如 >=0.1.0 <0.2.0>=0.2.0 <0.3.0

当 OLM 1.0 阻止自动更新时,您必须通过编辑 Operator 或扩展的自定义资源(CR)来手动验证并强制更新。

其他资源

7.3.8.2. 支持版本范围

在 Operator Lifecycle Manager (OLM) 1.0 中,您可以使用 Operator 或扩展的自定义资源(CR)中的比较字符串来指定版本范围。如果您在 CR 中指定版本范围,OLM 1.0 会安装或升级到可以在版本范围内解析的 Operator 的最新版本。

解析的版本工作流

  • 解析的版本是 Operator 的最新版本,满足 Operator 和环境的依赖项和限制。
  • 如果成功解决,则会自动安装指定范围内的 Operator 更新。
  • 当更新在指定的范围之外,或者无法成功解决,则不会安装更新。

有关 OLM 1.0 中依赖项和约束解析的更多信息,请参阅"OLM 1.0 中的依赖解析"。

7.3.8.3. 版本比较字符串

您可以通过在 Operator 或扩展的自定义资源(CR)的 spec.version 字段中添加比较字符串来定义版本范围。比较字符串是一个空格或以逗号分隔的值列表,以及以双引号括起的一个或多个比较运算符(")。您可以通过包括 OR、或双垂直栏(||)来添加另一个比较字符串,比较字符串之间的运算符。

表 7.4. 基本比较
比较运算符定义

=

等于

!=

不等于

>

大于

<

小于

>=

大于或等于

<=

小于或等于

您可以使用类似以下示例的范围比较在 Operator 或扩展 CR 中指定版本范围:

版本范围比较示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: pipelines-operator
spec:
  packageName: openshift-pipelines-operator-rh
  version: ">=1.11, <1.13"

您可以在所有类型的比较字符串中使用通配符字符。OLM 1.0 接受 xX 和星号(*)作为通配符字符。您可以在等号 (=) 比较运算符中使用通配符,代表在补丁或次版本级别上定义比较。

表 7.5. 比较字符串中的通配符字符示例
通配符比较匹配字符串

1.11.x

>=1.11.0, <1.12.0

>=1.12.X

>=1.12.0

<=2.x

<3

*

>=0.0.0

您可以使用波形符 (~) 比较运算符进行补丁版本比较。补丁版本比较指定最高为下一个主版本的次版本。

表 7.6. 补丁版本比较示例
补丁版本比较匹配字符串

~1.11.0

>=1.11.0, <1.12.0

~1

>=1, <2

~1.12

>=1.12, <1.13

~1.12.x

>=1.12.0, <1.13.0

~1.x

>=1, <2

您可以使用 caret (^) 比较运算符来比较主版本。如果您在第一个稳定版本发布前使用主发行版本比较,则次版本会定义 API 的稳定性级别。在语义版本(SemVer)规格中,第一个稳定版本被发布为 1.0.0 版本。

表 7.7. 主发行版本比较示例
主发行版本比较匹配字符串

^0

>=0.0.0, <1.0.0

^0.0

>=0.0.0, <0.1.0

^0.0.3

>=0.0.3, <0.0.4

^0.2

>=0.2.0, <0.3.0

^0.2.3

>=0.2.3, <0.3.0

^1.2.x

>= 1.2.0, < 2.0.0

^1.2.3

>= 1.2.3, < 2.0.0

^2.x

>= 2.0.0, < 3

^2.3

>= 2.3, < 3

7.3.8.4. 指定目标版本的自定义资源(CR)示例

在 Operator Lifecycle Manager (OLM) 1.0 中,集群管理员可以在自定义资源(CR)中声明性地设置 Operator 或扩展的目标版本。

您可以通过指定以下字段来定义目标版本:

  • Channel
  • 版本号
  • 版本范围

如果您在 CR 中指定频道,OLM 1.0 会安装可在指定频道中解析的 Operator 或扩展的最新版本。当向指定的频道发布更新时,OLM 1.0 会自动更新至可以从频道解析的最新发行版本。

带有指定频道的 CR 示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: pipelines-operator
spec:
  packageName: openshift-pipelines-operator-rh
  channel: latest 1

1
安装可从指定频道解析的最新版本。对频道的更新会自动安装。

如果在 CR 中指定 Operator 或扩展的目标版本,OLM 1.0 将安装指定的版本。当在 CR 中指定目标版本时,OLM 1.0 在向目录发布更新时不会更改目标版本。

如果要更新集群中安装的 Operator 版本,您必须手动编辑 Operator 的 CR。指定 Operator 的目标版本将 Operator 的版本固定到指定的发行版本。

指定了目标版本的 CR 示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: pipelines-operator
spec:
  packageName: openshift-pipelines-operator-rh
  version: 1.11.1 1

1
指定目标版本。如果要更新安装的 Operator 或扩展版本,您必须手动将 CR 更新至所需的目标版本。

如果要为 Operator 或扩展定义可接受的版本范围,您可以使用比较字符串指定版本范围。当您指定版本范围时,OLM 1.0 会安装可由 Operator Controller 解析的 Operator 或扩展的最新版本。

指定了版本范围的 CR 示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: pipelines-operator
spec:
  packageName: openshift-pipelines-operator-rh
  version: >1.11.1 1

1
指定所需的版本范围大于 1.11.1 版本。如需更多信息,请参阅"支持版本范围"。

创建或更新 CR 后,运行以下命令来应用配置文件:

命令语法

$ oc apply -f <extension_name>.yaml

7.3.8.5. 强制更新或回滚

OLM 1.0 不支持对下一个主版本的自动更新,或回滚到较早的版本。如果要执行主版本更新或回滚,您必须验证并强制更新。

警告

您必须验证强制进行手动更新或回滚的结果。验证强制更新或回滚失败可能会产生灾难性后果,如数据丢失。

先决条件

  • 已安装目录。
  • 已安装 Operator 或扩展。

流程

  1. 编辑 Operator 或扩展的自定义资源 (CR),如下例所示:

    CR 示例

    apiVersion: olm.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      name: <operator_name> 1
    spec:
      packageName: <package_name> 2
      version: <version> 3
      upgradeConstraintPolicy: Ignore 4

    1
    指定 Operator 或扩展的名称,如 pipelines-operator
    2
    指定软件包名称,如 openshift-pipelines-operator-rh
    3
    指定被阻断的更新或回滚版本。
    4
    可选:指定升级约束策略。要强制更新或回滚,请将字段设置为 Ignore。如果未指定,则默认设置为 Enforce
  2. 运行以下命令,对 Operator 或 extensions CR 应用更改:

    $ oc apply -f <extension_name>.yaml

其他资源

7.3.9. 删除 Operator

您可以通过删除 Operator 的自定义资源(CR)来删除 Operator 及其自定义资源定义(CRD)。

先决条件

  • 已安装目录。
  • 已安装 Operator。

流程

  • 运行以下命令来删除 Operator 及其 CRD:

    $ oc delete operator.operators.operatorframework.io <operator_name>

    输出示例

    operator.operators.operatorframework.io "<operator_name>" deleted

验证

  • 运行以下命令验证您的 Operator 及其资源已被删除:

    • 运行以下命令验证 Operator 已被删除:

      $ oc get operator.operators.operatorframework.io

      输出示例

      No resources found

    • 运行以下命令验证 Operator 的系统命名空间是否已删除:

      $ oc get ns <operator_name>-system

      输出示例

      Error from server (NotFound): namespaces "<operator_name>-system" not found

7.3.10. 删除目录

您可以通过删除其自定义资源 (CR) 来删除目录。

先决条件

  • 已安装目录。

流程

  • 运行以下命令来删除目录:

    $ oc delete catalog <catalog_name>

    输出示例

    catalog.catalogd.operatorframework.io "my-catalog" deleted

验证

  • 运行以下命令验证目录是否已删除:

    $ oc get catalog
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.