首页 / 资讯中心 / 文章详情

Argo CD get-reconcile-results 命令详解:离线比对全量应用协调结果并定位回归

Argo CD get-reconcile-results 命令详解:离线比对全量应用协调结果并定位回归 ★ FEATURED ARTICLE
Argo CD get-reconcile-results 命令详解离线比对全量应用协调结果并定位回归【免费下载链接】argo-cdDeclarative Continuous Deployment for Kubernetes项目地址: https://gitcode.com/GitHub_Trending/ar/argo-cdargocd admin app get-reconcile-results是 Argo CD 管理端admin下的一个诊断型命令它会把 Argo CD 实例中所有或按标签筛选的Application 的协调reconcile结果汇总后落盘为 YAML/JSON 文件配合diff-reconcile-results命令即可在两次运行之间做逐应用 diff用于验证 controller 升级、normalizer 规则变更、集群配置调整前后应用协调结果是否一致。读完本篇你能掌握该命令的完整参数、两种工作模式读取既有状态 / 重新计算协调的区别、输出文件结构以及命令背后的实现调用链与测试验证方式。命令定位与适用场景该命令属于argocd admin app命令组Manage applications configuration父命令的示例如下见 docs/user-guide/commands/argocd_admin_app.md# Reconcile all applications and store reconciliation summary in the specified file argocd admin app get-reconcile-results PATH典型使用流程是在环境 A例如当前版本执行argocd admin app get-reconcile-results results-before.yaml变更系统升级 Argo CD、修改argocd-cm中的 diff normalizer、更换集群配置等再次执行argocd admin app get-reconcile-results results-after.yaml用argocd admin app diff-reconcile-results results-before.yaml results-after.yaml输出差异。由于它位于admin命令组下命令不经过 Argo CD API Server而是直接通过 kubeconfig 访问 Kubernetes 集群因此使用者需要拥有对 Argo CD 所在集群以及--refresh模式下的目标集群的访问权限。用法与完整参数说明argocd admin app get-reconcile-results PATH [flags]其中PATH是要写入的本地文件路径。命令自身提供的选项继承自 cmd/argocd/commands/admin/app.go 中NewReconcileCommand的定义参数说明-l, --label标签选择器只处理匹配标签的 Application文档中写作--l对应源码command.Flags().StringVar(selector, l, ...)-o, --output输出格式yaml或json默认yaml--refresh置为 true 时重新计算各应用的协调结果而不是读取 Application 对象上的既有状态--repo-serverrepo-server 地址。--refresh模式下若未指定CLI 会自动对argocd-repo-serverPod 做 port-forward本地 8081 端口映射到 Pod--server-side-diff置为 true 时资源比对使用 server-side diff。默认false--ignore-normalizer-jq-execution-timeout设置 ignore normalizer 中 JQ 表达式的执行超时默认1s与 kubectl 一致的访问类选项由cli.AddKubectlFlagsToCmd统一注册--as string Username to impersonate for the operation --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. --as-uid string UID to impersonate for the operation --certificate-authority string Path to a cert file for the certificate authority --client-certificate string Path to a client certificate file for TLS --client-key string Path to a client key file for TLS --cluster string The name of the kubeconfig cluster to use --context string The name of the kubeconfig context to use --disable-compression If true, opt-out of response compression for all requests to the server -h, --help help for get-reconcile-results --insecure-skip-tls-verify If true, the servers certificate will not be checked for validity. This will make your HTTPS connections insecure --kubeconfig string Path to a kube config. Only required if out-of-cluster -n, --namespace string If present, the namespace scope for this CLI request --password string Password for basic authentication to the API server --proxy-url string If provided, this URL will be used to connect via proxy --request-timeout string The length of time to wait before giving up on a single server request (default 0) --server string The address and port of the Kubernetes API server --tls-server-name string If provided, this name will be used to validate server certificate --token string Bearer token for authentication to the API server --user string The name of the kubeconfig user to use --username string Username for basic authentication to the API server从argocd根命令继承的通用选项与整个 CLI 一致--argocd-context string The name of the Argo-CD server context to use --auth-token string Authentication token; set this or the ARGOCD_AUTH_TOKEN environment variable --client-crt string Client certificate file --client-crt-key string Client certificate key file --config string Path to Argo CD config (default ~/.config/argocd/config) --controller-name string Name of the Argo CD Application controller (default argocd-application-controller) --core If set to true then CLI talks directly to Kubernetes instead of talking to Argo CD API server --grpc-web Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. --grpc-web-root-path string Enables gRPC-web protocol. Set web root. -H, --header strings Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers) --http-retry-max int Maximum number of retries to establish http connection to Argo CD server --insecure Skip server certificate and domain verification --kube-context string Directs the command to the given kube-context --logformat string Set the logging format. One of: json|text (default json) --loglevel string Set the logging level. One of: debug|info|warn|error (default info) --plaintext Disable TLS --port-forward Connect to a random argocd-server port using port forwarding --port-forward-namespace string Namespace name which should be used for port forwarding --prompts-enabled Force optional interactive prompts to be enabled or disabled, overriding local configuration --redis-compress string (possible values: gzip, none) (default gzip) --redis-haproxy-name string (default argocd-redis-ha-haproxy) --redis-name string (default argocd-redis) --repo-server-name string (default argocd-repo-server) --server-crt string Server certificate file --server-name string (default argocd-server)其中-n/--namespace对本命令尤为关键它决定了 CLI 在哪个命名空间中列出 Application以及--refresh模式下寻找 repo-server Service、构建 settings manager 的命名空间。两种工作模式读取状态 vs 重新协调命令的Run逻辑在 cmd/argocd/commands/admin/app.go 中按--refresh分成两条路径模式一默认模式——读取 Application 既有状态对应getReconcileResults函数cmd/argocd/commands/admin/app.go通过 Argo CD 的 typed clientset 列出目标命名空间可加 label selector下所有 Application直接取每个 App 的Status.Conditions、Status.Health.Status、Status.Sync组装成结果项。该模式快、无副作用适合导出controller 最后一次协调后记录的状态快照。模式二--refresh——重新计算协调结果对应reconcileApplications函数cmd/argocd/commands/admin/app.go它会临时在客户端侧复现 application-controller 的核心比对流程准备 repo-server 连接若未通过--repo-server指定地址CLI 会按app.kubernetes.io/componentrepo-server标签找到 repo-server Service读取其app.kubernetes.io/name标签确定 Pod 名再对 8081 端口做 port-forward得到本地地址建立 informer 与状态缓存为 Application 与 AppProject 建立 SharedInformerFactory1 小时 resync等待缓存同步后通过newLiveStateCache构造LiveStateCache并执行Init()同时启动一个 metrics server 和一个 1 分钟过期的内存 app state cache构建 AppStateManager使用与 controller 相同的controller.NewAppStateManager注入argoDB从集群内 ConfigMap/Secret 读取集群注册信息、repo-server clientset、--server-side-diff与--ignore-normalizer-jq-execution-timeout选项逐应用比对按Spec.Destination.Server排序应用列表切换到新目标集群时先Invalidate()旧集群缓存并打印Reconciling apps of server对每个 App 调用appStateManager.CompareAppState(...)取回Health与Sync状态。值得注意的细节Run一开始会执行os.Setenv(v1alpha1.EnvVarFakeInClusterConfig, true)cmd/argocd/commands/admin/app.go。其含义是告诉底层组件当前运行在集群外访问目标集群时使用 kubeconfig 而非 in-cluster 服务账户——这正是该命令能在本地终端直接对多集群应用做重协调的前提。--refresh模式的限制需要本地 kubeconfig 能够访问所有目标集群通过 Argo CD 中注册的server/name解析--server-side-diff与 JQ 超时参数只在该模式下参与比对过程。输出文件结构与 diff 命令配合结果写入PATH的结构由saveToFile按-o序列化cmd/argocd/commands/admin/app.goGo 结构定义为type appReconcileResult struct { Name string json:name Health health.HealthStatusCode json:health Sync *v1alpha1.SyncStatus json:sync Conditions []v1alpha1.ApplicationCondition json:conditions } type reconcileResults struct { Applications []appReconcileResult json:applications }因此默认 YAML 输出形如applications: - name: guestbook health: Healthy sync: status: Synced ... conditions: []姊妹命令diff-reconcile-results PATH1 PATH2cmd/argocd/commands/admin/app.go把两个文件反序列化为reconcileResults按应用名建立映射、排序后逐应用输出 unified diff仅存在于某一侧的应用会显示为整段新增/删除。其输出行为在测试TestDiffReconcileResults_DifferentApps中有明确断言cmd/argocd/commands/admin/app_test.goapp1 app2 1,9d0 conditions: null health: name: app2 ... app3 0a1,9 conditions: null ...关键参数的源码印证--ignore-normalizer-jq-execution-timeout默认 1s绑定到normalizers.IgnoreNormalizerOpts.JQExecutionTimeout。在 util/argo/normalizers/diff_normalizer.go 中定义了DefaultJQExecutionTimeout 1 * time.SecondJQ patch 执行时使用该超时jqNormalizerPatch.Applyutil/argo/normalizers/diff_normalizer.go超时则报JQ patch execution timed out。如果你的resource.exclusions/ignoreDifferences中包含较重的 JQ 表达式--refresh模式下可以适当调大该值否则比对可能因超时失败。--l标签选择器两个模式中都作为ListOptions.LabelSelector传给 Application 列表接口可用于把诊断范围缩小到某一批应用例如同一 Git 目录生成的应用集。--server-side-diff透传给AppStateManager影响CompareAppState的资源差异算法选择在 Argo CD 实例全局启用了 server-side diff 的场景下用它可以让离线重协调的口径与线上一致。测试用例给出的行为基线单元测试 cmd/argocd/commands/admin/app_test.go 固定了两条路径的行为TestGetReconcileResultsL31-L52用 fake clientset 注入一个HealthyOutOfSync的 App断言默认模式原样导出Name/Health/Sync三要素TestGetReconcileResults_RefreshL54-L126mock 了 repo-server 的GenerateManifest、LiveStateCache.GetManagedLiveObjs/GetVersionsInfo/GetClusterCache等调用验证reconcileApplications走完整比对链路后对于 manifest 与 live 对象不符的应用返回health: Missingsync: OutOfSync。这说明--refresh模式复用的正是 controller 的核心比对组件AppStateManager、LiveStateCache、repo-server manifest 生成而不是重新发明一套逻辑因此结果与线上 controller 的判定口径一致这也是该命令能做变更前后回归比对的依据。实操示例# 1) 变更前读取 controller 记录的协调状态导出快照 argocd admin app get-reconcile-results /tmp/before.yaml --kubeconfig ~/.kube/config -n argocd # 2) 变更系统中按标签只导出 dev 应用集并重新计算协调 argocd admin app get-reconcile-results /tmp/after.yaml \ --refresh \ --repo-server localhost:18081 \ -l argocd.argoproj.io/instancedev \ -o json # 3) 对比两次结果 argocd admin app diff-reconcile-results /tmp/before.yaml /tmp/after.yaml说明与适用前提命令直接访问 Kubernetes API--kubeconfig/-n指向 Argo CD 安装所在集群与命名空间--refresh还要求 kubeconfig 能访问各目标集群--refresh且未指定--repo-server时会自动对 repo-server Pod 做 port-forward需要集群内具备 port-forward 权限输出文件仅包含name/health/sync/conditions四类字段不含 manifest 级 diff如需逐资源差异请结合argocd admin app diff-reconcile-results的 unified 输出或常规argocd app diff使用。相关命令argocd admin app — 父命令管理应用配置argocd admin app diff-reconcile-results — 对两份 reconcile 结果文件做 diff是本命令的标准下游用法。【免费下载链接】argo-cdDeclarative Continuous Deployment for Kubernetes项目地址: https://gitcode.com/GitHub_Trending/ar/argo-cd创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
阅读完成 · 觉得有帮助?
咨询建站