mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix conversion errors
This commit is contained in:
parent
022c227bce
commit
062d794cad
2 changed files with 8 additions and 4 deletions
|
@ -5,8 +5,12 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// convertToString converts value to string
|
||||
func convertToString(value interface{}) (string, error) {
|
||||
// convertNumberToString converts value to string
|
||||
func convertNumberToString(value interface{}) (string, error) {
|
||||
if value == nil {
|
||||
return "0", nil
|
||||
}
|
||||
|
||||
switch typed := value.(type) {
|
||||
case string:
|
||||
return string(typed), nil
|
||||
|
@ -17,7 +21,7 @@ func convertToString(value interface{}) (string, error) {
|
|||
case int:
|
||||
return strconv.Itoa(typed), nil
|
||||
default:
|
||||
return "", fmt.Errorf("Could not convert %T to string", value)
|
||||
return "", fmt.Errorf("could not convert %v to string", typed)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ func validateString(log logr.Logger, value interface{}, pattern string, operator
|
|||
// validateNumberWithStr compares quantity if pattern type is quantity
|
||||
// or a wildcard match to pattern string
|
||||
func validateNumberWithStr(log logr.Logger, value interface{}, pattern string, operator operator.Operator) bool {
|
||||
typedValue, err := convertToString(value)
|
||||
typedValue, err := convertNumberToString(value)
|
||||
if err != nil {
|
||||
log.Error(err, "failed to convert to string")
|
||||
return false
|
||||
|
|
Loading…
Add table
Reference in a new issue