Refactor(api): clean up resource comparison function naming in resource_info.go
What is the problem you're trying to solve
The Resource comparison API in pkg/scheduler/api/resource_info.go has inconsistent naming across functions added at different times. Several functions duplicate logic under different names, function names carry redundant suffixes, and some signatures accept *Resource parameters where only the resource names are used.
Identified during review of #4927 by @hajnalmt and @JesseStutler:
- https://github.com/volcano-sh/volcano/pull/4927#issuecomment-3753130772
- https://github.com/volcano-sh/volcano/pull/4927#issuecomment-3753209458
Current problems:
-
LessEqualandLessEqualWithResourcesNameimplement identical comparison logic. The only difference is the return type:boolvs(bool, []string). infact it already has a comment: "this function is the same as LessEqual, and it will be merged to LessEqual in the future." -
LessEqualWithDimensionAndResourcesName, theResourcesNamesuffix is unnecessary. Thereq *Resourceparameter is only used to check which dimensions to compare (req.MilliCPU > 0,req.Memory > 0, iteratingreq.ScalarResourceskeys. The actual values inreqare never used for comparison. -
LessEqualPartlyreturns onlybool, while all other comparison variants return(bool, []string). -
LessEqualPartlyWithDimensionZeroFiltered, the name is unclear. The function filters out dimensions that are irrelevant (both zero inrandrr) before comparing.
Environment:
- Volcano version: master (HEAD)
- Component:
pkg/scheduler/api
Describe the solution you'd like
-
Merge
LessEqualandLessEqualWithResourcesNameinto a singleLessEqualreturning(bool, []string). RemoveLessEqualWithResourcesName. -
Rename
LessEqualWithDimensionAndResourcesNametoLessEqualWithDimension. Changereq *Resourcetodims ResourceNameListsince only resource names are used. -
Update
LessEqualPartlyto return(bool, []string). -
Rename
LessEqualPartlyWithDimensionZeroFilteredtoLessEqualPartlyWithRelevantDimensions. -
Apply the same
req *Resourcetodims ResourceNameListsignature change toLessEqualPartlyWithDimensionandLessEqualPartlyWithRelevantDimensions.
Additional context
LessEqualhas approx. 25 call sites acrosspkg/scheduler/actions/,pkg/scheduler/plugins/,pkg/agentscheduler/, andtest/e2e/. Callers that only use theboolreturn will needok, _ :=after the merge.LessEqualWithDimensionAndResourcesNamehas 7 production call sites in the capacity, proportion, and overcommit plugins.LessEqualPartlyWithDimensionZeroFilteredhas 1 production caller in the capacity plugin.- The
GreaterPartly*functions added in #4927 were named to follow theLessEqual*convention, they should stay consistent with the new names after this refactor. LessEqualWithDimensionAndResourcesNameuses direct>comparison without the floating point epsilon check used inLessEqual(math.Abs(l-r) < diff). Not including this in this Issue as I think it's out of scope.
Documentation Updates
- [ ] This feature requires design or user documentation changes.
- [ ] If documentation changes are required, I will ensure the relevant documents are updated and published to the Volcano official website (https://volcano.sh) via the volcano-sh/website repository.
/assign
/kind rfe
/remove-kind feature
Super thanks for creating the issue and looking forward to the contribution! Please cc me into the PR 😊
@hajnalmt