Skip to content

修复vip无法正常固定ip#5865

Merged
oilbeater merged 2 commits intokubeovn:masterfrom
lfpython:master
Nov 5, 2025
Merged

修复vip无法正常固定ip#5865
oilbeater merged 2 commits intokubeovn:masterfrom
lfpython:master

Conversation

@lfpython
Copy link
Copy Markdown
Contributor

@lfpython lfpython commented Nov 5, 2025

Pull Request

What type of this PR

Examples of user facing changes:

  • Bug fixes

当vip.spec.MacAddress地址为空的时候,这里的指针并不是nil,导致后续mac地址分配出现问题;
我增加了mac地址是否等于空字符串的判断,只有当不是空串的时候才会给指针赋值。

Which issue(s) this PR fixes

Fixes #5861

Signed-off-by: lfpython <1173288857@qq.com>
Signed-off-by: lfpython <1173288857@qq.com>
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 5, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @lfpython, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决Kube-OVN中VIP(虚拟IP)的MAC地址分配逻辑中的一个缺陷。通过引入对 vip.Spec.MacAddress 是否为空字符串的显式检查,确保了MAC地址指针的正确初始化,从而避免了在特定情况下因指针指向空字符串而导致的MAC地址分配失败,提升了VIP功能的稳定性。

Highlights

  • VIP MAC地址分配: 修复了当 vip.Spec.MacAddress 为空字符串时,MAC地址指针被错误赋值导致后续MAC地址分配异常的问题。现在只有当 vip.Spec.MacAddress 不为空时,才会将指针指向该地址。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the bug Something isn't working label Nov 5, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @lfpython, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在修复一个关键的错误,该错误导致虚拟IP(VIP)在指定MAC地址为空字符串时无法正确分配固定IP。通过引入一个明确的空字符串检查,确保了MAC地址指针的正确处理,从而恢复了VIP的预期功能。

Highlights

  • 修复VIP固定IP分配问题: 解决了当vip.Spec.MacAddress为空字符串时,其指针不为nil导致MAC地址分配异常的bug。现在只有当MacAddress不为空字符串时,才会将其赋值给macPointer
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @lfpython, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在修复一个关键的错误,该错误导致在vip.Spec.MacAddress字段为空时,虚拟IP(VIP)无法正确地固定其MAC地址。通过引入一个额外的检查,确保仅在MAC地址明确指定且非空时才将其用于分配,从而提高了系统在处理VIP资源时的健壮性和准确性。

Highlights

  • 修复VIP固定IP问题: 解决了当vip.Spec.MacAddress为空字符串时,MAC地址分配出现异常的bug。
  • 改进MAC地址处理逻辑: 在为macPointer赋值前,增加了对vip.Spec.MacAddress是否为空字符串的判断,避免了将空字符串地址作为有效指针处理。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 修复了当 VIP 的 MAC 地址为空时,无法正确分配固定 IP 的问题。修改的核心逻辑是增加了一个检查,确保只有在 vip.Spec.MacAddress 不为空字符串时,才会为 macPointer 赋值。这个修复是正确且有效的。我在代码中提供了一个关于如何简化逻辑以提高可读性的建议,但这不影响当前修复的正确性。

Comment thread pkg/controller/vip.go
Comment on lines 105 to 109
if ipStr != "" || vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
if vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
}
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

此处的逻辑是正确的,成功修复了当 vip.Spec.MacAddress 为空字符串时 macPointer 不为 nil 的问题。

不过,为了提高代码的可读性,可以考虑重构这部分逻辑,避免使用嵌套的 if 语句。可以将 macPointer 的赋值操作提前,然后使用一个新的条件来判断是进行静态分配还是随机分配。这样可以让代码结构更清晰。

例如,可以这样修改:

if vip.Spec.MacAddress != "" {
    macPointer = &vip.Spec.MacAddress
}

