Skip to content

Commit

Permalink
util: fix incorrect comparison for resource.go#LessThanOrEqualComplet…
Browse files Browse the repository at this point in the history
…ely (#2235)

Signed-off-by: Tao Yang <[email protected]>
  • Loading branch information
TaoYang526 authored Oct 30, 2024
1 parent 78eafd4 commit 8661de2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/util/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func LessThanOrEqualCompletely(a corev1.ResourceList, b corev1.ResourceList) boo
result := true
delta := quotav1.Subtract(a, b)
for _, value := range delta {
if value.Value() > 0 {
if value.CmpInt64(0) > 0 {
result = false
break
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,16 @@ func TestLessThanOrEqualEnhanced(t *testing.T) {
},
expect: true,
},
{
name: "a < b, special case: deltaValue.Value() may overflow",
a: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("1000Gi"),
},
b: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("39999996Gi"),
},
expect: true,
},
{
name: "a > b",
a: corev1.ResourceList{
Expand Down

0 comments on commit 8661de2

Please sign in to comment.