mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Fix precision handling in validating LimitRange
This commit is contained in:
@@ -301,6 +301,27 @@ func (q *Quantity) String() string {
|
||||
return number + string(suffix)
|
||||
}
|
||||
|
||||
// Cmp compares q and y and returns:
|
||||
//
|
||||
// -1 if q < y
|
||||
// 0 if q == y
|
||||
// +1 if q > y
|
||||
//
|
||||
func (q *Quantity) Cmp(y Quantity) int {
|
||||
num1 := q.Value()
|
||||
num2 := y.Value()
|
||||
if num1 < MaxMilliValue && num2 < MaxMilliValue {
|
||||
num1 = q.MilliValue()
|
||||
num2 = y.MilliValue()
|
||||
}
|
||||
if num1 < num2 {
|
||||
return -1
|
||||
} else if num1 > num2 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (q *Quantity) Add(y Quantity) error {
|
||||
if q.Format != y.Format {
|
||||
return fmt.Errorf("format mismatch: %v vs. %v", q.Format, y.Format)
|
||||
|
||||
Reference in New Issue
Block a user