Skip to content

lo.Reduce in Command.LogValues discards accumulator, reports last candidate's pod count instead of total #2888

@binaryphile

Description

@binaryphile

Bug

In pkg/controllers/disruption/types.go, LogValues() computes podCount using lo.Reduce:

podCount := lo.Reduce(c.candidates, func(_ int, cd *Candidate, _ int) int {
    return len(cd.reschedulablePods)
}, 0)

The first _ int parameter is the accumulator. Because it's discarded, the function returns len(cd.reschedulablePods) for the last candidate only, not the sum across all candidates.

Expected

podCount := lo.Reduce(c.candidates, func(acc int, cd *Candidate, _ int) int {
    return acc + len(cd.reschedulablePods)
}, 0)

Impact

The "pod-count" field in structured disruption logs under-reports when multiple nodes are disrupted simultaneously (e.g., multi-node consolidation). Single-candidate disruptions are unaffected since last == only.

History

The line dates back to the original String() method (before commit c0e7299 refactored it to LogValues()). The refactor carried it over unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.needs-prioritytriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions