6.3. 使用 cluster-compare 插件


您可以使用 cluster-compare 插件将参考配置与来自 live 集群或 must-gather 数据的配置进行比较。

您可以使用 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
    Copy to Clipboard Toggle word wrap
    • -r 指定引用配置的 metadata.yaml 文件的路径。您可以指定本地目录或 URI。

      输出示例

      ...
      
      **********************************
      
      Cluster CR: operator.openshift.io/v1_Console_cluster 
      1
      
      Reference File: optional/console-disable/ConsoleOperatorDisable.yaml 
      2
      
      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: Removed 
      3
      
      +  managementState: Managed
         operatorLogLevel: Normal
      
      **********************************
      
      …
      
      Summary 
      4
      
      CRs with diffs: 5/49 
      5
      
      CRs in reference missing from the cluster: 1 
      6
      
      required-cluster-tuning:
        cluster-tuning:
          Missing CRs: 
      7
      
          - required/cluster-tuning/disabling-network-diagnostics/DisableSnoNetworkDiag.yaml
      No CRs are unmatched to reference CRs 
      8
      
      Metadata Hash: 512a9bf2e57fd5a5c44bbdea7abb3ffd7739d4a1f14ef9021f6793d5cdf868f0 
      9
      
      No patched CRs 
      10
      Copy to Clipboard Toggle word wrap

      1
      进行比较的 CR。该插件显示与对应模板不同的所有 CR。
      2
      与 CR 匹配的模板以进行比较。
      3
      Linux diff 格式的输出显示模板和集群 CR 之间的区别。
      4
      在插件报告了每个 CR 的 diffs 行后,还会报告不同内容的概述。
      5
      与相关模块不同的进行比较的 CR 数量。
      6
      在参考配置中存在但在实时集群中缺失的 CR 数量。
      7
      在参考配置中存在但在实时集群中缺失的 CR 列表。
      8
      与参考配置中对应的模板不匹配的 CR。
      9
      用于识别参考配置的元数据哈希。
      10
      进行了补丁的 CR 列表。
注意

通过将 -o junit 添加到命令,以 junit 格式获取输出。例如:

$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -o junit
Copy to Clipboard Toggle word wrap

junit 输出包括以下结果类型:

  • 为每个完全匹配模板传递的结果。
  • 找到或缺少所需自定义资源(CR)的不同结果失败。
  • 跳过使用用户覆盖机制修补的结果。

您可以使用 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
    Copy to Clipboard Toggle word wrap
    • -r 指定引用配置的 metadata.yaml 文件的路径。您可以指定本地目录或 URI。
    • -f 指定 must-gather 数据目录的路径。您可以指定本地目录或 URI。这个示例限制了相关集群配置目录的比较。
    • -R 递归搜索目标目录。

      输出示例

      ...
      
      **********************************
      
      Cluster CR: operator.openshift.io/v1_Console_cluster 
      1
      
      Reference File: optional/console-disable/ConsoleOperatorDisable.yaml 
      2
      
      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: Removed 
      3
      
      +  managementState: Managed
         operatorLogLevel: Normal
      
      **********************************
      
      …
      
      Summary 
      4
      
      CRs with diffs: 5/49 
      5
      
      CRs in reference missing from the cluster: 1 
      6
      
      required-cluster-tuning:
        cluster-tuning:
          Missing CRs: 
      7
      
          - required/cluster-tuning/disabling-network-diagnostics/DisableSnoNetworkDiag.yaml
      No CRs are unmatched to reference CRs 
      8
      
      Metadata Hash: 512a9bf2e57fd5a5c44bbdea7abb3ffd7739d4a1f14ef9021f6793d5cdf868f0 
      9
      
      No patched CRs 
      10
      Copy to Clipboard Toggle word wrap

      1
      进行比较的 CR。该插件显示与对应模板不同的所有 CR。
      2
      与 CR 匹配的模板以进行比较。
      3
      Linux diff 格式的输出显示模板和集群 CR 之间的区别。
      4
      在插件报告了每个 CR 的 diffs 行后,还会报告不同内容的概述。
      5
      与相关模块不同的进行比较的 CR 数量。
      6
      在参考配置中存在但在实时集群中缺失的 CR 数量。
      7
      在参考配置中存在但在实时集群中缺失的 CR 列表。
      8
      与参考配置中对应的模板不匹配的 CR。
      9
      用于识别参考配置的元数据哈希。
      10
      进行了补丁的 CR 列表。
注意

通过将 -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
Copy to Clipboard Toggle word wrap

junit 输出包括以下结果类型:

  • 为每个完全匹配模板传递的结果。
  • 找到或缺少所需自定义资源(CR)的不同结果失败。
  • 跳过使用用户覆盖机制修补的结果。

6.3.3. 参考 cluster-compare 插件选项

以下内容描述了 cluster-compare 插件的选项。

Expand
表 6.1. cluster-compare 插件选项
选项描述

-A, --all-resources

当与 live 集群一起使用时,尝试匹配集群中与引用配置中类型匹配的所有资源。与本地文件一起使用时,会尝试与参考配置中类型匹配的本地文件中的所有资源匹配。

--concurrency

