forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: exception selector interface
Signed-off-by: Anushka Mittal <[email protected]>
- Loading branch information
1 parent
31b820c
commit 7ba0740
Showing
5 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package exceptions | ||
|
||
import ( | ||
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
type Lister interface { | ||
List(labels.Selector) ([]*kyvernov2alpha1.PolicyException, error) | ||
} | ||
|
||
type selector struct { | ||
lister Lister | ||
} | ||
|
||
func New(lister Lister) selector { | ||
return selector{ | ||
lister: lister, | ||
} | ||
} | ||
|
||
func (s selector) Find(policyName string, ruleName string) ([]*kyvernov2alpha1.PolicyException, error) { | ||
polexs, err := s.lister.List(labels.Everything()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var results []*kyvernov2alpha1.PolicyException | ||
for _, polex := range polexs { | ||
if polex.Contains(policyName, ruleName) { | ||
results = append(results, polex) | ||
} | ||
} | ||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters