@@ -9,12 +9,10 @@ import (
99 "github.com/netobserv/network-observability-operator/internal/pkg/helper/cardinality"
1010
1111 apierrors "k8s.io/apimachinery/pkg/api/errors"
12- "k8s.io/apimachinery/pkg/runtime"
1312 "k8s.io/apimachinery/pkg/runtime/schema"
1413 "k8s.io/apimachinery/pkg/util/validation/field"
1514 ctrl "sigs.k8s.io/controller-runtime"
1615 logf "sigs.k8s.io/controller-runtime/pkg/log"
17- "sigs.k8s.io/controller-runtime/pkg/webhook"
1816 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1917)
2018
@@ -26,39 +24,26 @@ type FlowMetricWebhook struct {
2624}
2725
2826// +kubebuilder:webhook:verbs=create;update,path=/validate-flows-netobserv-io-v1alpha1-flowmetric,mutating=false,failurePolicy=fail,sideEffects=None,groups=flows.netobserv.io,resources=flowmetrics,versions=v1alpha1,name=flowmetricvalidationwebhook.netobserv.io,admissionReviewVersions=v1
29- var (
30- _ webhook.CustomValidator = & FlowMetricWebhook {FlowMetric {}}
31- )
32-
3327func (r * FlowMetricWebhook ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
34- return ctrl .NewWebhookManagedBy (mgr ).
35- For (& FlowMetric {}).
28+ return ctrl .NewWebhookManagedBy (mgr , & FlowMetric {}).
3629 WithValidator (& FlowMetricWebhook {}).
3730 Complete ()
3831}
3932
4033// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
41- func (r * FlowMetricWebhook ) ValidateCreate (ctx context.Context , newObj runtime. Object ) (warnings admission.Warnings , err error ) {
34+ func (r * FlowMetricWebhook ) ValidateCreate (ctx context.Context , fm * FlowMetric ) (warnings admission.Warnings , err error ) {
4235 flowmetriclog .Info ("validate create" , "name" , r .Name )
43- newFlowMetric , ok := newObj .(* FlowMetric )
44- if ! ok {
45- return nil , apierrors .NewBadRequest (fmt .Sprintf ("expected an FlowMetric but got a %T" , newObj ))
46- }
47- return validateFlowMetric (ctx , newFlowMetric )
36+ return validateFlowMetric (ctx , fm )
4837}
4938
5039// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
51- func (r * FlowMetricWebhook ) ValidateUpdate (ctx context.Context , _ , newObj runtime. Object ) (warnings admission.Warnings , err error ) {
40+ func (r * FlowMetricWebhook ) ValidateUpdate (ctx context.Context , _ , fm * FlowMetric ) (warnings admission.Warnings , err error ) {
5241 flowmetriclog .Info ("validate update" , "name" , r .Name )
53- newFlowMetric , ok := newObj .(* FlowMetric )
54- if ! ok {
55- return nil , apierrors .NewBadRequest (fmt .Sprintf ("expected an FlowMetric but got a %T" , newObj ))
56- }
57- return validateFlowMetric (ctx , newFlowMetric )
42+ return validateFlowMetric (ctx , fm )
5843}
5944
6045// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
61- func (r * FlowMetricWebhook ) ValidateDelete (_ context.Context , _ runtime. Object ) (warnings admission.Warnings , err error ) {
46+ func (r * FlowMetricWebhook ) ValidateDelete (_ context.Context , _ * FlowMetric ) (warnings admission.Warnings , err error ) {
6247 flowmetriclog .Info ("validate delete" , "name" , r .Name )
6348 return nil , nil
6449}
0 commit comments