Skip to content

<feat>[lb]: add IPVS DR/FullNAT load balancer support#3847

Open
MatheMatrix wants to merge 1 commit into5.5.16from
sync/shixin.ruan/shixin.ruan-ZSTAC-84610@@3
Open

<feat>[lb]: add IPVS DR/FullNAT load balancer support#3847
MatheMatrix wants to merge 1 commit into5.5.16from
sync/shixin.ruan/shixin.ruan-ZSTAC-84610@@3

Conversation

@MatheMatrix
Copy link
Copy Markdown
Owner

A1-A3: Add IPVS_MODE constants, IPVS_MODE PatternedSystemTag on
LoadBalancerListenerVO, and IPVS_DEFAULT_MODE/SCHEDULER GlobalConfig
A4: ValidateIpvsMode() in LoadBalancerApiInterceptor — enforces LB-wide
mode consistency, rejects L7 tags, whitelists scheduler algorithms,
skips MAX_CONNECTION/CONNECTION_IDLE_TIMEOUT auto-inserts for IPVS
A5-A6: Extend LbTO with ipvsMode/scheduler/connectionType fields;
populate from IPVS_MODE systemTag in makeLbTOs()
C1: Add bindToLo field to VyosKeepalivedCommands.VyosHaVip (@GrayVersion 5.5.16)

Resolves: ZSTAC-84610

Change-Id: I15d1ec49aacb2de818d71a50900c9e7440fb77a2

sync from gitlab !9718

A1-A3: Add IPVS_MODE constants, IPVS_MODE PatternedSystemTag on
       LoadBalancerListenerVO, and IPVS_DEFAULT_MODE/SCHEDULER GlobalConfig
A4: ValidateIpvsMode() in LoadBalancerApiInterceptor — enforces LB-wide
    mode consistency, rejects L7 tags, whitelists scheduler algorithms,
    skips MAX_CONNECTION/CONNECTION_IDLE_TIMEOUT auto-inserts for IPVS
A5-A6: Extend LbTO with ipvsMode/scheduler/connectionType fields;
       populate from IPVS_MODE systemTag in makeLbTOs()
C1: Add bindToLo field to VyosKeepalivedCommands.VyosHaVip (@GrayVersion 5.5.16)

Resolves: ZSTAC-84610

Change-Id: I15d1ec49aacb2de818d71a50900c9e7440fb77a2
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

总览

本次变更为负载均衡器添加IPVS(IP虚拟服务器)模式配置支持,包括模式验证、全局配置、系统标签定义、以及虚拟路由转移对象的IPVS字段扩展。

变更详情

内聚体 / 文件 摘要
IPVS验证与配置
plugin/loadBalancer/.../LoadBalancerApiInterceptor.java
添加validateIpvsMode方法进行IPVS一致性验证,包括模式混用检查、协议限制(仅TCP/UDP)、系统标签兼容性检查、平衡算法约束。创建监听器时从系统标签获取或应用默认IPVS模式,条件性自动添加超时/连接标签。
IPVS常量与配置
plugin/loadBalancer/.../LoadBalancerConstants.java, plugin/loadBalancer/.../LoadBalancerGlobalConfig.java, plugin/loadBalancer/.../LoadBalancerSystemTags.java
引入IPVS模式常量(DR、FULLNAT)、调度器映射、允许的平衡算法列表、全局默认模式和调度器配置、ipvsMode::{ipvsMode}系统标签定义。
虚拟路由传输对象扩展
plugin/virtualRouterProvider/.../VirtualRouterLoadBalancerBackend.java
LbTO类添加IPVS配置字段(ipvsModeschedulerconnectionType),从系统标签读取IPVS模式,映射平衡算法至IPVS调度器,根据模式设置连接类型。
VyOS配置增强
plugin/virtualRouterProvider/.../VyosKeepalivedCommands.java
VyosHaVip添加bindToLo布尔标志(灰度版本5.5.16),扩展VyOS HA VIP命令/响应模型。

代码审查难度估计

🎯 3 (中等) | ⏱️ ~25 分钟

诗歌

🐰 IPVS的梦想绽放,
模式验证层层把关,
TCP与UDP欢唱,
虚拟路由齐绽放,
均衡艺术跃上新舞台。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows the required [scope]: format with 'feat' type, 'lb' scope, and clear description about IPVS DR/FullNAT support. At 53 characters, it is well under the 72-character limit.
Description check ✅ Passed The PR description directly relates to the changeset, detailing IPVS mode constants, system tags, global config entries, validation logic, and field extensions. It clearly summarizes the key changes and references the JIRA issue ZSTAC-84610.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/shixin.ruan/shixin.ruan-ZSTAC-84610@@3

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerApiInterceptor.java`:
- Around line 1312-1325: The update currently calls validateIpvsMode() only when
an IPVS_MODE tag is present in msg.getSystemTags(), which misses cases where a
listener already using IPVS changes other tags or when switching a non-IPVS
listener to IPVS because persisted listener tags (maxConnection,
connectionIdleTimeout, session*, etc.) aren’t considered; fix by loading the
existing listener’s persisted system tags and current ipvsMode (via the
LoadBalancerListenerVO query used to get protocol), merge those persisted tags
with msg.getSystemTags() to produce an effective tag set and determine the
effective ipvsMode, then call validateIpvsMode(loadBalancerUuid,
effectiveIpvsMode, protocol, mergedTags, null,
msg.getLoadBalancerListenerUuid()) so all historical and new tags are validated
together before applying the update.

In
`@plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerGlobalConfig.java`:
- Around line 39-43: 限制全局配置 IPVS 默认值的取值范围:为 GlobalConfig IPVS_DEFAULT_MODE 和
IPVS_DEFAULT_SCHEDULER 增加严格校验,确保 IPVS_DEFAULT_MODE 只接受
LoadBalancerConstants.IPVS_MODES 中定义的值,IPVS_DEFAULT_SCHEDULER 只接受集合
{"rr","wrr","lc","sh"};在其 GlobalConfigValidation 的实现或注册点(与 IPVS_DEFAULT_MODE /
IPVS_DEFAULT_SCHEDULER 声明相近的校验器)添加检查逻辑并在不符合时拒绝/报错,避免非法字符串被写入后由
VirtualRouterLoadBalancerBackend.mapBalancerAlgorithmToIpvsScheduler 或 listener
创建时才失败。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 5f6afb7c-76ba-4f59-9acc-e71d1b4da8a8

📥 Commits

Reviewing files that changed from the base of the PR and between c8d25fd and 6dba6eb.

⛔ Files ignored due to path filters (1)
  • conf/globalConfig/lb.xml is excluded by !**/*.xml
📒 Files selected for processing (6)
  • plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerApiInterceptor.java
  • plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerConstants.java
  • plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerGlobalConfig.java
  • plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerSystemTags.java
  • plugin/virtualRouterProvider/src/main/java/org/zstack/network/service/virtualrouter/lb/VirtualRouterLoadBalancerBackend.java
  • plugin/virtualRouterProvider/src/main/java/org/zstack/network/service/virtualrouter/vyos/VyosKeepalivedCommands.java

Comment on lines +1312 to +1325
// Validate ipvsMode consistency if the update carries a new ipvsMode tag
String newIpvsMode = null;
for (String tag : msg.getSystemTags()) {
if (LoadBalancerSystemTags.IPVS_MODE.isMatch(tag)) {
newIpvsMode = LoadBalancerSystemTags.IPVS_MODE.getTokenByTag(tag, LoadBalancerSystemTags.IPVS_MODE_TOKEN);
}
}
if (newIpvsMode != null) {
String protocol = Q.New(LoadBalancerListenerVO.class)
.select(LoadBalancerListenerVO_.protocol)
.eq(LoadBalancerListenerVO_.uuid, msg.getLoadBalancerListenerUuid())
.findValue();
validateIpvsMode(loadBalancerUuid, newIpvsMode, protocol, msg.getSystemTags(), null, msg.getLoadBalancerListenerUuid());
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

更新 listener 时的 IPVS 校验还不完整。

这里仅在请求里显式带了 IPVS_MODE tag 时才调用 validateIpvsMode(),而且传进去的是 msg.getSystemTags()。这会漏掉两类场景:1)一个已经是 IPVS 的 listener 只改 balancerAlgorithm,不会再走 IPVS 白名单校验;2)把现有非 IPVS listener 切到 IPVS 时,库里已经存在的 maxConnection / connectionIdleTimeout / session* 等历史 tag 不会被检查。后面 plugin/virtualRouterProvider/src/main/java/org/zstack/network/service/virtualrouter/lb/VirtualRouterLoadBalancerBackend.javamakeLbTOs() 仍会把这些旧 tag 放进 parameters 下发,最终形成非法组合。建议这里先读取当前 listener 的持久化 tags 和当前 ipvsMode,合并出一份 effective 配置后再统一做校验。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerApiInterceptor.java`
around lines 1312 - 1325, The update currently calls validateIpvsMode() only
when an IPVS_MODE tag is present in msg.getSystemTags(), which misses cases
where a listener already using IPVS changes other tags or when switching a
non-IPVS listener to IPVS because persisted listener tags (maxConnection,
connectionIdleTimeout, session*, etc.) aren’t considered; fix by loading the
existing listener’s persisted system tags and current ipvsMode (via the
LoadBalancerListenerVO query used to get protocol), merge those persisted tags
with msg.getSystemTags() to produce an effective tag set and determine the
effective ipvsMode, then call validateIpvsMode(loadBalancerUuid,
effectiveIpvsMode, protocol, mergedTags, null,
msg.getLoadBalancerListenerUuid()) so all historical and new tags are validated
together before applying the update.

