1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/exceptions/selector.go
Charles-Edouard Brétéché 4438b24b69
refactor: exception selector interface (#9907)
* refactor: exception selector interface

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: shuting <shuting@nirmata.com>
2024-03-28 08:03:01 +00:00

34 lines
724 B
Go

package exceptions
import (
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
"k8s.io/apimachinery/pkg/labels"
)
type Lister interface {
List(labels.Selector) ([]*kyvernov2beta1.PolicyException, error)
}
type selector struct {
lister Lister
}
func New(lister Lister) selector {
return selector{
lister: lister,
}
}
func (s selector) Find(policyName string, ruleName string) ([]*kyvernov2beta1.PolicyException, error) {
polexs, err := s.lister.List(labels.Everything())
if err != nil {
return nil, err
}
var results []*kyvernov2beta1.PolicyException
for _, polex := range polexs {
if polex.Contains(policyName, ruleName) {
results = append(results, polex)
}
}
return results, nil
}