1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 01:46:55 +00:00
kyverno/pkg/engine/exceptions.go
Charles-Edouard Brétéché ad62014b33
chore: simplify getting exception name (#9916)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-03-15 15:02:57 +00:00

30 lines
850 B
Go

package engine
import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// GetPolicyExceptions get all exceptions that match both the policy and the rule.
func (e *engine) GetPolicyExceptions(
policy kyvernov1.PolicyInterface,
rule string,
) ([]kyvernov2beta1.PolicyException, error) {
var exceptions []kyvernov2beta1.PolicyException
if e.exceptionSelector == nil {
return exceptions, nil
}
polexs, err := e.exceptionSelector.List(labels.Everything())
if err != nil {
return exceptions, err
}
policyName := cache.MetaObjectToName(policy).String()
for _, polex := range polexs {
if polex.Contains(policyName, rule) {
exceptions = append(exceptions, *polex)
}
}
return exceptions, nil
}