已开启
fix(controller): cleanup per-model ClusterRole/ClusterRoleBinding on deletion #258
fix(controller): cleanup per-model ClusterRole/ClusterRoleBinding on deletion #258
已开启
luochen01创建于 9月29日
luochen01
luochen01
9月29日

关联 Issue

Closes #174

问题

删除 PD 分离模式的推理实例后,InferNex-Bridge 为各组件控制器创建的 per-model
ClusterRole / ClusterRoleBinding 未被清理,永久残留,导致集群垃圾累积,且权限未回收,易构成安全隐患。

根因

ClusterRole / ClusterRoleBinding 是 cluster-scoped 资源,无法设置 namespaced 的
ownerReference,因此 K8s GC 不会级联删除;而删除路径 reconcileInferNexServiceDeletion
只清理了 Gateway 路由与 singleton SA 的 owner refs,没有调用
syncComponentControllerRBACCleanup(该清理仅存在于正常 reconcile 的 prune 路径)。

修复

在 reconcileInferNexServiceDeletion 中、移除 finalizer 之前,通过
releaseSingletonOwnerReferences 显式清理 per-model 的 cluster-scoped RBAC:
该函数委托给 syncComponentControllerRBACCleanup(ctx, infsvc, nil),会逐个删除
ClusterRole / ClusterRoleBinding(幂等,NotFound 忽略),并释放共享 singleton
ServiceAccount 的 owner refs、清理 leader Role/RoleBinding 与 webhook 证书 Secret。

测试

  • go test ./internal/controller/ 全部通过
  • 为 gatewayTestScheme 注册 rbacv1,覆盖删除路径的 RBAC 清理
likedislike
合并受阻
luochen01luochen01
9月29日 关联了issue:InferNex-Bridge:删除推理实例后遗留 per-model ClusterRole / ClusterRoleBinding 未清理
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:sig/sig-ai-inference
openFuyao-bot
openFuyao-bot成员
9月29日 评论:

欢迎来到 openFuyao 社区

Hey @luochen01 , 感谢你对社区的贡献.

机器人使用手册

有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。您可以自助配置此仓库的 PR 合并规则,更多详情,请参阅此处。

联系指引

有疑问可以联系 SIG: sig-ai-inference ,
维护者是: @foxbit, @regandy ,
审核者是: @ShiroChen, @piamposer-li, @qinwenzh .

likedislike
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:openFuyao-cla/no
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:ci-running
openFuyao-bot
openFuyao-bot成员
9月29日 评论:

PR 合入 Checklist

代码评审报告

摘要

本次变更修复了 PD 分离模式推理实例删除后 per-model ClusterRole/ClusterRoleBinding 未清理的问题,通过调用 syncComponentControllerRBACCleanup 显式清理 cluster-scoped RBAC 资源。变更范围小、逻辑清晰,建议合入。

主要变更

  • component/InferNex-Bridge/internal/controller/infernexservice_controller.go:在删除路径中将 releaseSingletonOwnerReferences 调用替换为 syncComponentControllerRBACCleanup,并更新注释说明 cluster-scoped RBAC 的清理逻辑;移除已冗余的 releaseSingletonOwnerReferences 函数。
  • component/InferNex-Bridge/internal/controller/infernexservice_gateway_route_reconcile_test.go:为测试 scheme 添加 rbacv1 注册,确保删除路径的 RBAC 清理逻辑可正确测试。

优点

  • 精准定位根因:cluster-scoped 资源无法通过 ownerReference 级联删除,需在 finalizer 移除前显式清理。
  • 复用现有函数 syncComponentControllerRBACCleanup,避免重复代码。
  • 注释清晰解释了为何需要显式清理以及为何无需单独调用 releaseSingletonOwnerReferences。
  • 同步更新测试 scheme,保证测试覆盖。

问题

未发现需要计入评分的问题。

已说明项

  • [原轻微] - 测试覆盖范围:当前仅添加 rbacv1 scheme 注册,未直接验证 RBAC 清理行为。PR 作者说明 go test ./internal/controller/ 全部通过,且本次变更主要是修复而非功能新增,可接受。

量化评分

项 值
综合得分 100 / 100
未处理问题 严重 0 / 重要 0 / 轻微 0
决策 通过

AI 生成信息

项 值
辅助工具 Claude
模型 openPangu 2.0 Flash

使用 gitcode-pr-review skill 生成。

该评审结果仅供参考。

likedislike
openFuyao-botopenFuyao-bot成员
9月29日 删除了label:ci-running
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:ci-failed
luochen01luochen01
9月29日 强制推送  3 个提交:bdeb7ea9-2 commits from branch master,cef35cc2-fix(controller): cleanup per-model ClusterRole/ClusterRoleBinding on deletion
openFuyao-botopenFuyao-bot成员
9月29日 删除了label:ci-failed
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:ci-running
luochen01
luochen01
9月29日 评论:

/check-cla

likedislike
openFuyao-botopenFuyao-bot成员
9月29日 删除了label:openFuyao-cla/no
此处折叠了5条事件消息 查看更多
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:openFuyao-cla/yes
openFuyao-bot
openFuyao-bot成员
9月29日 评论:

CLA 签署成功

luochen01, 感谢您的代码贡献。 所有的代码贡献者都已完成了 CLA 签署。 👍

likedislike
openFuyao-botopenFuyao-bot成员
9月29日 删除了label:ci-failed
此处折叠了5条事件消息 查看更多
luochen01luochen01
9月30日 修改了pull request 的描述