2023-02-06 06:49:47 +01:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
2023-12-22 12:13:58 +02:00
|
|
|
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
|
2023-02-06 06:49:47 +01:00
|
|
|
"k8s.io/client-go/tools/cache"
|
|
|
|
)
|
|
|
|
|
2023-11-13 17:43:25 +02:00
|
|
|
// GetPolicyExceptions get all exceptions that match both the policy and the rule.
|
|
|
|
func (e *engine) GetPolicyExceptions(
|
2023-02-06 06:49:47 +01:00
|
|
|
policy kyvernov1.PolicyInterface,
|
|
|
|
rule string,
|
2023-12-22 12:13:58 +02:00
|
|
|
) ([]kyvernov2beta1.PolicyException, error) {
|
|
|
|
var exceptions []kyvernov2beta1.PolicyException
|
2023-11-13 17:43:25 +02:00
|
|
|
if e.exceptionSelector == nil {
|
|
|
|
return exceptions, nil
|
2023-02-06 06:49:47 +01:00
|
|
|
}
|
2024-03-28 09:03:01 +01:00
|
|
|
policyName := cache.MetaObjectToName(policy).String()
|
|
|
|
polexs, err := e.exceptionSelector.Find(policyName, rule)
|
2023-02-06 06:49:47 +01:00
|
|
|
if err != nil {
|
2023-11-13 17:43:25 +02:00
|
|
|
return exceptions, err
|
2023-02-06 06:49:47 +01:00
|
|
|
}
|
|
|
|
for _, polex := range polexs {
|
2024-03-28 09:03:01 +01:00
|
|
|
exceptions = append(exceptions, *polex)
|
2023-02-06 06:49:47 +01:00
|
|
|
}
|
2023-11-13 17:43:25 +02:00
|
|
|
return exceptions, nil
|
2023-02-06 06:49:47 +01:00
|
|
|
}
|