mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-13 19:28:55 +00:00
fix: filter name in add/sum error (#6657)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
f8b352ff55
commit
6f65b4416e
2 changed files with 16 additions and 13 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
type Operand interface {
|
||||
Add(interface{}) (interface{}, error)
|
||||
Add(interface{}, string) (interface{}, error)
|
||||
Subtract(interface{}) (interface{}, error)
|
||||
Multiply(interface{}) (interface{}, error)
|
||||
Divide(interface{}) (interface{}, error)
|
||||
|
@ -58,31 +58,31 @@ func ParseArithemticOperands(arguments []interface{}, operator string) (Operand,
|
|||
// Scalar +|- Scalar -> Scalar
|
||||
// Scalar +|- Quantity|Duration -> error
|
||||
|
||||
func (op1 Quantity) Add(op2 interface{}) (interface{}, error) {
|
||||
func (op1 Quantity) Add(op2 interface{}, operator string) (interface{}, error) {
|
||||
switch v := op2.(type) {
|
||||
case Quantity:
|
||||
op1.Quantity.Add(v.Quantity)
|
||||
return op1.String(), nil
|
||||
default:
|
||||
return nil, formatError(typeMismatchError, add)
|
||||
return nil, formatError(typeMismatchError, operator)
|
||||
}
|
||||
}
|
||||
|
||||
func (op1 Duration) Add(op2 interface{}) (interface{}, error) {
|
||||
func (op1 Duration) Add(op2 interface{}, operator string) (interface{}, error) {
|
||||
switch v := op2.(type) {
|
||||
case Duration:
|
||||
return (op1.Duration + v.Duration).String(), nil
|
||||
default:
|
||||
return nil, formatError(typeMismatchError, add)
|
||||
return nil, formatError(typeMismatchError, operator)
|
||||
}
|
||||
}
|
||||
|
||||
func (op1 Scalar) Add(op2 interface{}) (interface{}, error) {
|
||||
func (op1 Scalar) Add(op2 interface{}, operator string) (interface{}, error) {
|
||||
switch v := op2.(type) {
|
||||
case Scalar:
|
||||
return op1.float64 + v.float64, nil
|
||||
default:
|
||||
return nil, formatError(typeMismatchError, add)
|
||||
return nil, formatError(typeMismatchError, operator)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -773,13 +773,16 @@ func jpToBoolean(arguments []interface{}) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func jpAdd(arguments []interface{}) (interface{}, error) {
|
||||
op1, op2, err := ParseArithemticOperands(arguments, add)
|
||||
func _jpAdd(arguments []interface{}, operator string) (interface{}, error) {
|
||||
op1, op2, err := ParseArithemticOperands(arguments, operator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return op1.Add(op2, operator)
|
||||
}
|
||||
|
||||
return op1.Add(op2)
|
||||
func jpAdd(arguments []interface{}) (interface{}, error) {
|
||||
return _jpAdd(arguments, add)
|
||||
}
|
||||
|
||||
func jpSum(arguments []interface{}) (interface{}, error) {
|
||||
|
@ -791,14 +794,14 @@ func jpSum(arguments []interface{}) (interface{}, error) {
|
|||
return nil, formatError(genericError, sum, "at least one element in the array is required")
|
||||
}
|
||||
var err error
|
||||
sum := items[0]
|
||||
result := items[0]
|
||||
for _, item := range items[1:] {
|
||||
sum, err = jpAdd([]interface{}{sum, item})
|
||||
result, err = _jpAdd([]interface{}{result, item}, sum)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return sum, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func jpSubtract(arguments []interface{}) (interface{}, error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue