1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

feat: add typed client support and metrics wrapper (#4724)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-09-29 13:42:50 +02:00 committed by GitHub
parent da3970de5b
commit 205bb28b52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 315 additions and 711 deletions

View file

@ -10,7 +10,6 @@ import (
wrappedkyvernov1alpha2 "github.com/kyverno/kyverno/pkg/clients/wrappers/kyverno/v1alpha2"
wrappedkyvernov1beta1 "github.com/kyverno/kyverno/pkg/clients/wrappers/kyverno/v1beta1"
wrappedwgpolicyk8sv1alpha2 "github.com/kyverno/kyverno/pkg/clients/wrappers/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
"github.com/kyverno/kyverno/pkg/metrics"
"k8s.io/client-go/rest"
)
@ -39,17 +38,16 @@ func (c *clientset) Wgpolicyk8sV1alpha2() versionedpolicyreportv1alpha2.Wgpolicy
return c.wgpolicyk8sV1alpha2
}
func NewForConfig(c *rest.Config, m *metrics.MetricsConfig) (versioned.Interface, error) {
clientQueryMetric := utils.NewClientQueryMetric(m)
func NewForConfig(c *rest.Config, m metrics.MetricsConfigManager) (versioned.Interface, error) {
kClientset, err := versioned.NewForConfig(c)
if err != nil {
return nil, err
}
return &clientset{
Interface: kClientset,
kyvernoV1: wrappedkyvernov1.Wrap(kClientset.KyvernoV1(), clientQueryMetric),
kyvernoV1beta1: wrappedkyvernov1beta1.Wrap(kClientset.KyvernoV1beta1(), clientQueryMetric),
kyvernoV1alpha2: wrappedkyvernov1alpha2.Wrap(kClientset.KyvernoV1alpha2(), clientQueryMetric),
wgpolicyk8sV1alpha2: wrappedwgpolicyk8sv1alpha2.Wrap(kClientset.Wgpolicyk8sV1alpha2(), clientQueryMetric),
kyvernoV1: wrappedkyvernov1.Wrap(kClientset.KyvernoV1(), m),
kyvernoV1beta1: wrappedkyvernov1beta1.Wrap(kClientset.KyvernoV1beta1(), m),
kyvernoV1alpha2: wrappedkyvernov1alpha2.Wrap(kClientset.KyvernoV1alpha2(), m),
wgpolicyk8sV1alpha2: wrappedwgpolicyk8sv1alpha2.Wrap(kClientset.Wgpolicyk8sV1alpha2(), m),
}, nil
}

View file

@ -1,60 +0,0 @@
package v1
import (
"context"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
v1 "github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type clusterPolicies struct {
inner v1.ClusterPolicyInterface
clientQueryMetric utils.ClientQueryMetric
}
func wrapClusterPolicies(c v1.ClusterPolicyInterface, m utils.ClientQueryMetric) v1.ClusterPolicyInterface {
return &clusterPolicies{
inner: c,
clientQueryMetric: m,
}
}
func (c *clusterPolicies) Create(ctx context.Context, o *kyvernov1.ClusterPolicy, opts metav1.CreateOptions) (*kyvernov1.ClusterPolicy, error) {
return utils.Create(ctx, c.clientQueryMetric, "ClusterPolicy", "", o, opts, c.inner.Create)
}
func (c *clusterPolicies) Update(ctx context.Context, o *kyvernov1.ClusterPolicy, opts metav1.UpdateOptions) (*kyvernov1.ClusterPolicy, error) {
return utils.Update(ctx, c.clientQueryMetric, "ClusterPolicy", "", o, opts, c.inner.Update)
}
func (c *clusterPolicies) UpdateStatus(ctx context.Context, o *kyvernov1.ClusterPolicy, opts metav1.UpdateOptions) (*kyvernov1.ClusterPolicy, error) {
return utils.UpdateStatus(ctx, c.clientQueryMetric, "ClusterPolicy", "", o, opts, c.inner.UpdateStatus)
}
func (c *clusterPolicies) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "ClusterPolicy", "", name, opts, c.inner.Delete)
}
func (c *clusterPolicies) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "ClusterPolicy", "", opts, listOpts, c.inner.DeleteCollection)
}
func (c *clusterPolicies) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1.ClusterPolicy, error) {
return utils.Get(ctx, c.clientQueryMetric, "ClusterPolicy", "", name, opts, c.inner.Get)
}
func (c *clusterPolicies) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1.ClusterPolicyList, error) {
return utils.List(ctx, c.clientQueryMetric, "ClusterPolicy", "", opts, c.inner.List)
}
func (c *clusterPolicies) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "ClusterPolicy", "", opts, c.inner.Watch)
}
func (c *clusterPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1.ClusterPolicy, error) {
return utils.Patch(ctx, c.clientQueryMetric, "ClusterPolicy", "", name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,62 +0,0 @@
package v1
import (
"context"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
v1 "github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type generateRequest struct {
inner v1.GenerateRequestInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapGenerateRequests(c v1.GenerateRequestInterface, m utils.ClientQueryMetric, namespace string) v1.GenerateRequestInterface {
return &generateRequest{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *generateRequest) Create(ctx context.Context, o *kyvernov1.GenerateRequest, opts metav1.CreateOptions) (*kyvernov1.GenerateRequest, error) {
return utils.Create(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, o, opts, c.inner.Create)
}
func (c *generateRequest) Update(ctx context.Context, o *kyvernov1.GenerateRequest, opts metav1.UpdateOptions) (*kyvernov1.GenerateRequest, error) {
return utils.Update(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, o, opts, c.inner.Update)
}
func (c *generateRequest) UpdateStatus(ctx context.Context, o *kyvernov1.GenerateRequest, opts metav1.UpdateOptions) (*kyvernov1.GenerateRequest, error) {
return utils.UpdateStatus(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, o, opts, c.inner.UpdateStatus)
}
func (c *generateRequest) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, name, opts, c.inner.Delete)
}
func (c *generateRequest) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *generateRequest) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1.GenerateRequest, error) {
return utils.Get(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, name, opts, c.inner.Get)
}
func (c *generateRequest) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1.GenerateRequestList, error) {
return utils.List(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, opts, c.inner.List)
}
func (c *generateRequest) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, opts, c.inner.Watch)
}
func (c *generateRequest) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1.GenerateRequest, error) {
return utils.Patch(ctx, c.clientQueryMetric, "GenerateRequest", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,32 +1,61 @@
package v1
import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
v1 "github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
"github.com/kyverno/kyverno/pkg/metrics"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"k8s.io/client-go/rest"
)
type client struct {
inner v1.KyvernoV1Interface
clientQueryMetric utils.ClientQueryMetric
inner v1.KyvernoV1Interface
metrics metrics.MetricsConfigManager
}
func (c *client) ClusterPolicies() v1.ClusterPolicyInterface {
return wrapClusterPolicies(c.inner.ClusterPolicies(), c.clientQueryMetric)
recorder := metrics.ClusteredClientQueryRecorder(c.metrics, "ClusterPolicy", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1.ClusterPolicy]
controllerutils.ListClient[*kyvernov1.ClusterPolicyList]
controllerutils.StatusClient[*kyvernov1.ClusterPolicy]
}{
metrics.ObjectClient[*kyvernov1.ClusterPolicy](recorder, c.inner.ClusterPolicies()),
metrics.ListClient[*kyvernov1.ClusterPolicyList](recorder, c.inner.ClusterPolicies()),
metrics.StatusClient[*kyvernov1.ClusterPolicy](recorder, c.inner.ClusterPolicies()),
}
}
func (c *client) Policies(namespace string) v1.PolicyInterface {
return wrapPolicies(c.inner.Policies(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "Policy", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1.Policy]
controllerutils.ListClient[*kyvernov1.PolicyList]
controllerutils.StatusClient[*kyvernov1.Policy]
}{
metrics.ObjectClient[*kyvernov1.Policy](recorder, c.inner.Policies(namespace)),
metrics.ListClient[*kyvernov1.PolicyList](recorder, c.inner.Policies(namespace)),
metrics.StatusClient[*kyvernov1.Policy](recorder, c.inner.Policies(namespace)),
}
}
func (c *client) GenerateRequests(namespace string) v1.GenerateRequestInterface {
return wrapGenerateRequests(c.inner.GenerateRequests(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "GenerateRequest", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1.GenerateRequest]
controllerutils.ListClient[*kyvernov1.GenerateRequestList]
controllerutils.StatusClient[*kyvernov1.GenerateRequest]
}{
metrics.ObjectClient[*kyvernov1.GenerateRequest](recorder, c.inner.GenerateRequests(namespace)),
metrics.ListClient[*kyvernov1.GenerateRequestList](recorder, c.inner.GenerateRequests(namespace)),
metrics.StatusClient[*kyvernov1.GenerateRequest](recorder, c.inner.GenerateRequests(namespace)),
}
}
func (c *client) RESTClient() rest.Interface {
return c.inner.RESTClient()
}
func Wrap(inner v1.KyvernoV1Interface, m utils.ClientQueryMetric) v1.KyvernoV1Interface {
return &client{inner, m}
func Wrap(inner v1.KyvernoV1Interface, metrics metrics.MetricsConfigManager) v1.KyvernoV1Interface {
return &client{inner, metrics}
}

View file

@ -1,62 +0,0 @@
package v1
import (
"context"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
v1 "github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type policies struct {
inner v1.PolicyInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapPolicies(c v1.PolicyInterface, m utils.ClientQueryMetric, namespace string) v1.PolicyInterface {
return &policies{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *policies) Create(ctx context.Context, o *kyvernov1.Policy, opts metav1.CreateOptions) (*kyvernov1.Policy, error) {
return utils.Create(ctx, c.clientQueryMetric, "Policy", c.ns, o, opts, c.inner.Create)
}
func (c *policies) Update(ctx context.Context, o *kyvernov1.Policy, opts metav1.UpdateOptions) (*kyvernov1.Policy, error) {
return utils.Update(ctx, c.clientQueryMetric, "Policy", c.ns, o, opts, c.inner.Update)
}
func (c *policies) UpdateStatus(ctx context.Context, o *kyvernov1.Policy, opts metav1.UpdateOptions) (*kyvernov1.Policy, error) {
return utils.UpdateStatus(ctx, c.clientQueryMetric, "Policy", c.ns, o, opts, c.inner.UpdateStatus)
}
func (c *policies) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "Policy", c.ns, name, opts, c.inner.Delete)
}
func (c *policies) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "Policy", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *policies) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1.Policy, error) {
return utils.Get(ctx, c.clientQueryMetric, "Policy", c.ns, name, opts, c.inner.Get)
}
func (c *policies) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1.PolicyList, error) {
return utils.List(ctx, c.clientQueryMetric, "Policy", c.ns, opts, c.inner.List)
}
func (c *policies) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "Policy", c.ns, opts, c.inner.Watch)
}
func (c *policies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1.Policy, error) {
return utils.Patch(ctx, c.clientQueryMetric, "Policy", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,58 +0,0 @@
package v1alpha2
import (
"context"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type admissionReport struct {
inner v1alpha2.AdmissionReportInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapAdmissionReports(c v1alpha2.AdmissionReportInterface, m utils.ClientQueryMetric, namespace string) v1alpha2.AdmissionReportInterface {
return &admissionReport{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *admissionReport) Create(ctx context.Context, o *kyvernov1alpha2.AdmissionReport, opts metav1.CreateOptions) (*kyvernov1alpha2.AdmissionReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, o, opts, c.inner.Create)
}
func (c *admissionReport) Update(ctx context.Context, o *kyvernov1alpha2.AdmissionReport, opts metav1.UpdateOptions) (*kyvernov1alpha2.AdmissionReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, o, opts, c.inner.Update)
}
func (c *admissionReport) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, name, opts, c.inner.Delete)
}
func (c *admissionReport) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *admissionReport) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1alpha2.AdmissionReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, name, opts, c.inner.Get)
}
func (c *admissionReport) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1alpha2.AdmissionReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, opts, c.inner.List)
}
func (c *admissionReport) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, opts, c.inner.Watch)
}
func (c *admissionReport) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1alpha2.AdmissionReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "AdmissionReport", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,58 +0,0 @@
package v1alpha2
import (
"context"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type backgroundScanReport struct {
inner v1alpha2.BackgroundScanReportInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapBackgroundScanReports(c v1alpha2.BackgroundScanReportInterface, m utils.ClientQueryMetric, namespace string) v1alpha2.BackgroundScanReportInterface {
return &backgroundScanReport{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *backgroundScanReport) Create(ctx context.Context, o *kyvernov1alpha2.BackgroundScanReport, opts metav1.CreateOptions) (*kyvernov1alpha2.BackgroundScanReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, o, opts, c.inner.Create)
}
func (c *backgroundScanReport) Update(ctx context.Context, o *kyvernov1alpha2.BackgroundScanReport, opts metav1.UpdateOptions) (*kyvernov1alpha2.BackgroundScanReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, o, opts, c.inner.Update)
}
func (c *backgroundScanReport) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, name, opts, c.inner.Delete)
}
func (c *backgroundScanReport) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *backgroundScanReport) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1alpha2.BackgroundScanReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, name, opts, c.inner.Get)
}
func (c *backgroundScanReport) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1alpha2.BackgroundScanReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, opts, c.inner.List)
}
func (c *backgroundScanReport) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, opts, c.inner.Watch)
}
func (c *backgroundScanReport) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1alpha2.BackgroundScanReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "BackgroundScanReport", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,56 +0,0 @@
package v1alpha2
import (
"context"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type clusterAdmissionReports struct {
inner v1alpha2.ClusterAdmissionReportInterface
clientQueryMetric utils.ClientQueryMetric
}
func wrapClusterAdmissionReports(c v1alpha2.ClusterAdmissionReportInterface, m utils.ClientQueryMetric) v1alpha2.ClusterAdmissionReportInterface {
return &clusterAdmissionReports{
inner: c,
clientQueryMetric: m,
}
}
func (c *clusterAdmissionReports) Create(ctx context.Context, o *kyvernov1alpha2.ClusterAdmissionReport, opts metav1.CreateOptions) (*kyvernov1alpha2.ClusterAdmissionReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", o, opts, c.inner.Create)
}
func (c *clusterAdmissionReports) Update(ctx context.Context, o *kyvernov1alpha2.ClusterAdmissionReport, opts metav1.UpdateOptions) (*kyvernov1alpha2.ClusterAdmissionReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", o, opts, c.inner.Update)
}
func (c *clusterAdmissionReports) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", name, opts, c.inner.Delete)
}
func (c *clusterAdmissionReports) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", opts, listOpts, c.inner.DeleteCollection)
}
func (c *clusterAdmissionReports) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1alpha2.ClusterAdmissionReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", name, opts, c.inner.Get)
}
func (c *clusterAdmissionReports) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1alpha2.ClusterAdmissionReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", opts, c.inner.List)
}
func (c *clusterAdmissionReports) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", opts, c.inner.Watch)
}
func (c *clusterAdmissionReports) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1alpha2.ClusterAdmissionReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "ClusterAdmissionReport", "", name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,56 +0,0 @@
package v1alpha2
import (
"context"
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type clusterBackgroundScanReports struct {
inner v1alpha2.ClusterBackgroundScanReportInterface
clientQueryMetric utils.ClientQueryMetric
}
func wrapClusterBackgroundScanReports(c v1alpha2.ClusterBackgroundScanReportInterface, m utils.ClientQueryMetric) v1alpha2.ClusterBackgroundScanReportInterface {
return &clusterBackgroundScanReports{
inner: c,
clientQueryMetric: m,
}
}
func (c *clusterBackgroundScanReports) Create(ctx context.Context, o *kyvernov1alpha2.ClusterBackgroundScanReport, opts metav1.CreateOptions) (*kyvernov1alpha2.ClusterBackgroundScanReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", o, opts, c.inner.Create)
}
func (c *clusterBackgroundScanReports) Update(ctx context.Context, o *kyvernov1alpha2.ClusterBackgroundScanReport, opts metav1.UpdateOptions) (*kyvernov1alpha2.ClusterBackgroundScanReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", o, opts, c.inner.Update)
}
func (c *clusterBackgroundScanReports) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", name, opts, c.inner.Delete)
}
func (c *clusterBackgroundScanReports) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", opts, listOpts, c.inner.DeleteCollection)
}
func (c *clusterBackgroundScanReports) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1alpha2.ClusterBackgroundScanReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", name, opts, c.inner.Get)
}
func (c *clusterBackgroundScanReports) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1alpha2.ClusterBackgroundScanReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", opts, c.inner.List)
}
func (c *clusterBackgroundScanReports) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", opts, c.inner.Watch)
}
func (c *clusterBackgroundScanReports) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1alpha2.ClusterBackgroundScanReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "ClusterBackgroundScanReport", "", name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,36 +1,66 @@
package v1alpha2
import (
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
"github.com/kyverno/kyverno/pkg/metrics"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"k8s.io/client-go/rest"
)
type client struct {
inner v1alpha2.KyvernoV1alpha2Interface
clientQueryMetric utils.ClientQueryMetric
inner v1alpha2.KyvernoV1alpha2Interface
metrics metrics.MetricsConfigManager
}
func (c *client) ClusterAdmissionReports() v1alpha2.ClusterAdmissionReportInterface {
return wrapClusterAdmissionReports(c.inner.ClusterAdmissionReports(), c.clientQueryMetric)
recorder := metrics.ClusteredClientQueryRecorder(c.metrics, "ClusterAdmissionReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1alpha2.ClusterAdmissionReport]
controllerutils.ListClient[*kyvernov1alpha2.ClusterAdmissionReportList]
}{
metrics.ObjectClient[*kyvernov1alpha2.ClusterAdmissionReport](recorder, c.inner.ClusterAdmissionReports()),
metrics.ListClient[*kyvernov1alpha2.ClusterAdmissionReportList](recorder, c.inner.ClusterAdmissionReports()),
}
}
func (c *client) ClusterBackgroundScanReports() v1alpha2.ClusterBackgroundScanReportInterface {
return wrapClusterBackgroundScanReports(c.inner.ClusterBackgroundScanReports(), c.clientQueryMetric)
recorder := metrics.ClusteredClientQueryRecorder(c.metrics, "ClusterBackgroundScanReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1alpha2.ClusterBackgroundScanReport]
controllerutils.ListClient[*kyvernov1alpha2.ClusterBackgroundScanReportList]
}{
metrics.ObjectClient[*kyvernov1alpha2.ClusterBackgroundScanReport](recorder, c.inner.ClusterBackgroundScanReports()),
metrics.ListClient[*kyvernov1alpha2.ClusterBackgroundScanReportList](recorder, c.inner.ClusterBackgroundScanReports()),
}
}
func (c *client) AdmissionReports(namespace string) v1alpha2.AdmissionReportInterface {
return wrapAdmissionReports(c.inner.AdmissionReports(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "AdmissionReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1alpha2.AdmissionReport]
controllerutils.ListClient[*kyvernov1alpha2.AdmissionReportList]
}{
metrics.ObjectClient[*kyvernov1alpha2.AdmissionReport](recorder, c.inner.AdmissionReports(namespace)),
metrics.ListClient[*kyvernov1alpha2.AdmissionReportList](recorder, c.inner.AdmissionReports(namespace)),
}
}
func (c *client) BackgroundScanReports(namespace string) v1alpha2.BackgroundScanReportInterface {
return wrapBackgroundScanReports(c.inner.BackgroundScanReports(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "BackgroundScanReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1alpha2.BackgroundScanReport]
controllerutils.ListClient[*kyvernov1alpha2.BackgroundScanReportList]
}{
metrics.ObjectClient[*kyvernov1alpha2.BackgroundScanReport](recorder, c.inner.BackgroundScanReports(namespace)),
metrics.ListClient[*kyvernov1alpha2.BackgroundScanReportList](recorder, c.inner.BackgroundScanReports(namespace)),
}
}
func (c *client) RESTClient() rest.Interface {
return c.inner.RESTClient()
}
func Wrap(inner v1alpha2.KyvernoV1alpha2Interface, m utils.ClientQueryMetric) v1alpha2.KyvernoV1alpha2Interface {
return &client{inner, m}
func Wrap(inner v1alpha2.KyvernoV1alpha2Interface, metrics metrics.MetricsConfigManager) v1alpha2.KyvernoV1alpha2Interface {
return &client{inner, metrics}
}

View file

@ -1,24 +1,35 @@
package v1beta1
import (
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1beta1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
"github.com/kyverno/kyverno/pkg/metrics"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"k8s.io/client-go/rest"
)
type client struct {
inner v1beta1.KyvernoV1beta1Interface
clientQueryMetric utils.ClientQueryMetric
inner v1beta1.KyvernoV1beta1Interface
metrics metrics.MetricsConfigManager
}
func (c *client) UpdateRequests(namespace string) v1beta1.UpdateRequestInterface {
return wrapUpdateRequests(c.inner.UpdateRequests(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "UpdateRequest", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*kyvernov1beta1.UpdateRequest]
controllerutils.ListClient[*kyvernov1beta1.UpdateRequestList]
controllerutils.StatusClient[*kyvernov1beta1.UpdateRequest]
}{
metrics.ObjectClient[*kyvernov1beta1.UpdateRequest](recorder, c.inner.UpdateRequests(namespace)),
metrics.ListClient[*kyvernov1beta1.UpdateRequestList](recorder, c.inner.UpdateRequests(namespace)),
metrics.StatusClient[*kyvernov1beta1.UpdateRequest](recorder, c.inner.UpdateRequests(namespace)),
}
}
func (c *client) RESTClient() rest.Interface {
return c.inner.RESTClient()
}
func Wrap(inner v1beta1.KyvernoV1beta1Interface, m utils.ClientQueryMetric) v1beta1.KyvernoV1beta1Interface {
return &client{inner, m}
func Wrap(inner v1beta1.KyvernoV1beta1Interface, metrics metrics.MetricsConfigManager) v1beta1.KyvernoV1beta1Interface {
return &client{inner, metrics}
}

View file

@ -1,62 +0,0 @@
package v1beta1
import (
"context"
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/kyverno/v1beta1"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type updateRequests struct {
inner v1beta1.UpdateRequestInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapUpdateRequests(c v1beta1.UpdateRequestInterface, m utils.ClientQueryMetric, namespace string) v1beta1.UpdateRequestInterface {
return &updateRequests{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *updateRequests) Create(ctx context.Context, o *kyvernov1beta1.UpdateRequest, opts metav1.CreateOptions) (*kyvernov1beta1.UpdateRequest, error) {
return utils.Create(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, o, opts, c.inner.Create)
}
func (c *updateRequests) Update(ctx context.Context, o *kyvernov1beta1.UpdateRequest, opts metav1.UpdateOptions) (*kyvernov1beta1.UpdateRequest, error) {
return utils.Update(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, o, opts, c.inner.Update)
}
func (c *updateRequests) UpdateStatus(ctx context.Context, o *kyvernov1beta1.UpdateRequest, opts metav1.UpdateOptions) (*kyvernov1beta1.UpdateRequest, error) {
return utils.UpdateStatus(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, o, opts, c.inner.UpdateStatus)
}
func (c *updateRequests) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, name, opts, c.inner.Delete)
}
func (c *updateRequests) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *updateRequests) Get(ctx context.Context, name string, opts metav1.GetOptions) (*kyvernov1beta1.UpdateRequest, error) {
return utils.Get(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, name, opts, c.inner.Get)
}
func (c *updateRequests) List(ctx context.Context, opts metav1.ListOptions) (*kyvernov1beta1.UpdateRequestList, error) {
return utils.List(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, opts, c.inner.List)
}
func (c *updateRequests) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, opts, c.inner.Watch)
}
func (c *updateRequests) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kyvernov1beta1.UpdateRequest, error) {
return utils.Patch(ctx, c.clientQueryMetric, "UpdateRequest", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,56 +0,0 @@
package v1alpha2
import (
"context"
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type clusterPolicyReports struct {
inner v1alpha2.ClusterPolicyReportInterface
clientQueryMetric utils.ClientQueryMetric
}
func wrapClusterPolicyReports(c v1alpha2.ClusterPolicyReportInterface, m utils.ClientQueryMetric) v1alpha2.ClusterPolicyReportInterface {
return &clusterPolicyReports{
inner: c,
clientQueryMetric: m,
}
}
func (c *clusterPolicyReports) Create(ctx context.Context, o *policyreportv1alpha2.ClusterPolicyReport, opts metav1.CreateOptions) (*policyreportv1alpha2.ClusterPolicyReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", o, opts, c.inner.Create)
}
func (c *clusterPolicyReports) Update(ctx context.Context, o *policyreportv1alpha2.ClusterPolicyReport, opts metav1.UpdateOptions) (*policyreportv1alpha2.ClusterPolicyReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", o, opts, c.inner.Update)
}
func (c *clusterPolicyReports) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", name, opts, c.inner.Delete)
}
func (c *clusterPolicyReports) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", opts, listOpts, c.inner.DeleteCollection)
}
func (c *clusterPolicyReports) Get(ctx context.Context, name string, opts metav1.GetOptions) (*policyreportv1alpha2.ClusterPolicyReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", name, opts, c.inner.Get)
}
func (c *clusterPolicyReports) List(ctx context.Context, opts metav1.ListOptions) (*policyreportv1alpha2.ClusterPolicyReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", opts, c.inner.List)
}
func (c *clusterPolicyReports) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", opts, c.inner.Watch)
}
func (c *clusterPolicyReports) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*policyreportv1alpha2.ClusterPolicyReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "ClusterPolicyReport", "", name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,58 +0,0 @@
package v1alpha2
import (
"context"
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type policyReports struct {
inner v1alpha2.PolicyReportInterface
clientQueryMetric utils.ClientQueryMetric
ns string
}
func wrapPolicyReports(c v1alpha2.PolicyReportInterface, m utils.ClientQueryMetric, namespace string) v1alpha2.PolicyReportInterface {
return &policyReports{
inner: c,
clientQueryMetric: m,
ns: namespace,
}
}
func (c *policyReports) Create(ctx context.Context, o *policyreportv1alpha2.PolicyReport, opts metav1.CreateOptions) (*policyreportv1alpha2.PolicyReport, error) {
return utils.Create(ctx, c.clientQueryMetric, "PolicyReport", c.ns, o, opts, c.inner.Create)
}
func (c *policyReports) Update(ctx context.Context, o *policyreportv1alpha2.PolicyReport, opts metav1.UpdateOptions) (*policyreportv1alpha2.PolicyReport, error) {
return utils.Update(ctx, c.clientQueryMetric, "PolicyReport", c.ns, o, opts, c.inner.Update)
}
func (c *policyReports) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return utils.Delete(ctx, c.clientQueryMetric, "PolicyReport", c.ns, name, opts, c.inner.Delete)
}
func (c *policyReports) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return utils.DeleteCollection(ctx, c.clientQueryMetric, "PolicyReport", c.ns, opts, listOpts, c.inner.DeleteCollection)
}
func (c *policyReports) Get(ctx context.Context, name string, opts metav1.GetOptions) (*policyreportv1alpha2.PolicyReport, error) {
return utils.Get(ctx, c.clientQueryMetric, "PolicyReport", c.ns, name, opts, c.inner.Get)
}
func (c *policyReports) List(ctx context.Context, opts metav1.ListOptions) (*policyreportv1alpha2.PolicyReportList, error) {
return utils.List(ctx, c.clientQueryMetric, "PolicyReport", c.ns, opts, c.inner.List)
}
func (c *policyReports) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return utils.Watch(ctx, c.clientQueryMetric, "PolicyReport", c.ns, opts, c.inner.Watch)
}
func (c *policyReports) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*policyreportv1alpha2.PolicyReport, error) {
return utils.Patch(ctx, c.clientQueryMetric, "PolicyReport", c.ns, name, pt, data, opts, c.inner.Patch, subresources...)
}

