5.16. 将软件包清单项目迁移到捆绑包格式
OpenShift Container Platform 4.8 及更高版本中删除了对 Operator 的传统软件包清单格式的支持。如果您有一个最初使用软件包清单格式创建的 Operator 项目,您可以使用 Operator SDK 将项目迁移到捆绑包格式。从 OpenShift Container Platform 4.6 开始,捆绑包格式是 Operator Lifecycle Manager(OLM)的首选打包格式。
5.16.1. 关于打包格式迁移
Operator SDK pkgman-to-bundle
命令有助于将 Operator Lifecycle Manager(OLM)软件包清单迁移到捆绑包。命令采用输入软件包清单目录,并为输入目录中存在的每个清单版本生成捆绑包。然后,您还可以为每个生成的捆绑包构建捆绑包镜像。
例如,以软件包清单格式考虑项目的以下 packagemanifests/
目录:
软件包清单格式布局示例
packagemanifests/ └── etcd ├── 0.0.1 │ ├── etcdcluster.crd.yaml │ └── etcdoperator.clusterserviceversion.yaml ├── 0.0.2 │ ├── etcdbackup.crd.yaml │ ├── etcdcluster.crd.yaml │ ├── etcdoperator.v0.0.2.clusterserviceversion.yaml │ └── etcdrestore.crd.yaml └── etcd.package.yaml
运行迁移后,bundle/
目录中会生成以下捆绑包:
捆绑包格式布局示例
bundle/ ├── bundle-0.0.1 │ ├── bundle.Dockerfile │ ├── manifests │ │ ├── etcdcluster.crd.yaml │ │ ├── etcdoperator.clusterserviceversion.yaml │ ├── metadata │ │ └── annotations.yaml │ └── tests │ └── scorecard │ └── config.yaml └── bundle-0.0.2 ├── bundle.Dockerfile ├── manifests │ ├── etcdbackup.crd.yaml │ ├── etcdcluster.crd.yaml │ ├── etcdoperator.v0.0.2.clusterserviceversion.yaml │ ├── etcdrestore.crd.yaml ├── metadata │ └── annotations.yaml └── tests └── scorecard └── config.yaml
根据生成的布局,两个捆绑包的捆绑包镜像也使用以下名称构建:
-
quay.io/example/etcd:0.0.1
-
quay.io/example/etcd:0.0.2
5.16.2. 迁移软件包清单项目到捆绑包格式
Operator 作者可以使用 Operator SDK 将软件包清单格式 Operator 项目迁移到捆绑包格式项目。
先决条件
- 已安装 operator SDK CLI
- Operator 项目最初使用 Operator SDK 以软件包清单格式生成
流程
使用 Operator SDK 将软件包清单项目迁移到捆绑包格式并生成捆绑包镜像:
$ operator-sdk pkgman-to-bundle <package_manifests_dir> \ 1 [--output-dir <directory>] \ 2 --image-tag-base <image_name_base> 3
验证
验证生成的捆绑包镜像是否成功运行:
$ operator-sdk run bundle <bundle_image_name>:<tag>
输出示例
INFO[0025] Successfully created registry pod: quay-io-my-etcd-0-9-4 INFO[0025] Created CatalogSource: etcd-catalog INFO[0026] OperatorGroup "operator-sdk-og" created INFO[0026] Created Subscription: etcdoperator-v0-9-4-sub INFO[0031] Approved InstallPlan install-5t58z for the Subscription: etcdoperator-v0-9-4-sub INFO[0031] Waiting for ClusterServiceVersion "default/etcdoperator.v0.9.4" to reach 'Succeeded' phase INFO[0032] Waiting for ClusterServiceVersion "default/etcdoperator.v0.9.4" to appear INFO[0048] Found ClusterServiceVersion "default/etcdoperator.v0.9.4" phase: Pending INFO[0049] Found ClusterServiceVersion "default/etcdoperator.v0.9.4" phase: Installing INFO[0064] Found ClusterServiceVersion "default/etcdoperator.v0.9.4" phase: Succeeded INFO[0065] OLM has successfully installed "etcdoperator.v0.9.4"