在与来自 live 版本的资源进行比较时,为要并行处理的模板数量指定一个整数值。较大的数字会增加速度,但同时也会增加内存、I/O 和 CPU 的用量。默认值为 4

-c, --diff-config

指定用户配置文件的路径。

-f, --filename

指定与参考配置进行比较的配置自定义资源的文件名、目录或 URL。

--generate-override-for

指定需要补丁的模板路径。

--show-template-functions

显示可用的模板功能。

注意

您必须使用相对于 metadata.yaml 文件的目标模板的文件路径。例如,如果 metadata.yaml 文件的文件路径是 ./compare/metadata.yaml,则模板的相对文件路径可能是 optional/my-template.yaml

-h,--help

显示帮助信息。

-k, --kustomize

指定处理 kustomization 目录的路径。此标志不能与 -f-R 一起使用。

-o, --output

指定输出格式。选项包括 jsonyamljunitgenerate-patches

--override-reason

指定生成覆盖的原因。

-p, --overrides

为参考配置指定补丁覆盖文件的路径。

-R, --recursive

处理以递归方式在 -f, --filename 中指定的目录。

-r, --reference

指定引用配置 metadata.yaml 文件的路径。

--show-managed-fields

指定 true 在比较中包含受管字段。

-v,--verbose

增加插件输出的详细程度。

您可以使用 cluster-compare 插件将参考配置与来自 live 集群或 must-gather 数据的配置进行比较。

这个示例将实时集群的配置与电信核心参考配置进行比较。电信核心参考配置源自电信核心参考设计规范(RDS)。电信核心 RDS 专为集群设计,以支持大规模电信应用程序,包括控制平面和一些集中式数据平面功能。

参考配置打包在带有电信核心 RDS 的容器镜像中。

有关将 cluster-compare 插件与电信核心和电信 RAN 分布式单元(DU)配置文件一起使用的更多信息,请参阅"添加资源"部分。

先决条件

  • 您可以使用具有 cluster-admin 角色的用户访问集群。
  • 有访问 registry.redhat.io 容器镜像 registry 的凭证。
  • 已安装 cluster-compare 插件。

流程

  1. 运行以下命令,使用凭证登录到容器镜像 registry:

    $ podman login registry.redhat.io
    Copy to Clipboard Toggle word wrap
  2. 运行以下命令,从 lecommunications-core-rds-rhel9 容器镜像中提取内容:

    $ mkdir -p ./out
    Copy to Clipboard Toggle word wrap
    $ podman run -it registry.redhat.io/openshift4/openshift-telco-core-rds-rhel9:v4.18 | base64 -d | tar xv -C out
    Copy to Clipboard Toggle word wrap

    您可以在 reference-crs-kube-compare/ 目录中查看引用配置。

    out/telco-core-rds/configuration/reference-crs-kube-compare/
    ├── metadata.yaml 
    1
    
    ├── optional 
    2
    
    │   ├── logging
    │   ├── networking
    │   ├── other
    │   └── tuning
    └── required 
    3
    
        ├── networking
        ├── other
        ├── performance
        ├── scheduling
        └── storage
    Copy to Clipboard Toggle word wrap
    1
    参考配置的配置文件。
    2
    可选模板的目录。
    3
    所需模板的目录。
  3. 运行以下命令,将集群的配置与电信核心参考配置进行比较:

    $ oc cluster-compare -r out/telco-core-rds/configuration/reference-crs-kube-compare/metadata.yaml
    Copy to Clipboard Toggle word wrap

    输出示例

    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_cluster 
    1
    
    Reference File: required/other/operator-hub.yaml 
    2
    
    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
    
    **********************************
    
    Summary 
    4
    
    CRs with diffs: 3/4 
    5
    
    CRs in reference missing from the cluster: 22 
    6
    
    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 CRs 
    8
    
    Metadata Hash: fe41066bac56517be02053d436c815661c9fa35eec5922af25a1be359818f297 
    9
    
    No patched CRs 
    10
    Copy to Clipboard Toggle word wrap

    1
    进行比较的 CR。该插件显示与对应模板不同的所有 CR。
    2
    与 CR 匹配的模板以进行比较。
    3
    Linux diff 格式的输出显示模板和集群 CR 之间的区别。
    4
    在插件报告了每个 CR 的 diffs 行后,还会报告不同内容的概述。
    5
    与相关模块不同的进行比较的 CR 数量。
    6
    在参考配置中存在但在实时集群中缺失的 CR 数量。
    7
    在参考配置中存在但在实时集群中缺失的 CR 列表。
    8
    与参考配置中对应的模板不匹配的 CR。
    9
    用于识别参考配置的元数据哈希。
    10
    进行了补丁的 CR 列表。
注意

通过将 -o junit 添加到命令,以 junit 格式获取输出。例如:

$ oc cluster-compare -r out/telco-core-rds/configuration/reference-crs-kube-compare/metadata.yaml -o junit
Copy to Clipboard Toggle word wrap

junit 输出包括以下结果类型:

  • 为每个完全匹配模板传递的结果。
  • 找到或缺少所需自定义资源(CR)的不同结果失败。
  • 跳过使用用户覆盖机制修补的结果。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat