04/27 所有RKE2集群rancher web页面均出现Cluster agent is not connected

环境信息:

  • RKE2 版本: v1.31.2+rke2r1
  • Rancher 版本: v2.8.5 / v2.10.x
  • 节点 CPU 架构,操作系统和版本: amd64, Ubuntu 22.04 LTS / Ubuntu 18.04 LTS
  • 集群配置: 3 server (control-plane) + 多 agent (worker) 节点高可用架构

问题描述:

在多个 RKE2 集群中,cattle-cluster-agent Pod 突然进入 CrashLoopBackOff 状态,导致 Rancher UI 持续显示 [Waiting] configuring bootstrap node(s) ... waiting for cluster agent to connect。经排查,该崩溃由 Agent 内部的 Helm 仓库同步控制器 (repoHandler) 在解析/排序 ClusterRepoindex.yaml 时触发空指针异常 (nil pointer dereference) 所致。此问题阻断了下游集群向 Rancher 管理平面的心跳注册与状态上报。

重现步骤:

  1. 通过 Helm 部署 Rancher (v2.8.5v2.10.x)。
  2. 使用 Rancher 创建或导入 RKE2 集群 (v1.31.2+rke2r1),拓扑为 3 Master + 多 Node。
  3. 在集群中配置一个或多个 ClusterRepo (Helm 应用商店仓库),且该仓库的 index.yaml 包含格式不规范的数据(如缺失 version 字段、元数据为 null 或版本列表结构异常)。
  4. 等待 cattle-cluster-agent 触发 Catalog 同步任务。
  5. 观察 cattle-cluster-agent Pod 日志,确认出现 Helm 版本排序时的 Go Panic。

预期结果:
attle-cluster-agent 应具备容错机制。当遇到格式异常的 Helm 仓库索引时,应记录 Warning/Event 并跳过该仓库,保持 Pod 正常运行,确保集群管理通道持续可用

实际结果:

cattle-cluster-agent 直接 Panic 崩溃,进入无限重启循环。Rancher UI 无法获取集群状态,所有通过 UI 下发的集群操作均被阻塞。核心堆栈指向:

panic: runtime error: invalid memory address or nil pointer dereference
helm.sh/helm/v3/pkg/repo.ChartVersions.Less(...)
github.com/rancher/rancher/pkg/controllers/dashboard/helm.(*repoHandler).download(...)
日志
time="2026-04-27T10:32:04Z" level=info msg="Updating TLS secret for cattle-system/serving-cert (count: 32): ..."
E0427 10:32:05.276397      56 runtime.go:79] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 1247 [running]:
k8s.io/apimachinery/pkg/util/runtime.logPanic({0x40e5600?, 0x8373380})
        /go/pkg/mod/k8s.io/apimachinery@v0.28.6/pkg/util/runtime/runtime.go:75 +0x85
...
helm.sh/helm/v3/pkg/repo.ChartVersions.Less({0xc00e0b3000, 0x65, 0x32?}, 0x19?, 0x64)
        /go/pkg/mod/github.com/rancher/helm/v3@v3.13.3-rancher1/pkg/repo/index.go:74 +0x76
sort.reverse.Less(...)
        /usr/lib64/go/1.21/src/sort/sort.go:93
...
github.com/rancher/rancher/pkg/controllers/dashboard/helm.(*repoHandler).download(_, _, {0x1, {0xc006d1cd80, 0x2b}, {0xc000fc7e30, 0xd}, {0x0, 0x0}, {{0x0, ...}}, ...}, ...)
        /go/src/github.com/rancher/rancher/pkg/controllers/dashboard/helm/repo.go:238 +0x5d7
github.com/rancher/rancher/pkg/controllers/dashboard/helm.(*repoHandler).ClusterRepoDownloadStatusHandler(_, _, {0x1, {0xc006d1cd80, 0x2b}, {0xc000fc7e30, 0xd}, {0x0, 0x0}, {{0x0, ...}}, ...})
        /go/src/github.com/rancher/rancher/pkg/controllers/dashboard/helm/repo.go:91 +0x214
...
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x1b24556]

临时规避方案 (Workaround): 删除触发解析异常的 Helm 仓库资源后,Agent 可立即恢复:

kubectl delete clusterrepos --all --ignore-not-found=true
kubectl rollout restart deployment cattle-cluster-agent -n cattle-system
1 个赞