volcano icon indicating copy to clipboard operation
volcano copied to clipboard

Refactor(api): clean up resource comparison function naming in resource_info.go

Open vyagh opened this issue 8 months ago • 5 comments

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:

  1. LessEqual and LessEqualWithResourcesName implement identical comparison logic. The only difference is the return type: bool vs (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."

  2. LessEqualWithDimensionAndResourcesName , the ResourcesName suffix is unnecessary. The req *Resource parameter is only used to check which dimensions to compare (req.MilliCPU > 0, req.Memory > 0, iterating req.ScalarResources keys. The actual values in req are never used for comparison.

  3. LessEqualPartly returns only bool, while all other comparison variants return (bool, []string).

  4. LessEqualPartlyWithDimensionZeroFiltered , the name is unclear. The function filters out dimensions that are irrelevant (both zero in r and rr) before comparing.

Environment:

  • Volcano version: master (HEAD)
  • Component: pkg/scheduler/api

Describe the solution you'd like

  1. Merge LessEqual and LessEqualWithResourcesName into a single LessEqual returning (bool, []string). Remove LessEqualWithResourcesName.

  2. Rename LessEqualWithDimensionAndResourcesName to LessEqualWithDimension. Change req *Resource to dims ResourceNameList since only resource names are used.

  3. Update LessEqualPartly to return (bool, []string).

  4. Rename LessEqualPartlyWithDimensionZeroFiltered to LessEqualPartlyWithRelevantDimensions.

  5. Apply the same req *Resource to dims ResourceNameList signature change to LessEqualPartlyWithDimension and LessEqualPartlyWithRelevantDimensions.

Additional context

  • LessEqual has approx. 25 call sites across pkg/scheduler/actions/, pkg/scheduler/plugins/, pkg/agentscheduler/, and test/e2e/. Callers that only use the bool return will need ok, _ := after the merge.
  • LessEqualWithDimensionAndResourcesName has 7 production call sites in the capacity, proportion, and overcommit plugins.
  • LessEqualPartlyWithDimensionZeroFiltered has 1 production caller in the capacity plugin.
  • The GreaterPartly* functions added in #4927 were named to follow the LessEqual* convention, they should stay consistent with the new names after this refactor.
  • LessEqualWithDimensionAndResourcesName uses direct > comparison without the floating point epsilon check used in LessEqual (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.

vyagh avatar Apr 04 '26 03:04 vyagh

/assign

vyagh avatar Apr 04 '26 03:04 vyagh

/kind rfe

vyagh avatar Apr 04 '26 03:04 vyagh

/remove-kind feature

vyagh avatar Apr 04 '26 03:04 vyagh

Super thanks for creating the issue and looking forward to the contribution! Please cc me into the PR 😊

hajnalmt avatar Apr 06 '26 07:04 hajnalmt

@hajnalmt

vyagh avatar Apr 06 '26 16:04 vyagh