Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CLUSTER_DNS_SVC_IP & CLUSTER_KUBERNETES_SVC_IP ip concat error #1421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yunpiao
Copy link

@yunpiao yunpiao commented Nov 8, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

修复了在 CLUSTER_DNS_SVC_IP 和 CLUSTER_KUBERNETES_SVC_IP 中,处理超出 /24 子网掩码时 IP 地址获取错误的问题。在某些情况下,当 CIDR 超过 /24 时,最后一个八位字节的 IP 地址解析不正确,导致 IP 获取失败。

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

这个修复解决了超出 /24 子网掩码时,IP 地址计算错误的问题。特别是 /25、/26 等子网掩码时,CIDR 后缀(如 /25)被去除,确保只获取纯 IP 地址并正确计算偏移。


@gjmzj
Copy link
Collaborator

gjmzj commented Nov 12, 2024

能否具体给个例子,说明原来的配置方式可能产生错误的情况

@yunpiao
Copy link
Author

yunpiao commented Nov 14, 2024

举例说明 当 SERVICE_CIDR = 100.64.192.192/25 时,SERVICE_CIDR.split('.')[3] 会得到 192/25,这不是纯数字,直接转换为整数会错误解析为 0, 也就是 100.64.192.0 + 1 或者 +2, 造成 dns ip 和 cluster ip 获取异常 。

修复方法:用 regex_replace('/.*', '') 去掉 CIDR 部分 /25,确保只获取 192,然后再加上偏移量 1 或者 2。这样就能正确生成 IP 地址 100.64.192.194。

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