if ipStr != "" || macPointer != nil {
    v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
} else {
    // Random allocate
    v4ip, v6ip, mac, err = c.acquireIPAddress(subnet.Name, vip.Name, portName)
}

当然,这只是一个优化建议,当前的代码已经可以正常工作。

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 修复了当 vip.spec.MacAddress 为空字符串时,macPointer 仍然被赋值导致后续 MAC 地址分配出错的问题。修改通过增加一个检查,确保只在 vip.spec.MacAddress 非空时才为 macPointer 赋值,从而解决了该 bug。代码逻辑正确,但可以稍微简化以提高可读性。

Comment thread pkg/controller/vip.go
Comment on lines 105 to 109
if ipStr != "" || vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
if vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
}
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

这部分代码的逻辑是正确的,成功修复了 bug。不过,嵌套的 if 语句可以简化,以提高代码的可读性。可以将内部的 if 条件合并到外部,使代码更简洁。

if vip.Spec.MacAddress != "" {
	macPointer = &vip.Spec.MacAddress
}
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

您好,感谢您对项目的贡献。本次变更是为了修复当 vip.spec.MacAddress 为空字符串时,macPointer 被错误地赋予一个非 nil 的指针,从而导致后续 MAC 地址分配失败的问题。您的修复是有效的,通过增加一个检查来确保只有在 vip.spec.MacAddress 非空时才为 macPointer 赋值。我有一个小的重构建议,可以让代码逻辑更清晰一些,但您当前的实现已经解决了问题。做得很好!

Comment thread pkg/controller/vip.go
Comment on lines 105 to 109
if ipStr != "" || vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
if vip.Spec.MacAddress != "" {
macPointer = &vip.Spec.MacAddress
}
v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

这部分代码的逻辑是正确的,成功修复了问题。不过,通过一个小重构可以使代码更简洁易读。当前的嵌套 if 语句有些冗余。我们可以先处理 macPointer 的赋值,然后再用一个 if-else 块来决定是调用 acquireStaticIPAddress 还是 acquireIPAddress。这样可以使逻辑分离更清晰。

 	if vip.Spec.MacAddress != "" {
 		macPointer = &vip.Spec.MacAddress
 	}

	if ipStr != "" || macPointer != nil {
		v4ip, v6ip, mac, err = c.acquireStaticIPAddress(subnet.Name, vip.Name, portName, ipStr, macPointer)
	} else {
		// Random allocate
		v4ip, v6ip, mac, err = c.acquireIPAddress(subnet.Name, vip.Name, portName)
	}

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 5, 2025
@oilbeater oilbeater merged commit a19f92e into kubeovn:master Nov 5, 2025
74 checks passed
@lfpython
Copy link
Copy Markdown
Contributor Author

lfpython commented Dec 5, 2025

@zbb88888 为什么这个没有更新

@zbb88888
Copy link
Copy Markdown
Collaborator

zbb88888 commented Dec 5, 2025

@lfpython 大佬,你说的更新是指回合到 1.14 么?

zbb88888 pushed a commit that referenced this pull request Dec 5, 2025
* 修复vip无法正常固定ip

Signed-off-by: lfpython <1173288857@qq.com>

* 修改代码缩进

Signed-off-by: lfpython <1173288857@qq.com>

---------

Signed-off-by: lfpython <1173288857@qq.com>
@zbb88888
Copy link
Copy Markdown
Collaborator

zbb88888 commented Dec 5, 2025

已回合到 1.14

@lfpython
Copy link
Copy Markdown
Contributor Author

lfpython commented Dec 8, 2025

@zbb88888 你看一下已经发版的1.14.18呢,这里代码还是原来的,并没有更新

@zbb88888
Copy link
Copy Markdown
Collaborator

zbb88888 commented Dec 8, 2025

image image

@lfpython 可以看到,再发版之后回合的。需要等下一次发版了。如果急的话, 可以考虑自己发一个版本或者从 docker hub 下载1.14.19-x86后缀的镜像

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

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] vip type 非slb无法固定ip创建

3 participants