Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions pkg/engine/sources/control_plane.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sources

import (
"context"

"github.com/kyverno/kyverno-envoy-plugin/pkg/engine"
"github.com/kyverno/kyverno-envoy-plugin/sdk/core"
"github.com/kyverno/kyverno-envoy-plugin/sdk/core/sources"
Expand All @@ -11,10 +13,15 @@ func NewControlPlane[POLICY any](
compiler engine.Compiler[POLICY],
) (core.Source[POLICY], error) {
listener := NewListener()
transform := sources.NewTransformErr(listener, func(in *v1alpha1.ValidatingPolicy) (POLICY, error) {
policy, err := compiler.Compile(in)
return policy, err.ToAggregate()
})
// TODO: cache
return transform, nil
cache := sources.NewCache(
listener,
func(_ context.Context, in *v1alpha1.ValidatingPolicy) (string, error) {
return in.Name + in.ResourceVersion, nil
},
func(_ context.Context, _ string, in *v1alpha1.ValidatingPolicy) (POLICY, error) {
policy, err := compiler.Compile(in)
return policy, err.ToAggregate()
},
)
return cache, nil
}
19 changes: 13 additions & 6 deletions pkg/engine/sources/kube.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sources

import (
"context"

"github.com/kyverno/kyverno-envoy-plugin/pkg/engine"
"github.com/kyverno/kyverno-envoy-plugin/sdk/core"
"github.com/kyverno/kyverno-envoy-plugin/sdk/core/sources"
Expand All @@ -20,10 +22,15 @@ func NewKube[POLICY any](name string, mgr ctrl.Manager, compiler engine.Compiler
return nil, err

}
transform := sources.NewTransformErr(apis, func(in *v1alpha1.ValidatingPolicy) (POLICY, error) {
policy, err := compiler.Compile(in)
return policy, err.ToAggregate()
})
// TODO: cache
return transform, nil
cache := sources.NewCache(
apis,
func(_ context.Context, in *v1alpha1.ValidatingPolicy) (string, error) {
return in.Name + in.ResourceVersion, nil
},
func(_ context.Context, _ string, in *v1alpha1.ValidatingPolicy) (POLICY, error) {
policy, err := compiler.Compile(in)
return policy, err.ToAggregate()
},
)
return cache, nil
}