Skip to content

Commit

Permalink
polex version bump
Browse files Browse the repository at this point in the history
Signed-off-by: Ved Ratan <[email protected]>
  • Loading branch information
VedRatan committed Jun 19, 2024
1 parent 1925a33 commit f43f27c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cmd/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewExceptionSelector(
polexCache, err := exceptioncontroller.NewController(
kyvernoInformer.Kyverno().V1().ClusterPolicies(),
kyvernoInformer.Kyverno().V1().Policies(),
kyvernoInformer.Kyverno().V2alpha1().PolicyExceptions(),
kyvernoInformer.Kyverno().V2beta1().PolicyExceptions(),
exceptionNamespace,
)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions pkg/controllers/exceptions/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import (

"github.com/go-logr/logr"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
"github.com/kyverno/kyverno/pkg/autogen"
kyvernov1informers "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v1"
kyvernov2alpha1informers "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v2alpha1"
kyvernov2beta1informers "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v2beta1"
kyvernov1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1"
kyvernov2alpha1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v2alpha1"
kyvernov2beta1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v2beta1"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/workqueue"
)

type ruleIndex = map[string][]*kyvernov2alpha1.PolicyException
type ruleIndex = map[string][]*kyvernov2beta1.PolicyException

type policyIndex = map[string]ruleIndex

type controller struct {
// listers
cpolLister kyvernov1listers.ClusterPolicyLister
polLister kyvernov1listers.PolicyLister
polexLister kyvernov2alpha1listers.PolicyExceptionLister
polexLister kyvernov2beta1listers.PolicyExceptionLister

// queue
queue workqueue.RateLimitingInterface
Expand All @@ -50,7 +50,7 @@ const (
func NewController(
cpolInformer kyvernov1informers.ClusterPolicyInformer,
polInformer kyvernov1informers.PolicyInformer,
polexInformer kyvernov2alpha1informers.PolicyExceptionInformer,
polexInformer kyvernov2beta1informers.PolicyExceptionInformer,
namespace string,
) (*controller, error) {
queue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), ControllerName)
Expand Down Expand Up @@ -80,13 +80,13 @@ func (c *controller) Run(ctx context.Context, workers int) {
controllerutils.Run(ctx, logger.V(3), ControllerName, time.Second, c.queue, workers, maxRetries, c.reconcile)
}

func (c *controller) Find(policyName string, ruleName string) ([]*kyvernov2alpha1.PolicyException, error) {
func (c *controller) Find(policyName string, ruleName string) ([]*kyvernov2beta1.PolicyException, error) {
c.lock.RLock()
defer c.lock.RUnlock()
return c.index[policyName][ruleName], nil
}

func (c *controller) addPolex(polex *kyvernov2alpha1.PolicyException) {
func (c *controller) addPolex(polex *kyvernov2beta1.PolicyException) {
names := sets.New[string]()
for _, ex := range polex.Spec.Exceptions {
names.Insert(ex.PolicyName)
Expand All @@ -96,7 +96,7 @@ func (c *controller) addPolex(polex *kyvernov2alpha1.PolicyException) {
}
}

func (c *controller) updatePolex(old *kyvernov2alpha1.PolicyException, new *kyvernov2alpha1.PolicyException) {
func (c *controller) updatePolex(old *kyvernov2beta1.PolicyException, new *kyvernov2beta1.PolicyException) {
names := sets.New[string]()
for _, ex := range old.Spec.Exceptions {
names.Insert(ex.PolicyName)
Expand All @@ -109,7 +109,7 @@ func (c *controller) updatePolex(old *kyvernov2alpha1.PolicyException, new *kyve
}
}

func (c *controller) deletePolex(polex *kyvernov2alpha1.PolicyException) {
func (c *controller) deletePolex(polex *kyvernov2beta1.PolicyException) {
names := sets.New[string]()
for _, ex := range polex.Spec.Exceptions {
names.Insert(ex.PolicyName)
Expand All @@ -135,7 +135,7 @@ func (c *controller) getPolicy(namespace, name string) (kyvernov1.PolicyInterfac
}
}

func (c *controller) listExceptions() ([]*kyvernov2alpha1.PolicyException, error) {
func (c *controller) listExceptions() ([]*kyvernov2beta1.PolicyException, error) {
if c.namespace == "" {
return c.polexLister.List(labels.Everything())
}
Expand All @@ -147,7 +147,7 @@ func (c *controller) buildRuleIndex(key string, policy kyvernov1.PolicyInterface
if err != nil {
return nil, err
}
slices.SortFunc(polexList, func(a, b *kyvernov2alpha1.PolicyException) int {
slices.SortFunc(polexList, func(a, b *kyvernov2beta1.PolicyException) int {
if cmp := cmp.Compare(a.Namespace, b.Namespace); cmp != 0 {
return cmp
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/report/background/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-logr/logr"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned"
kyvernov1informers "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v1"
Expand Down Expand Up @@ -207,7 +207,7 @@ func (c *controller) getMeta(namespace, name string) (metav1.Object, error) {
}
}

func (c *controller) needsReconcile(namespace, name, hash string, exceptions []kyvernov2alpha1.PolicyException, policies ...engineapi.GenericPolicy) (bool, bool, error) {
func (c *controller) needsReconcile(namespace, name, hash string, exceptions []kyvernov2beta1.PolicyException, policies ...engineapi.GenericPolicy) (bool, bool, error) {
// if the reportMetadata does not exist, we need a full reconcile
reportMetadata, err := c.getMeta(namespace, name)
if err != nil {
Expand Down Expand Up @@ -263,7 +263,7 @@ func (c *controller) reconcileReport(
uid types.UID,
gvk schema.GroupVersionKind,
resource resource.Resource,
exceptions []kyvernov2alpha1.PolicyException,
exceptions []kyvernov2beta1.PolicyException,
policies ...engineapi.GenericPolicy,
) error {
// namespace labels to be used by the scanner
Expand Down Expand Up @@ -470,16 +470,16 @@ func (c *controller) reconcile(ctx context.Context, log logr.Logger, key, namesp
return nil
}

func (c *controller) addException(obj *kyvernov2alpha1.PolicyException) {
func (c *controller) addException(obj *kyvernov2beta1.PolicyException) {
c.enqueueResources()
}

func (c *controller) updateException(old, obj *kyvernov2alpha1.PolicyException) {
func (c *controller) updateException(old, obj *kyvernov2beta1.PolicyException) {
if old.GetResourceVersion() != obj.GetResourceVersion() {
c.enqueueResources()
}
}

func (c *controller) deleteException(obj *kyvernov2alpha1.PolicyException) {
func (c *controller) deleteException(obj *kyvernov2beta1.PolicyException) {
c.enqueueResources()
}
8 changes: 4 additions & 4 deletions pkg/controllers/report/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/go-logr/logr"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
"github.com/kyverno/kyverno/pkg/autogen"
kyvernov1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1"
kyvernov2alpha1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v2alpha1"
kyvernov2beta1listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v2beta1"
datautils "github.com/kyverno/kyverno/pkg/utils/data"
policyvalidation "github.com/kyverno/kyverno/pkg/validation/policy"
admissionregistrationv1alpha1 "k8s.io/api/admissionregistration/v1alpha1"
Expand All @@ -17,8 +17,8 @@ import (
admissionregistrationv1alpha1listers "k8s.io/client-go/listers/admissionregistration/v1alpha1"
)

func FetchPolicyExceptions(polexLister kyvernov2alpha1listers.PolicyExceptionLister, namespace string) ([]kyvernov2alpha1.PolicyException, error) {
var exceptions []kyvernov2alpha1.PolicyException
func FetchPolicyExceptions(polexLister kyvernov2beta1listers.PolicyExceptionLister, namespace string) ([]kyvernov2beta1.PolicyException, error) {
var exceptions []kyvernov2beta1.PolicyException
if polexs, err := polexLister.PolicyExceptions(namespace).List(labels.Everything()); err != nil {
return nil, err
} else {
Expand Down
8 changes: 4 additions & 4 deletions pkg/engine/api/ruleresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"fmt"

kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
pssutils "github.com/kyverno/kyverno/pkg/pss/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -43,7 +43,7 @@ type RuleResponse struct {
// podSecurityChecks contains pod security checks (only if this is a pod security rule)
podSecurityChecks *PodSecurityChecks
// exception is the exception applied (if any)
exception *kyvernov2alpha1.PolicyException
exception *kyvernov2beta1.PolicyException
}

func NewRuleResponse(name string, ruleType RuleType, msg string, status RuleStatus) *RuleResponse {
Expand Down Expand Up @@ -78,7 +78,7 @@ func RuleFail(name string, ruleType RuleType, msg string) *RuleResponse {
return NewRuleResponse(name, ruleType, msg, RuleStatusFail)
}

func (r RuleResponse) WithException(exception *kyvernov2alpha1.PolicyException) *RuleResponse {
func (r RuleResponse) WithException(exception *kyvernov2beta1.PolicyException) *RuleResponse {
r.exception = exception
return &r
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (r *RuleResponse) Stats() ExecutionStats {
return r.stats
}

func (r *RuleResponse) Exception() *kyvernov2alpha1.PolicyException {
func (r *RuleResponse) Exception() *kyvernov2beta1.PolicyException {
return r.exception
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/api/selector.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package api

import (
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
)

// PolicyExceptionSelector is an abstract interface used to resolve poliicy exceptions
type PolicyExceptionSelector interface {
// Find returns policy exceptions matching a given policy name and rule name.
// Objects returned here must be treated as read-only.
Find(string, string) ([]*kyvernov2alpha1.PolicyException, error)
Find(string, string) ([]*kyvernov2beta1.PolicyException, error)
}
6 changes: 3 additions & 3 deletions pkg/engine/exceptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package engine
import (
"github.com/go-logr/logr"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
matched "github.com/kyverno/kyverno/pkg/utils/match"
"k8s.io/client-go/tools/cache"
Expand All @@ -13,7 +13,7 @@ func findExceptions(
selector engineapi.PolicyExceptionSelector,
policy kyvernov1.PolicyInterface,
rule string,
) ([]*kyvernov2alpha1.PolicyException, error) {
) ([]*kyvernov2beta1.PolicyException, error) {
if selector == nil {
return nil, nil
}
Expand All @@ -25,7 +25,7 @@ func matchesException(
selector engineapi.PolicyExceptionSelector,
policyContext engineapi.PolicyContext,
rule kyvernov1.Rule,
) (*kyvernov2alpha1.PolicyException, error) {
) (*kyvernov2beta1.PolicyException, error) {
candidates, err := findExceptions(selector, policyContext.Policy(), rule.Name)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/exceptions/selector.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package exceptions

import (
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
"k8s.io/apimachinery/pkg/labels"
)

type Lister interface {
List(labels.Selector) ([]*kyvernov2alpha1.PolicyException, error)
List(labels.Selector) ([]*kyvernov2beta1.PolicyException, error)
}

type selector struct {
Expand All @@ -19,12 +19,12 @@ func New(lister Lister) selector {
}
}

func (s selector) Find(policyName string, ruleName string) ([]*kyvernov2alpha1.PolicyException, error) {
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 []*kyvernov2alpha1.PolicyException
var results []*kyvernov2beta1.PolicyException
for _, polex := range polexs {
if polex.Contains(policyName, ruleName) {
results = append(results, polex)
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/report/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/kyverno/kyverno/api/kyverno"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -64,11 +64,11 @@ func PolicyLabelPrefix(policy engineapi.GenericPolicy) string {
return LabelPrefixValidatingAdmissionPolicy
}

func PolicyExceptionLabel(exception kyvernov2alpha1.PolicyException) string {
func PolicyExceptionLabel(exception kyvernov2beta1.PolicyException) string {
return LabelPrefixPolicyException + exception.GetName()
}

func SetPolicyExceptionLabel(report kyvernov1alpha2.ReportInterface, exception kyvernov2alpha1.PolicyException) {
func SetPolicyExceptionLabel(report kyvernov1alpha2.ReportInterface, exception kyvernov2beta1.PolicyException) {
controllerutils.SetLabel(report, PolicyExceptionLabel(exception), exception.GetResourceVersion())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/resource/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewFakeHandlers(ctx context.Context, policyCache policycache.Cache) webhook
dclient := dclient.NewEmptyFakeClient()
configuration := config.NewDefaultConfiguration(false)
urLister := kyvernoInformers.Kyverno().V1beta1().UpdateRequests().Lister().UpdateRequests(config.KyvernoNamespace())
peLister := kyvernoInformers.Kyverno().V2alpha1().PolicyExceptions().Lister()
peLister := kyvernoInformers.Kyverno().V2beta1().PolicyExceptions().Lister()
jp := jmespath.New(configuration)
rclient := registryclient.NewOrDie()

Expand Down

0 comments on commit f43f27c

Please sign in to comment.