View file

@ -1,28 +1,44 @@
package v1alpha2
import (
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/typed/policyreport/v1alpha2"
"github.com/kyverno/kyverno/pkg/clients/wrappers/utils"
"github.com/kyverno/kyverno/pkg/metrics"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"k8s.io/client-go/rest"
)
type client struct {
inner v1alpha2.Wgpolicyk8sV1alpha2Interface
clientQueryMetric utils.ClientQueryMetric
inner v1alpha2.Wgpolicyk8sV1alpha2Interface
metrics metrics.MetricsConfigManager
}
func (c *client) ClusterPolicyReports() v1alpha2.ClusterPolicyReportInterface {
return wrapClusterPolicyReports(c.inner.ClusterPolicyReports(), c.clientQueryMetric)
recorder := metrics.ClusteredClientQueryRecorder(c.metrics, "ClusterPolicyReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*policyreportv1alpha2.ClusterPolicyReport]
controllerutils.ListClient[*policyreportv1alpha2.ClusterPolicyReportList]
}{
metrics.ObjectClient[*policyreportv1alpha2.ClusterPolicyReport](recorder, c.inner.ClusterPolicyReports()),
metrics.ListClient[*policyreportv1alpha2.ClusterPolicyReportList](recorder, c.inner.ClusterPolicyReports()),
}
}
func (c *client) PolicyReports(namespace string) v1alpha2.PolicyReportInterface {
return wrapPolicyReports(c.inner.PolicyReports(namespace), c.clientQueryMetric, namespace)
recorder := metrics.NamespacedClientQueryRecorder(c.metrics, namespace, "PolicyReport", metrics.KyvernoClient)
return struct {
controllerutils.ObjectClient[*policyreportv1alpha2.PolicyReport]
controllerutils.ListClient[*policyreportv1alpha2.PolicyReportList]
}{
metrics.ObjectClient[*policyreportv1alpha2.PolicyReport](recorder, c.inner.PolicyReports(namespace)),
metrics.ListClient[*policyreportv1alpha2.PolicyReportList](recorder, c.inner.PolicyReports(namespace)),
}
}
func (c *client) RESTClient() rest.Interface {
return c.inner.RESTClient()
}
func Wrap(inner v1alpha2.Wgpolicyk8sV1alpha2Interface, m utils.ClientQueryMetric) v1alpha2.Wgpolicyk8sV1alpha2Interface {
return &client{inner, m}
func Wrap(inner v1alpha2.Wgpolicyk8sV1alpha2Interface, metrics metrics.MetricsConfigManager) v1alpha2.Wgpolicyk8sV1alpha2Interface {
return &client{inner, metrics}
}

View file

@ -1,24 +0,0 @@
package utils
import "github.com/kyverno/kyverno/pkg/metrics"
type ClientQueryMetric interface {
Record(clientQueryOperation metrics.ClientQueryOperation, clientType metrics.ClientType, resourceKind string, resourceNamespace string)
}
type metricsConfig struct {
metricsConfig *metrics.MetricsConfig
}
func NewClientQueryMetric(m *metrics.MetricsConfig) ClientQueryMetric {
return &metricsConfig{
metricsConfig: m,
}
}
func (c *metricsConfig) Record(clientQueryOperation metrics.ClientQueryOperation, clientType metrics.ClientType, resourceKind string, resourceNamespace string) {
if c.metricsConfig == nil {
return
}
c.metricsConfig.RecordClientQueries(clientQueryOperation, clientType, resourceKind, resourceNamespace)
}

View file

@ -1,55 +0,0 @@
package utils
import (
"context"
"github.com/kyverno/kyverno/pkg/metrics"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
func Create[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, o *K, opts metav1.CreateOptions, inner func(context.Context, *K, metav1.CreateOptions) (*K, error)) (*K, error) {
m.Record(metrics.ClientCreate, metrics.KyvernoClient, kind, ns)
return inner(ctx, o, opts)
}
func Update[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, o *K, opts metav1.UpdateOptions, inner func(context.Context, *K, metav1.UpdateOptions) (*K, error)) (*K, error) {
m.Record(metrics.ClientUpdate, metrics.KyvernoClient, kind, ns)
return inner(ctx, o, opts)
}
func UpdateStatus[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, o *K, opts metav1.UpdateOptions, inner func(context.Context, *K, metav1.UpdateOptions) (*K, error)) (*K, error) {
m.Record(metrics.ClientUpdateStatus, metrics.KyvernoClient, kind, ns)
return inner(ctx, o, opts)
}
func Delete(ctx context.Context, m ClientQueryMetric, kind string, ns string, name string, opts metav1.DeleteOptions, inner func(context.Context, string, metav1.DeleteOptions) error) error {
m.Record(metrics.ClientDelete, metrics.KyvernoClient, kind, ns)
return inner(ctx, name, opts)
}
func DeleteCollection(ctx context.Context, m ClientQueryMetric, kind string, ns string, opts metav1.DeleteOptions, listOpts metav1.ListOptions, inner func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error) error {
m.Record(metrics.ClientDeleteCollection, metrics.KyvernoClient, kind, ns)
return inner(ctx, opts, listOpts)
}
func Get[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, name string, opts metav1.GetOptions, inner func(context.Context, string, metav1.GetOptions) (*K, error)) (*K, error) {
m.Record(metrics.ClientGet, metrics.KyvernoClient, kind, ns)
return inner(ctx, name, opts)
}
func List[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, opts metav1.ListOptions, inner func(context.Context, metav1.ListOptions) (*K, error)) (*K, error) {
m.Record(metrics.ClientList, metrics.KyvernoClient, kind, ns)
return inner(ctx, opts)
}
func Watch(ctx context.Context, m ClientQueryMetric, kind string, ns string, opts metav1.ListOptions, inner func(context.Context, metav1.ListOptions) (watch.Interface, error)) (watch.Interface, error) {
m.Record(metrics.ClientWatch, metrics.KyvernoClient, kind, ns)
return inner(ctx, opts)
}
func Patch[K any](ctx context.Context, m ClientQueryMetric, kind string, ns string, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, inner func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*K, error), subresources ...string) (*K, error) {
m.Record(metrics.ClientPatch, metrics.KyvernoClient, kind, ns)
return inner(ctx, name, pt, data, opts, subresources...)
}

124
pkg/metrics/client.go Normal file
View file

@ -0,0 +1,124 @@
package metrics
import (
"context"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type Recorder interface {
Record(clientQueryOperation ClientQueryOperation)
}
type clientQueryRecorder struct {
manager MetricsConfigManager
ns string
kind string
client ClientType
}
func NamespacedClientQueryRecorder(m MetricsConfigManager, ns, kind string, client ClientType) Recorder {
return &clientQueryRecorder{
manager: m,
ns: ns,
kind: kind,
client: client,
}
}
func ClusteredClientQueryRecorder(m MetricsConfigManager, kind string, client ClientType) Recorder {
return &clientQueryRecorder{
manager: m,
kind: kind,
client: client,
}
}
func (r *clientQueryRecorder) Record(clientQueryOperation ClientQueryOperation) {
r.manager.RecordClientQueries(clientQueryOperation, r.client, r.kind, r.ns)
}
type objectClient[T metav1.Object] struct {
recorder Recorder
inner controllerutils.ObjectClient[T]
}
func (c *objectClient[T]) Create(ctx context.Context, obj T, opts metav1.CreateOptions) (T, error) {
defer c.recorder.Record(ClientCreate)
return c.inner.Create(ctx, obj, opts)
}
func (c *objectClient[T]) Update(ctx context.Context, obj T, opts metav1.UpdateOptions) (T, error) {
defer c.recorder.Record(ClientUpdate)
return c.inner.Update(ctx, obj, opts)
}
func (c *objectClient[T]) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
defer c.recorder.Record(ClientDelete)
return c.inner.Delete(ctx, name, opts)
}
func (c *objectClient[T]) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
defer c.recorder.Record(ClientDeleteCollection)
return c.inner.DeleteCollection(ctx, opts, listOpts)
}
func (c *objectClient[T]) Get(ctx context.Context, name string, opts metav1.GetOptions) (T, error) {
defer c.recorder.Record(ClientGet)
return c.inner.Get(ctx, name, opts)
}
func (c *objectClient[T]) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
defer c.recorder.Record(ClientUpdate)
return c.inner.Watch(ctx, opts)
}
func (c *objectClient[T]) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (T, error) {
defer c.recorder.Record(ClientPatch)
return c.inner.Patch(ctx, name, pt, data, opts, subresources...)
}
type listClient[T any] struct {
recorder Recorder
inner controllerutils.ListClient[T]
}
func (c *listClient[T]) List(ctx context.Context, opts metav1.ListOptions) (T, error) {
defer c.recorder.Record(ClientList)
return c.inner.List(ctx, opts)
}
type statusClient[T metav1.Object] struct {
recorder Recorder
inner controllerutils.StatusClient[T]
}
func (c *statusClient[T]) UpdateStatus(ctx context.Context, obj T, opts metav1.UpdateOptions) (T, error) {
defer c.recorder.Record(ClientUpdateStatus)
return c.inner.UpdateStatus(ctx, obj, opts)
}
func ObjectClient[T metav1.Object](recorder Recorder, inner controllerutils.ObjectClient[T],
) controllerutils.ObjectClient[T] {
return &objectClient[T]{
recorder: recorder,
inner: inner,
}
}
func StatusClient[T metav1.Object](recorder Recorder, inner controllerutils.StatusClient[T]) controllerutils.StatusClient[T] {
return &statusClient[T]{
recorder: recorder,
inner: inner,
}
}
func ListClient[T any](recorder Recorder, inner controllerutils.ListClient[T]) controllerutils.ListClient[T] {
return &listClient[T]{
recorder: recorder,
inner: inner,
}
}

