6.3. 使用 cluster-compare 插件
您可以使用 cluster-compare 插件将参考配置与来自 live 集群或 must-gather 数据的配置进行比较。
6.3.1. 将 cluster-compare 插件与实时集群一起使用 复制链接链接已复制到粘贴板!
您可以使用 cluster-compare 插件将引用配置与来自 live 集群的配置自定义资源(CR)进行比较。
验证实时集群配置,以确保在设计、开发或测试场景中遵守引用配置。
在非生产环境中,将 cluster-compare 插件与 live 集群一起使用。对于生产环境,请使用带有 must-gather 数据的插件。
先决条件
-
已安装 OpenShift CLI(
oc)。 -
您可以使用具有
cluster-admin角色的用户访问集群。 -
您下载了
cluster-compare插件,并将其包含在PATH环境变量中。 - 您可以访问参考配置。
流程
使用以下命令运行
cluster-compare插件:$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml-r指定引用配置的metadata.yaml文件的路径。您可以指定本地目录或 URI。输出示例
... ********************************** Cluster CR: operator.openshift.io/v1_Console_cluster1 Reference File: optional/console-disable/ConsoleOperatorDisable.yaml2 Diff Output: diff -u -N /tmp/MERGED-622469311/operator-openshift-io-v1_console_cluster /tmp/LIVE-2358803347/operator-openshift-io-v1_console_cluster /tmp/MERGED-622469311/operator-openshift-io-v1_console_cluster 2024-11-20 15:43:42.888633602 +0000 +++ /tmp/LIVE-2358803347/operator-openshift-io-v1_console_cluster 2024-11-20 15:43:42.888633602 +0000 @@ -4,5 +4,5 @@ name: cluster spec: logLevel: Normal - managementState: Removed3 + managementState: Managed operatorLogLevel: Normal ********************************** … Summary4 CRs with diffs: 5/495 CRs in reference missing from the cluster: 16 required-cluster-tuning: cluster-tuning: Missing CRs:7 - required/cluster-tuning/disabling-network-diagnostics/DisableSnoNetworkDiag.yaml No CRs are unmatched to reference CRs8 Metadata Hash: 512a9bf2e57fd5a5c44bbdea7abb3ffd7739d4a1f14ef9021f6793d5cdf868f09 No patched CRs10
通过将 -o junit 添加到命令,以 junit 格式获取输出。例如:
$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -o junit
junit 输出包括以下结果类型:
- 为每个完全匹配模板传递的结果。
- 找到或缺少所需自定义资源(CR)的不同结果失败。
- 跳过使用用户覆盖机制修补的结果。
6.3.2. 将 cluster-compare 插件与 must-gather 数据一起使用 复制链接链接已复制到粘贴板!
您可以使用 cluster-compare 插件将引用配置与 must-gather 数据的配置自定义资源(CR)进行比较。
使用 must-gather 数据来在生产环境中排除配置问题来验证集群配置。
对于生产环境,仅将 cluster-compare 插件与 must-gather 数据一起使用。
-
您可以从目标集群访问
must-gather数据。 -
已安装 OpenShift CLI(
oc)。 -
您已下载了
cluster-compare插件,并将其包含在PATH环境变量中。 - 您可以访问参考配置。
流程
运行以下命令,将
must-gather数据与参考配置进行比较:$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -f "must-gather*/*/cluster-scoped-resources","must-gather*/*/namespaces" -R-
-r指定引用配置的metadata.yaml文件的路径。您可以指定本地目录或 URI。 -
-f指定must-gather数据目录的路径。您可以指定本地目录或 URI。这个示例限制了相关集群配置目录的比较。 -R递归搜索目标目录。输出示例
... ********************************** Cluster CR: operator.openshift.io/v1_Console_cluster1 Reference File: optional/console-disable/ConsoleOperatorDisable.yaml2 Diff Output: diff -u -N /tmp/MERGED-622469311/operator-openshift-io-v1_console_cluster /tmp/LIVE-2358803347/operator-openshift-io-v1_console_cluster /tmp/MERGED-622469311/operator-openshift-io-v1_console_cluster 2024-11-20 15:43:42.888633602 +0000 +++ /tmp/LIVE-2358803347/operator-openshift-io-v1_console_cluster 2024-11-20 15:43:42.888633602 +0000 @@ -4,5 +4,5 @@ name: cluster spec: logLevel: Normal - managementState: Removed3 + managementState: Managed operatorLogLevel: Normal ********************************** … Summary4 CRs with diffs: 5/495 CRs in reference missing from the cluster: 16 required-cluster-tuning: cluster-tuning: Missing CRs:7 - required/cluster-tuning/disabling-network-diagnostics/DisableSnoNetworkDiag.yaml No CRs are unmatched to reference CRs8 Metadata Hash: 512a9bf2e57fd5a5c44bbdea7abb3ffd7739d4a1f14ef9021f6793d5cdf868f09 No patched CRs10
-
通过将 -o junit 添加到命令,以 junit 格式获取输出。例如:
$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -f "must-gather*/*/cluster-scoped-resources","must-gather*/*/namespaces" -R -o junit
junit 输出包括以下结果类型:
- 为每个完全匹配模板传递的结果。
- 找到或缺少所需自定义资源(CR)的不同结果失败。
- 跳过使用用户覆盖机制修补的结果。
6.3.3. 参考 cluster-compare 插件选项 复制链接链接已复制到粘贴板!
以下内容描述了 cluster-compare 插件的选项。
| 选项 | 描述 |
|---|---|
|
| 当与 live 集群一起使用时,尝试匹配集群中与引用配置中类型匹配的所有资源。与本地文件一起使用时,会尝试与参考配置中类型匹配的本地文件中的所有资源匹配。 |
|
|
在与来自 live 版本的资源进行比较时,为要并行处理的模板数量指定一个整数值。较大的数字会增加速度,但同时也会增加内存、I/O 和 CPU 的用量。默认值为 |
|
| 指定用户配置文件的路径。 |
|
| 指定与参考配置进行比较的配置自定义资源的文件名、目录或 URL。 |
|
| 指定需要补丁的模板路径。 |
|
| 显示可用的模板功能。 注意
您必须使用相对于 |
|
| 显示帮助信息。 |
|
|
指定处理 |
|
|
指定输出格式。选项包括 |
|
| 指定生成覆盖的原因。 |
|
| 为参考配置指定补丁覆盖文件的路径。 |
|
|
处理以递归方式在 |
|
|
指定引用配置 |
|
|
指定 |
|
| 增加插件输出的详细程度。 |
6.3.4. 示例:比较带有电信内核参考配置的集群 复制链接链接已复制到粘贴板!
您可以使用 cluster-compare 插件将参考配置与来自 live 集群或 must-gather 数据的配置进行比较。
这个示例将实时集群的配置与电信核心参考配置进行比较。电信核心参考配置源自电信核心参考设计规范(RDS)。电信核心 RDS 专为集群设计,以支持大规模电信应用程序,包括控制平面和一些集中式数据平面功能。
参考配置打包在带有电信核心 RDS 的容器镜像中。
有关将 cluster-compare 插件与电信核心和电信 RAN 分布式单元(DU)配置文件一起使用的更多信息,请参阅"添加资源"部分。
先决条件
-
您可以使用具有
cluster-admin角色的用户访问集群。 -
有访问
registry.redhat.io容器镜像 registry 的凭证。 -
已安装
cluster-compare插件。
流程
运行以下命令,使用凭证登录到容器镜像 registry:
$ podman login registry.redhat.io运行以下命令,从
lecommunications-core-rds-rhel9容器镜像中提取内容:$ mkdir -p ./out$ podman run -it registry.redhat.io/openshift4/openshift-telco-core-rds-rhel9:v4.18 | base64 -d | tar xv -C out您可以在
reference-crs-kube-compare/目录中查看引用配置。out/telco-core-rds/configuration/reference-crs-kube-compare/ ├── metadata.yaml1 ├── optional2 │ ├── logging │ ├── networking │ ├── other │ └── tuning └── required3 ├── networking ├── other ├── performance ├── scheduling └── storage运行以下命令,将集群的配置与电信核心参考配置进行比较:
$ oc cluster-compare -r out/telco-core-rds/configuration/reference-crs-kube-compare/metadata.yaml输出示例
W1212 14:13:06.281590 36629 compare.go:425] Reference Contains Templates With Types (kind) Not Supported By Cluster: BFDProfile, BGPAdvertisement, BGPPeer, ClusterLogForwarder, Community, IPAddressPool, MetalLB, MultiNetworkPolicy, NMState, NUMAResourcesOperator, NUMAResourcesScheduler, NodeNetworkConfigurationPolicy, SriovNetwork, SriovNetworkNodePolicy, SriovOperatorConfig, StorageCluster ... ********************************** Cluster CR: config.openshift.io/v1_OperatorHub_cluster1 Reference File: required/other/operator-hub.yaml2 Diff Output: diff -u -N /tmp/MERGED-2801470219/config-openshift-io-v1_operatorhub_cluster /tmp/LIVE-2569768241/config-openshift-io-v1_operatorhub_cluster --- /tmp/MERGED-2801470219/config-openshift-io-v1_operatorhub_cluster 2024-12-12 14:13:22.898756462 +0000 +++ /tmp/LIVE-2569768241/config-openshift-io-v1_operatorhub_cluster 2024-12-12 14:13:22.898756462 +0000 @@ -1,6 +1,6 @@ apiVersion: config.openshift.io/v1 kind: OperatorHub metadata: + annotations:3 + include.release.openshift.io/hypershift: "true" name: cluster -spec: - disableAllDefaultSources: true ********************************** Summary4 CRs with diffs: 3/45 CRs in reference missing from the cluster: 226 other: other: Missing CRs:7 - optional/other/control-plane-load-kernel-modules.yaml - optional/other/worker-load-kernel-modules.yaml required-networking: networking-root: Missing CRs: - required/networking/nodeNetworkConfigurationPolicy.yaml networking-sriov: Missing CRs: - required/networking/sriov/sriovNetwork.yaml - required/networking/sriov/sriovNetworkNodePolicy.yaml - required/networking/sriov/SriovOperatorConfig.yaml - required/networking/sriov/SriovSubscription.yaml - required/networking/sriov/SriovSubscriptionNS.yaml - required/networking/sriov/SriovSubscriptionOperGroup.yaml required-other: scheduling: Missing CRs: - required/other/catalog-source.yaml - required/other/icsp.yaml required-performance: performance: Missing CRs: - required/performance/PerformanceProfile.yaml required-scheduling: scheduling: Missing CRs: - required/scheduling/nrop.yaml - required/scheduling/NROPSubscription.yaml - required/scheduling/NROPSubscriptionNS.yaml - required/scheduling/NROPSubscriptionOperGroup.yaml - required/scheduling/sched.yaml required-storage: storage-odf: Missing CRs: - required/storage/odf-external/01-rook-ceph-external-cluster-details.secret.yaml - required/storage/odf-external/02-ocs-external-storagecluster.yaml - required/storage/odf-external/odfNS.yaml - required/storage/odf-external/odfOperGroup.yaml - required/storage/odf-external/odfSubscription.yaml No CRs are unmatched to reference CRs8 Metadata Hash: fe41066bac56517be02053d436c815661c9fa35eec5922af25a1be359818f2979 No patched CRs10
通过将 -o junit 添加到命令,以 junit 格式获取输出。例如:
$ oc cluster-compare -r out/telco-core-rds/configuration/reference-crs-kube-compare/metadata.yaml -o junit
junit 输出包括以下结果类型:
- 为每个完全匹配模板传递的结果。
- 找到或缺少所需自定义资源(CR)的不同结果失败。
- 跳过使用用户覆盖机制修补的结果。