Skip to content

Commit

Permalink
Merge pull request #2650 from kingeasternsun/improve/diff-replace-mag…
Browse files Browse the repository at this point in the history
…ic-number

🌈 style(resource_info): replace 0, -1 with Zero,Infinity
  • Loading branch information
volcano-sh-bot authored Jan 12, 2023
2 parents 68425c3 + 16e98ec commit c451fea
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pkg/scheduler/api/resource_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ func (r *Resource) Diff(rr *Resource, defaultValue DimensionDefaultValue) (*Reso
decreasedVal.ScalarResources = make(map[v1.ResourceName]float64)
for lName, lQuant := range leftRes.ScalarResources {
rQuant := rightRes.ScalarResources[lName]
if lQuant == -1 {
increasedVal.ScalarResources[lName] = -1
if lQuant == float64(Infinity) {
increasedVal.ScalarResources[lName] = lQuant
continue
}
if rQuant == -1 {
decreasedVal.ScalarResources[lName] = -1
if rQuant == float64(Infinity) {
decreasedVal.ScalarResources[lName] = rQuant
continue
}
if lQuant > rQuant {
Expand Down Expand Up @@ -563,22 +563,14 @@ func (r *Resource) setDefaultValue(leftResource, rightResource *Resource, defaul
for resourceName := range leftResource.ScalarResources {
_, ok := rightResource.ScalarResources[resourceName]
if !ok {
if defaultValue == Zero {
rightResource.ScalarResources[resourceName] = 0
} else if defaultValue == Infinity {
rightResource.ScalarResources[resourceName] = -1
}
rightResource.ScalarResources[resourceName] = float64(defaultValue)
}
}

for resourceName := range rightResource.ScalarResources {
_, ok := leftResource.ScalarResources[resourceName]
if !ok {
if defaultValue == Zero {
leftResource.ScalarResources[resourceName] = 0
} else if defaultValue == Infinity {
leftResource.ScalarResources[resourceName] = -1
}
leftResource.ScalarResources[resourceName] = float64(defaultValue)
}
}
}
Expand Down

0 comments on commit c451fea

Please sign in to comment.