Skip to content

Commit 1a6e19d

Browse files
committed
Fix breaking changes
1 parent 2e13049 commit 1a6e19d

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

api/flowcollector/v1beta2/flowcollector_validation_webhook.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strings"
1212

1313
"github.com/netobserv/flowlogs-pipeline/pkg/dsl"
14-
kerr "k8s.io/apimachinery/pkg/api/errors"
15-
runtime "k8s.io/apimachinery/pkg/runtime"
1614
"k8s.io/apimachinery/pkg/util/intstr"
1715
logf "sigs.k8s.io/controller-runtime/pkg/log"
1816
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -33,27 +31,19 @@ var (
3331
)
3432

3533
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
36-
func (r *FlowCollector) ValidateCreate(ctx context.Context, newObj runtime.Object) (admission.Warnings, error) {
34+
func (r *FlowCollector) ValidateCreate(ctx context.Context, fc *FlowCollector) (admission.Warnings, error) {
3735
log.Info("validate create", "name", r.Name)
38-
fc, ok := newObj.(*FlowCollector)
39-
if !ok {
40-
return nil, kerr.NewBadRequest(fmt.Sprintf("expected a FlowCollector but got a %T", newObj))
41-
}
4236
return r.Validate(ctx, fc)
4337
}
4438

4539
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
46-
func (r *FlowCollector) ValidateUpdate(ctx context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
40+
func (r *FlowCollector) ValidateUpdate(ctx context.Context, _, fc *FlowCollector) (admission.Warnings, error) {
4741
log.Info("validate update", "name", r.Name)
48-
fc, ok := newObj.(*FlowCollector)
49-
if !ok {
50-
return nil, kerr.NewBadRequest(fmt.Sprintf("expected a FlowCollector but got a %T", newObj))
51-
}
5242
return r.Validate(ctx, fc)
5343
}
5444

5545
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
56-
func (r *FlowCollector) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
46+
func (r *FlowCollector) ValidateDelete(_ context.Context, _ *FlowCollector) (admission.Warnings, error) {
5747
log.Info("validate delete", "name", r.Name)
5848
return nil, nil
5949
}

api/flowcollector/v1beta2/flowcollector_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222

2323
// +kubebuilder:webhook:verbs=create;update,path=/validate-flows-netobserv-io-v1beta2-flowcollector,mutating=false,failurePolicy=fail,sideEffects=None,groups=flows.netobserv.io,resources=flowcollectors,versions=v1beta2,name=flowcollectorconversionwebhook.netobserv.io,admissionReviewVersions=v1
2424
func (r *FlowCollector) SetupWebhookWithManager(mgr ctrl.Manager) error {
25-
return ctrl.NewWebhookManagedBy(mgr).
26-
For(r).
25+
return ctrl.NewWebhookManagedBy(mgr, r).
2726
WithValidator(r).
2827
Complete()
2928
}

api/flowmetrics/v1alpha1/flowmetric_webhook.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
3327
func (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

Comments
 (0)