1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/utils/report/selector.go
Mariam Fahmy 8732183cc6
feat: generate backgroundscan reports for validating admission policies (#8135)
* feat: generate backgroundscan reports for validating admission policies

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>

* fix: skip validate check images if errors are encourted when validating the resource

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>

---------

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
2023-09-05 11:42:17 +00:00

44 lines
1.4 KiB
Go

package report
import (
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
)
func SelectorResourceUidEquals(uid types.UID) (labels.Selector, error) {
selector := labels.Everything()
requirement, err := labels.NewRequirement(LabelResourceUid, selection.Equals, []string{string(uid)})
if err == nil {
selector = selector.Add(*requirement)
}
return selector, err
}
func SelectorPolicyDoesNotExist(policy engineapi.GenericPolicy) (labels.Selector, error) {
selector := labels.Everything()
requirement, err := labels.NewRequirement(PolicyLabel(policy), selection.DoesNotExist, nil)
if err == nil {
selector = selector.Add(*requirement)
}
return selector, err
}
func SelectorPolicyExists(policy engineapi.GenericPolicy) (labels.Selector, error) {
selector := labels.Everything()
requirement, err := labels.NewRequirement(PolicyLabel(policy), selection.Exists, nil)
if err == nil {
selector = selector.Add(*requirement)
}
return selector, err
}
func SelectorPolicyNotEquals(policy engineapi.GenericPolicy) (labels.Selector, error) {
selector := labels.Everything()
requirement, err := labels.NewRequirement(PolicyLabel(policy), selection.NotEquals, []string{policy.GetResourceVersion()})
if err == nil {
selector = selector.Add(*requirement)
}
return selector, err
}