Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pkg/controllers/disruption/consolidation_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,44 @@ func mockCandidate(name string) *Candidate {
}
}

func TestLogValues_PodCount(t *testing.T) {
// Create candidates with different numbers of reschedulable pods
c1 := mockCandidate("node-1")
c1.NodeClaim = &v1.NodeClaim{ObjectMeta: metav1.ObjectMeta{Name: "nc-1"}}
c1.reschedulablePods = []*corev1.Pod{
{ObjectMeta: metav1.ObjectMeta{Name: "pod-1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod-2"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod-3"}},
}

c2 := mockCandidate("node-2")
c2.NodeClaim = &v1.NodeClaim{ObjectMeta: metav1.ObjectMeta{Name: "nc-2"}}
c2.reschedulablePods = []*corev1.Pod{
{ObjectMeta: metav1.ObjectMeta{Name: "pod-4"}},
{ObjectMeta: metav1.ObjectMeta{Name: "pod-5"}},
}

cmd := Command{
Candidates: []*Candidate{c1, c2},
Replacements: []*Replacement{},
}

logValues := cmd.LogValues()
// LogValues returns key-value pairs: find the "pod-count" key and check its value
var podCount int
for i := 0; i < len(logValues)-1; i += 2 {
if logValues[i] == "pod-count" {
podCount = logValues[i+1].(int)
break
}
}

// pod-count should be 3 + 2 = 5, not just 2 (the last candidate's count)
if podCount != 5 {
t.Errorf("LogValues() pod-count = %d, want 5 (sum of all candidates' pods)", podCount)
}
}

func TestConsolidationCandidateEvent(t *testing.T) {
recorder := test.NewEventRecorder()

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/disruption/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (c Command) EmitRejectedEvents(recorder events.Recorder, reason string) {
}

func (c Command) LogValues() []any {
podCount := lo.Reduce(c.Candidates, func(_ int, cd *Candidate, _ int) int { return len(cd.reschedulablePods) }, 0)
podCount := lo.Reduce(c.Candidates, func(acc int, cd *Candidate, _ int) int { return acc + len(cd.reschedulablePods) }, 0)

candidateNodes := lo.Map(c.Candidates, func(candidate *Candidate, _ int) interface{} {
return map[string]interface{}{
Expand Down
Loading