已合并
[bugfix] deployer NodePort 冲突检测:CRD 重命名 Service 误判导致扩缩容失败 #776
[bugfix] deployer NodePort 冲突检测:CRD 重命名 Service 误判导致扩缩容失败 #776
已合并
杨安创建于 3 天前
杨安
杨安成员
3 天前

问题

服务部署成功后执行 --update_instance_num 扩缩容,NodePort 冲突检测会把本服务自己占用的端口判为冲突,导致交互改端口或报冲突,扩缩容拉不起来。

Related Issue:https://gitcode.com/Ascend/MindIE-Motor/issues/506

根因

_is_self_owned 只认「同 namespace + Service 名完全相同」。但 InferServiceSet 模式下 CRD 会重命名 Service:

{service_name}-{InferServiceSet 名}-{索引}-{role}
例:mindie-motor-coordinator-infer -> mindie-motor-coordinator-infer-vllm-0-coordinator

集群里的实际名字与生成 yaml 中声明的短名永远不相等,自有端口因此被误判为他人占用。首次部署时集群还没有这些端口,检测通过,问题只在重复部署 / 扩缩容时暴露。

修改

  • PlannedNodePort 增加 infer_set_name / role_name,解析 InferServiceSet 时记录 CRD 上下文
  • _is_self_owned 在名字完全相同之外,额外匹配 CRD 命名规则;索引用 \\d+ 而非写死 -0-,兼容 InferServiceSet 副本数大于 1
  • 跨 namespace 判断不变,他人占用的端口仍正常报冲突
  • README 补充自有端口与 CRD 命名说明

测试

tests/examples/deployer/test_nodeport_allocator.py 新增 1 条端到端用例:模拟服务已运行、三个 NodePort 均被本服务的 CRD Service 占用,断言不弹窗、不改写端口。

用例强制 sys.stdin.isatty() 为 True 走交互路径,修复被回退时会因弹窗而失败;其中一个 Service 使用非 0 索引,覆盖副本数大于 1 的命名。

likedislike
Pull Request已成功合入, 合并人@wangyang
(感谢 杨安 的贡献)
atomgit-bot
atomgit-bot
3 天前 评论:

变更摘要

本 PR 修复 InferServiceSet 模式下部署器 NodePort 冲突检测的误判问题:由于 CRD 会将 Service 重命名为 {service_name}-{InferServiceSet 名}-{索引}-{role},集群中的实际名字与 yaml 中声明的短名永远不相等,导致 _is_self_owned 把本服务自占的端口误判为他人占用,进而使 --update_instance_num 扩缩容失败。改动为 PlannedNodePort 增加 CRD 上下文字段,并让 _is_self_owned 在名字完全相同之外额外匹配 CRD 命名规则,同时保持跨 namespace 的冲突判定不变。

主要改动

  • PlannedNodePort 增加 CRD 上下文字段: 在 examples/deployer/lib/nodeport_allocator.py 中为 PlannedNodePort 新增 infer_set_namerole_name 两个可选字段,并在 _planned_from_service_spec_collect_from_infer_service_set 解析 InferServiceSet 时从 metadata 与 role 上下文填充这两个字段。
  • 新增 _matches_crd_service_name 自有端口匹配: 新增函数按 {service_name}-{infer_set_name}-\d+-{role_name} 正则(索引用 \d+,兼容副本数大于 1)匹配 CRD 重命名后的集群 Service 名;_is_self_owned 在 namespace 相同且名字完全相等之外,增加对该命名规则的匹配,跨 namespace 的他人占用仍照常判为冲突。
  • 新增冲突检测测试用例: 在 tests/examples/deployer/test_nodeport_allocator.py 中新增 3 条测试,覆盖 CRD 重命名的自有端口不算冲突、同名端口在其他 namespace 仍判冲突,以及完整 resolve_and_rewrite_nodeports 扩缩容场景下不弹窗、三个端口均不被改写。
  • README 补充说明: 按 PR 描述在 README 中补充自有端口判定与 CRD 命名规则的说明。
likedislike
atomgit-bot
atomgit-bot
3 天前 评论:

代码审查

审查完成。最终汇总:

审查结论

逐文件确认

examples/deployer/lib/nodeport_allocator.py — 已审查。核心改动(PlannedNodePort 新增 infer_set_name/role_name 字段、_planned_from_service_spec/_collect_from_infer_service_set 透传、_matches_crd_service_name 正则、_is_self_owned 增加 CRD 模式匹配)逻辑自洽:正则各段均 re.escape、字段顺序与 CRD 文档化命名 {svc}-{infer_set}-{index}-{role} 一致、跨 namespace 判断保持正确、跨 InferServiceSet 前缀(vllm vs vllm2/vllm-1)不会交叉误匹配、新字段/参数对既有调用向后兼容。报告 2 条 P3 问题(见下)。

tests/examples/deployer/test_nodeport_allocator.py — 已审查。3 条新增测试内部一致、可正确通过(包括完整 resolve_and_rewrite_nodeports 扩缩容场景的 mock 与断言);无独立缺陷。仅作为缺失用例的方向并入第 2 条发现。

发现统计

  • P0:0
  • P1:0
  • P2:0
  • P3:2(低置信度)
    1. nodeport_allocator.py:318-327 — 自有权判定仅凭名称模式匹配、无归属(ownerReferences/标签)校验,同 namespace 下名称恰好符合 CRD 规则的非自有 Service 占用同一端口时,真实冲突会被静默掩盖。
    2. nodeport_allocator.py:325 — PR 核心声称的 \d+(副本数>1 兼容)无任何非 0 索引测试用例,索引模式回归(-0-/\d)时现有测试全部无法拦截。

总体风险判断

本次改动正确解决了「CRD 重命名 Service 导致自有端口被误判为冲突」这一核心问题,修复逻辑本身精确、向后兼容、测试覆盖了主要路径,未发现 P0–P2 级别缺陷。剩余风险为低概率的名称模式误匹配(他人端口被静默放行)以及副本数>1 场景缺少回归测试,均属低风险、可后续加固项,整体可合入。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
ascend-robotascend-robot成员
3 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
3 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/MindIE-Motor 吕有辉, 王洋 (2/2) 吕有辉 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

mindie_yangan, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
3 天前 添加了label:ci-pipeline-running
此处折叠了59条消息 查看更多
ascend-robotascend-robot成员
3 天前 添加了label:approved
wangyang
wangyang成员
3 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
3 天前 添加了label:lgtm
wangyangwangyang成员
3 天前 关闭了关联的issue
wangyangwangyang成员
3 天前 合入了pull request