mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 23:46:56 +00:00
* skip other checks if operations do not match Signed-off-by: Jim Bugwadia <jim@nirmata.com> * copy resource/rule as match seems to mutate for wildcard checks Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix deepcopy Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Jim Bugwadia <jim@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
24 lines
637 B
Go
24 lines
637 B
Go
package match
|
|
|
|
import (
|
|
"github.com/kyverno/kyverno/pkg/engine/wildcards"
|
|
"github.com/kyverno/kyverno/pkg/logging"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
)
|
|
|
|
func CheckSelector(expected *metav1.LabelSelector, actual map[string]string) (bool, error) {
|
|
if expected == nil {
|
|
return false, nil
|
|
}
|
|
expected = wildcards.ReplaceInSelector(expected, actual)
|
|
selector, err := metav1.LabelSelectorAsSelector(expected)
|
|
if err != nil {
|
|
logging.Error(err, "failed to build label selector")
|
|
return false, err
|
|
}
|
|
if selector.Matches(labels.Set(actual)) {
|
|
return true, nil
|
|
}
|
|
return false, nil
|
|
}
|