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: Statefulset pod should change IP when recreating with a changed pool in annotation #3669

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

lou-lan
Copy link
Collaborator

@lou-lan lou-lan commented Jun 26, 2024

Fix #3543

@lou-lan lou-lan requested review from cyclinder and ty-dc June 26, 2024 09:52
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch from 21368fd to 039d17f Compare June 26, 2024 09:53
@lou-lan lou-lan changed the title Fix create pod use old ip when update StatefulSet pool name with anno… Fix Pod use old IP when update StatefulSet pool name with annotation Jun 26, 2024
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.16%. Comparing base (5566f50) to head (670dab2).
Report is 10 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3669      +/-   ##
==========================================
- Coverage   81.21%   81.16%   -0.05%     
==========================================
  Files          50       50              
  Lines        4391     4391              
==========================================
- Hits         3566     3564       -2     
- Misses        669      670       +1     
- Partials      156      157       +1     
Flag Coverage Δ
unittests 81.16% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch 2 times, most recently from b244c4b to f514448 Compare June 26, 2024 10:03
@weizhoublue
Copy link
Collaborator

need add a new E2E for this bug

@@ -70,7 +73,7 @@ func (sm *statefulSetManager) ListStatefulSets(ctx context.Context, cached bool,
// IsValidStatefulSetPod only serves for StatefulSet pod, it will check the pod whether need to be cleaned up with the given params podNS, podName.
// Once the pod's controller StatefulSet was deleted, the pod's corresponding IPPool IP and Endpoint need to be cleaned up.
// Or the pod's controller StatefulSet decreased its replicas and the pod's index is out of replicas, it needs to be cleaned up too.
func (sm *statefulSetManager) IsValidStatefulSetPod(ctx context.Context, namespace, podName, podControllerType string) (bool, error) {
func (sm *statefulSetManager) IsValidStatefulSetPod(ctx context.Context, namespace, podName, podControllerType string, endpoint *spiderpoolv2beta1.SpiderEndpoint) (bool, error) {
Copy link
Collaborator

@weizhoublue weizhoublue Jun 26, 2024

Choose a reason for hiding this comment

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

我觉得 这个 api 是 验证 pod 是否是一个有效的 statefulset pod 副本,是否在 副本数 范围内。 而 新加入的代码却使得该 函数 超出了本身的 功能定位,成为一个 非常 杂的 函数 。 它甚至 影响了 GC 等场景的IP回收场景的行为,会产生bug , 对现有代码逻辑影响比较大

新代码我建议是 独立为新一个函数来调用,如 verifyStaterfulSetPodIPValidity() , 来确认当前的 st pod 的 ip 是否是 有效的,是否符合 annotation

pkg/ipam/release.go Outdated Show resolved Hide resolved
pkg/ipam/release.go Outdated Show resolved Hide resolved
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch 3 times, most recently from 27f42c8 to 7032602 Compare June 27, 2024 09:02
@@ -98,6 +145,22 @@ func (i *ipam) Allocate(ctx context.Context, addArgs *models.IpamAddArgs) (*mode
return addResp, nil
}

func checkEndpointInPool(endpointMap, poolMap map[string]map[string]struct{}) bool {
Copy link
Collaborator

@weizhoublue weizhoublue Jun 27, 2024

Choose a reason for hiding this comment

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

这个 api 可以移动到 utils.go 下 , 然后 换个表述 可能会更好理解 函数的作用

checkNicPoolExistence( current, expected map[string]map[string]struct{} ) bool

pkg/ipam/allocate.go Outdated Show resolved Hide resolved
endpointMap[ip.NIC][*ip.IPv6Pool] = struct{}{}
}
}
if !checkEndpointInPool(endpointMap, poolMap) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

如果 不需要释放,也需要一条 debug 日志,知道 代码做了什么检查
stateful pod 的 ip (什么ip,属于什么ippool)符合当前 期望的 ippool ( ippool 打印出来), 不需要释放 ip

pkg/ipam/allocate.go Outdated Show resolved Hide resolved
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch from 7032602 to 366ae3a Compare June 27, 2024 11:41
@lou-lan lou-lan requested a review from bzsuni as a code owner June 27, 2024 11:41
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch 6 times, most recently from 9b0c489 to ee48fbc Compare June 28, 2024 02:28
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch 3 times, most recently from 38decb6 to 5d150fa Compare June 28, 2024 03:06
@weizhoublue
Copy link
Collaborator

modify the relevant doc

@lou-lan
Copy link
Collaborator Author

lou-lan commented Jun 28, 2024

need add a new E2E for this bug

A00009

pkg/ipam/allocate.go Outdated Show resolved Hide resolved
pkg/ipam/allocate.go Outdated Show resolved Hide resolved
pkg/ipam/allocate.go Outdated Show resolved Hide resolved
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch from 5d150fa to f596700 Compare June 28, 2024 06:45
@lou-lan lou-lan requested a review from windsonsea as a code owner June 28, 2024 06:45
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch from f596700 to 81f84a1 Compare June 28, 2024 06:48
pkg/ipam/allocate.go Outdated Show resolved Hide resolved
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch 3 times, most recently from a5c01a7 to e677c73 Compare June 28, 2024 08:22
@lou-lan lou-lan force-pushed the fix/inconsistent-pool-names branch from e677c73 to 670dab2 Compare June 28, 2024 08:24
@weizhoublue weizhoublue added cherrypick-release-v0.8 Cherry-pick the PR to branch release-v0.8. cherrypick-release-v0.9 labels Jun 28, 2024
@weizhoublue weizhoublue changed the title Fix Pod use old IP when update StatefulSet pool name with annotation Fix: Statefulset pod should change IP when recreating with a changed pool in annotation Jun 28, 2024
@lou-lan lou-lan enabled auto-merge June 28, 2024 09:14
@weizhoublue weizhoublue merged commit 2a50107 into main Jun 28, 2024
57 checks passed
@weizhoublue weizhoublue deleted the fix/inconsistent-pool-names branch June 28, 2024 09:50
github-actions bot pushed a commit that referenced this pull request Jun 28, 2024
Fix: Statefulset pod should change IP when recreating with a changed pool in annotation
Signed-off-by: robot <tao.yang@daocloud.io>
github-actions bot pushed a commit that referenced this pull request Jun 28, 2024
Fix: Statefulset pod should change IP when recreating with a changed pool in annotation
Signed-off-by: robot <tao.yang@daocloud.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

got unexpected IP in statefulset case
2 participants