-
Notifications
You must be signed in to change notification settings - Fork 260
Fix CNS IP demand overcounting by filtering terminal Pods in IPAMv2 #3697
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18dbd62
Initial plan for issue
Copilot 1071531
Fix CNS IP demand overcounting by filtering terminal Pods in IPAMv2
Copilot 12d2834
Fix gocritic rangeValCopy performance issue in PodIPDemandListener
Copilot 5b542a9
Implement server-side Pod filtering with indexer for status.phase
Copilot 509be35
Revert to client-side filtering strategy while keeping status.phase i…
Copilot 64a7ba1
Fix linting issues: remove trailing blank lines in modified files
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package v2 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| v1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestPodIPDemandListener(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| pods []v1.Pod | ||
| expected int | ||
| }{ | ||
| { | ||
| name: "empty pod list", | ||
| pods: []v1.Pod{}, | ||
| expected: 0, | ||
| }, | ||
| { | ||
| name: "single running pod", | ||
| pods: []v1.Pod{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod1"}, | ||
| Status: v1.PodStatus{Phase: v1.PodRunning}, | ||
| }, | ||
| }, | ||
| expected: 1, | ||
| }, | ||
| { | ||
| name: "multiple running pods", | ||
| pods: []v1.Pod{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod1"}, | ||
| Status: v1.PodStatus{Phase: v1.PodRunning}, | ||
| }, | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod2"}, | ||
| Status: v1.PodStatus{Phase: v1.PodPending}, | ||
| }, | ||
| }, | ||
| expected: 2, | ||
| }, | ||
| { | ||
| name: "mix of running and terminal pods - should exclude terminal", | ||
| pods: []v1.Pod{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod1"}, | ||
| Status: v1.PodStatus{Phase: v1.PodRunning}, | ||
| }, | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod2"}, | ||
| Status: v1.PodStatus{Phase: v1.PodSucceeded}, | ||
| }, | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod3"}, | ||
| Status: v1.PodStatus{Phase: v1.PodFailed}, | ||
| }, | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod4"}, | ||
| Status: v1.PodStatus{Phase: v1.PodPending}, | ||
| }, | ||
| }, | ||
| expected: 2, // Only pod1 (Running) and pod4 (Pending) should be counted | ||
| }, | ||
| { | ||
| name: "only terminal pods - should count zero", | ||
| pods: []v1.Pod{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod1"}, | ||
| Status: v1.PodStatus{Phase: v1.PodSucceeded}, | ||
| }, | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{Name: "pod2"}, | ||
| Status: v1.PodStatus{Phase: v1.PodFailed}, | ||
| }, | ||
| }, | ||
| expected: 0, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| ch := make(chan int, 1) | ||
| listener := PodIPDemandListener(ch) | ||
|
|
||
| listener(tt.pods) | ||
|
|
||
| select { | ||
| case result := <-ch: | ||
| if result != tt.expected { | ||
| t.Errorf("expected %d, got %d", tt.expected, result) | ||
| } | ||
| default: | ||
| t.Error("expected value in channel") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.