View file

@ -4,20 +4,18 @@ import (
"context"
"github.com/kyverno/kyverno/pkg/config"
"github.com/kyverno/kyverno/pkg/metrics"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
var ErrorsNotFound = "root CA certificate not found"
// ReadRootCASecret returns the RootCA from the pre-defined secret
func ReadRootCASecret(client kubernetes.Interface, metricsConfig metrics.MetricsConfigManager) ([]byte, error) {
func ReadRootCASecret(client controllerutils.GetClient[*corev1.Secret]) ([]byte, error) {
sname := GenerateRootCASecretName()
stlsca, err := client.CoreV1().Secrets(config.KyvernoNamespace()).Get(context.TODO(), sname, metav1.GetOptions{})
metricsConfig.RecordClientQueries(metrics.ClientGet, metrics.KubeClient, "Secret", config.KyvernoNamespace())
stlsca, err := client.Get(context.TODO(), sname, metav1.GetOptions{})
if err != nil {
return nil, err
}

View file

@ -6,9 +6,73 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
)
type CreateClient[T metav1.Object] interface {
Create(context.Context, T, metav1.CreateOptions) (T, error)
}
type UpdateClient[T metav1.Object] interface {
Update(context.Context, T, metav1.UpdateOptions) (T, error)
}
type DeleteClient[T metav1.Object] interface {
Delete(context.Context, string, metav1.DeleteOptions) error
}
type DeleteCollectionClient[T metav1.Object] interface {
DeleteCollection(context.Context, metav1.DeleteOptions, metav1.ListOptions) error
}
type GetClient[T metav1.Object] interface {
Get(context.Context, string, metav1.GetOptions) (T, error)
}
type WatchClient[T metav1.Object] interface {
Watch(context.Context, metav1.ListOptions) (watch.Interface, error)
}
type PatchClient[T metav1.Object] interface {
Patch(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (T, error)
}
type ObjectClient[T metav1.Object] interface {
CreateClient[T]
UpdateClient[T]
DeleteClient[T]
DeleteCollectionClient[T]
GetClient[T]
WatchClient[T]
PatchClient[T]
}
type ListClient[T any] interface {
List(context.Context, metav1.ListOptions) (T, error)
}
type StatusClient[T metav1.Object] interface {
UpdateStatus(context.Context, T, metav1.UpdateOptions) (T, error)
}
type ObjectListClient[T metav1.Object, L any] interface {
ObjectClient[T]
ListClient[L]
}
type ObjectStatusClient[T metav1.Object] interface {
ObjectClient[T]
StatusClient[T]
}
type ObjectListStatusClient[T metav1.Object, L any] interface {
ObjectClient[T]
ListClient[L]
StatusClient[T]
}
type Object[T any] interface {
*T
metav1.Object

View file

@ -50,10 +50,11 @@ func (wrc *Register) readCaData() []byte {
logger := wrc.log.WithName("readCaData")
var caData []byte
var err error
recorder := metrics.NamespacedClientQueryRecorder(wrc.metricsConfig, config.KyvernoNamespace(), "Secret", metrics.KubeClient)
secretsClient := metrics.ObjectClient[*corev1.Secret](recorder, wrc.kubeClient.CoreV1().Secrets(config.KyvernoNamespace()))
// Check if ca is defined in the secret tls-ca
// assume the key and signed cert have been defined in secret tls.kyverno
if caData, err = tls.ReadRootCASecret(wrc.kubeClient, wrc.metricsConfig); err == nil {
if caData, err = tls.ReadRootCASecret(secretsClient); err == nil {
logger.V(4).Info("read CA from secret")
return caData
}