Comment on lines +39 to +43
@GlobalConfigValidation
public static GlobalConfig IPVS_DEFAULT_MODE = new GlobalConfig(CATEGORY, "ipvs.defaultMode");

@GlobalConfigValidation
public static GlobalConfig IPVS_DEFAULT_SCHEDULER = new GlobalConfig(CATEGORY, "ipvs.defaultScheduler");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

请在全局配置层限制 IPVS 默认值的取值范围。

这里的校验还不够强:ipvs.defaultScheduler 现在可以被写成任意字符串,而 plugin/virtualRouterProvider/src/main/java/org/zstack/network/service/virtualrouter/lb/VirtualRouterLoadBalancerBackend.javamapBalancerAlgorithmToIpvsScheduler() 会直接把它当 fallback 下发给 VR;ipvs.defaultMode 也会在创建 listener 时才迟到失败。建议把这两个配置收敛到明确的允许集合(LoadBalancerConstants.IPVS_MODESrr/wrr/lc/sh),避免坏配置先落库、再在运行时爆出来。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@plugin/loadBalancer/src/main/java/org/zstack/network/service/lb/LoadBalancerGlobalConfig.java`
around lines 39 - 43, 限制全局配置 IPVS 默认值的取值范围:为 GlobalConfig IPVS_DEFAULT_MODE 和
IPVS_DEFAULT_SCHEDULER 增加严格校验,确保 IPVS_DEFAULT_MODE 只接受
LoadBalancerConstants.IPVS_MODES 中定义的值,IPVS_DEFAULT_SCHEDULER 只接受集合
{"rr","wrr","lc","sh"};在其 GlobalConfigValidation 的实现或注册点(与 IPVS_DEFAULT_MODE /
IPVS_DEFAULT_SCHEDULER 声明相近的校验器)添加检查逻辑并在不符合时拒绝/报错,避免非法字符串被写入后由
VirtualRouterLoadBalancerBackend.mapBalancerAlgorithmToIpvsScheduler 或 listener
创建时才失败。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants