1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix wildcard match

This commit is contained in:
Jim Bugwadia 2020-11-29 00:35:33 -08:00
parent 27f9516eb2
commit 251129d09b
3 changed files with 6 additions and 4 deletions

View file

@ -83,7 +83,7 @@ func (eh EqualHandler) validateValueWithMapPattern(key map[string]interface{}, v
func (eh EqualHandler) validateValueWithStringPattern(key string, value interface{}) bool {
if val, ok := value.(string); ok {
return wildcard.Match(key, val)
return wildcard.Match(val, key)
}
eh.log.Info("Expected type string", "value", value, "type", fmt.Sprintf("%T", value))

View file

@ -3,6 +3,7 @@ package operator
import (
"encoding/json"
"fmt"
"github.com/minio/minio/pkg/wildcard"
"github.com/go-logr/logr"
@ -76,14 +77,14 @@ func keyExistsInArray(key string, value interface{}, log logr.Logger) (invalidTy
case string:
if wildcard.Match(key, valuesAvailable) {
if wildcard.Match(valuesAvailable, key) {
keyExists = true
return
}
var arr []string
if err := json.Unmarshal([]byte(valuesAvailable), &arr); err != nil {
log.Error(err, "failed to unmarshal to string slice", "value", value)
log.Error(err, "failed to unmarshal value to JSON string array", "key", key, "value", value)
invalidType = true
return
}

View file

@ -82,8 +82,9 @@ func (neh NotEqualHandler) validateValueWithMapPattern(key map[string]interface{
func (neh NotEqualHandler) validateValueWithStringPattern(key string, value interface{}) bool {
if val, ok := value.(string); ok {
return !wildcard.Match(key, val)
return !wildcard.Match(val, key)
}
neh.log.Info("Expected type string", "value", value, "type", fmt.Sprintf("%T", value))
return false
}