$ operator-sdk bundle validate <bundle_dir_or_image> <flags>
作为 Operator 作者,您可以在 Operator SDK 中运行bundle validate
命令来验证 Operator bundle 的内容和格式。您可以对远程 Operator bundle 镜像或本地 Operator bundle 目录运行此命令。
Red Hat 支持的 Operator SDK CLI 工具版本(包括 Operator 项目相关的脚手架和测试工具)已弃用,并计划在未来版本的 OpenShift Container Platform 中移除。Red Hat 将在当前版本生命周期内为此功能提供错误修复和支持,但此功能将不再接收增强功能,并将从未来的 OpenShift Container Platform 版本中移除。 不建议使用 Red Hat 支持的 Operator SDK 版本创建新的 Operator 项目。拥有现有 Operator 项目的 Operator 作者可以使用 OpenShift Container Platform 4.17 版本发布的 Operator SDK CLI 工具版本来维护其项目并创建针对较新版本的 OpenShift Container Platform 的 Operator 版本。 以下与 Operator 项目相关的基础镜像*未*弃用。这些基础镜像的运行时功能和配置 API 仍受支持,用于错误修复和解决 CVE。
有关 OpenShift Container Platform 中已弃用或移除的主要功能的最新列表,请参阅 OpenShift Container Platform 发行说明的“已弃用和移除的功能”部分。 有关不受支持的社区维护的 Operator SDK 版本的信息,请参阅Operator SDK (Operator Framework)。 |
虽然 Operator SDK scorecard
命令可以根据配置文件和测试镜像对您的 Operator 运行测试,但bundle validate
子命令可以验证本地 bundle 目录和远程 bundle 镜像的内容和结构。
bundle validate
命令语法$ operator-sdk bundle validate <bundle_dir_or_image> <flags>
使用 |
bundle 镜像在验证之前会从远程注册表中提取并在本地构建。本地 bundle 目录必须包含 Operator 元数据和清单。bundle 元数据和清单必须具有类似于以下 bundle 布局的结构
./bundle
├── manifests
│ ├── cache.my.domain_memcacheds.yaml
│ └── memcached-operator.clusterserviceversion.yaml
└── metadata
└── annotations.yaml
如果未检测到错误,bundle 测试将通过验证并以0
的退出代码结束。
INFO[0000] All validation tests have completed successfully
如果检测到错误,测试将无法通过验证并以1
的退出代码结束。
ERRO[0000] Error: Value cache.example.com/v1alpha1, Kind=Memcached: CRD "cache.example.com/v1alpha1, Kind=Memcached" is present in bundle "" but not defined in CSV
只要未检测到错误,即使产生警告的 bundle 测试仍可以以0
的退出代码通过验证。测试仅在出现错误时才会失败。
WARN[0000] Warning: Value : (memcached-operator.v0.0.1) annotations not found
INFO[0000] All validation tests have completed successfully
有关bundle validate
子命令的更多信息,请运行
$ operator-sdk bundle validate -h
Operator SDK 附带预定义的验证器,这些验证器排列成套件。如果您运行bundle validate
命令而不指定验证器,则会运行默认测试。默认测试验证 bundle 是否符合 Operator Framework 社区定义的规范。有关更多信息,请参阅“bundle 格式”。
您可以运行可选验证器来测试 OperatorHub 兼容性或已弃用的 Kubernetes API 等问题。可选验证器始终会除了默认测试之外运行。
bundle validate
命令语法$ operator-sdk bundle validate <bundle_dir_or_image>
--select-optional <test_label>
名称 | 描述 | 标签 |
---|---|---|
Operator Framework |
此验证器会根据 Operator Framework 提供的完整验证器套件测试 Operator bundle。 |
|
OperatorHub |
此验证器会测试 Operator bundle 与 OperatorHub 的兼容性。 |
|
最佳实践 |
此验证器会测试 Operator bundle 是否符合 Operator Framework 定义的最佳实践。它会检查诸如空 CRD 说明或不受支持的 Operator Lifecycle Manager (OLM) 资源等问题。 |
|
每次输入bundle validate
命令时,默认验证器都会运行测试。您可以使用--select-optional
标志运行可选验证器。可选验证器会除了默认测试之外运行测试。
使用 Operator SDK 生成的 Operator 项目
如果您想对本地 bundle 目录运行默认验证器,请在您的 Operator 项目目录中输入以下命令
$ operator-sdk bundle validate ./bundle
如果您想对远程 Operator bundle 镜像运行默认验证器,请输入以下命令
$ operator-sdk bundle validate \
<bundle_registry>/<bundle_image_name>:<tag>
其中
指定托管 bundle 的注册表,例如 quay.io/example
。
指定 bundle 镜像的名称,例如 memcached-operator
。
指定 bundle 镜像的标签,例如 v1.36.1
。
如果您想验证 Operator bundle 镜像,必须将您的镜像托管在远程注册表中。Operator SDK 会拉取镜像并在本地构建后再运行测试。 |
如果您想对 Operator bundle 运行其他验证器,请输入以下命令
$ operator-sdk bundle validate \
<bundle_dir_or_image> \
--select-optional <test_label>
其中
指定本地 bundle 目录或远程 bundle 镜像,例如 ~/projects/memcached
或 quay.io/example/memcached-operator:v1.36.1
。
指定要运行的验证器的名称,例如 name=good-practices
。
ERRO[0000] Error: Value apiextensions.k8s.io/v1, Kind=CustomResource: unsupported media type registry+v1 for bundle object
WARN[0000] Warning: Value k8sevent.v0.0.1: owned CRD "k8sevents.k8s.k8sevent.com" has an empty description
您可以通过运行 bundle validate
命令来验证您的 Operator 的多平台就绪性。该命令会验证您的 Operator 项目是否满足以下条件:
您的 Operator 的管理器镜像支持集群服务版本 (CSV) 文件中标注的平台。
您的 Operator 的 CSV 具有 Operator Lifecycle Manager (OLM) 和 OperatorHub 支持平台的标签。
运行以下命令以验证您的 Operator 项目的多架构就绪性:
$ operator-sdk bundle validate ./bundle \
--select-optional name=multiarch
INFO[0020] All validation tests have completed successfully
ERRO[0016] Error: Value test-operator.v0.0.1: not all images specified are providing the support described via the CSV labels. Note that (SO.architecture): (linux.ppc64le) was not found for the image(s) [quay.io/example-org/test-operator:v1alpha1]
ERRO[0016] Error: Value test-operator.v0.0.1: not all images specified are providing the support described via the CSV labels. Note that (SO.architecture): (linux.s390x) was not found for the image(s) [quay.io/example-org/test-operator:v1alpha1]
ERRO[0016] Error: Value test-operator.v0.0.1: not all images specified are providing the support described via the CSV labels. Note that (SO.architecture): (linux.amd64) was not found for the image(s) [quay.io/example-org/test-operator:v1alpha1]
ERRO[0016] Error: Value test-operator.v0.0.1: not all images specified are providing the support described via the CSV labels. Note that (SO.architecture): (linux.arm64) was not found for the image(s) [quay.io/example-org/test-operator:v1alpha1]
WARN[0014] Warning: Value test-operator.v0.0.1: check if the CSV is missing the label (operatorframework.io/arch.<value>) for the Arch(s): ["amd64" "arm64" "ppc64le" "s390x"]. Be aware that your Operator manager image ["quay.io/example-org/test-operator:v1alpha1"] provides this support. Thus, it is very likely that you want to provide it and if you support more than amd64 architectures, you MUST,use the required labels for all which are supported.Otherwise, your solution cannot be listed on the cluster for these architectures