From e2e053a11f2e2decabe900519b951d6e72b2fc67 Mon Sep 17 00:00:00 2001 From: Brendan Shephard Date: Wed, 7 Feb 2024 11:30:08 +1000 Subject: [PATCH] [webhook] Update webhook functions for CR update This change updates the webhook functions to comply with the new standard for controller-runtime. Signed-off-by: Brendan Shephard --- api/v1beta1/heat_webhook.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api/v1beta1/heat_webhook.go b/api/v1beta1/heat_webhook.go index f4b7df72..dc86e5e8 100644 --- a/api/v1beta1/heat_webhook.go +++ b/api/v1beta1/heat_webhook.go @@ -32,6 +32,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" + "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) // HeatDefaults - @@ -89,19 +90,19 @@ func (spec *HeatSpec) Default() { var _ webhook.Validator = &Heat{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *Heat) ValidateCreate() error { +func (r *Heat) ValidateCreate() (admission.Warnings, error) { heatlog.Info("validate create", "name", r.Name) // TODO(user): fill in your validation logic upon object creation. - return nil + return nil, nil } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Heat) ValidateUpdate(old runtime.Object) error { +func (r *Heat) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { heatlog.Info("validate update", "name", r.Name) oldHeat, ok := old.(*Heat) if !ok { - return apierrors.NewInternalError( + return nil, apierrors.NewInternalError( fmt.Errorf("Expected a Heatv1 object, but got %T", oldHeat)) } @@ -116,20 +117,20 @@ func (r *Heat) ValidateUpdate(old runtime.Object) error { } if errors != nil { - return apierrors.NewInvalid( + return nil, apierrors.NewInvalid( schema.GroupKind{Group: "heat.openstack.org", Kind: "Heat"}, r.Name, errors, ) } - return nil + return nil, nil } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *Heat) ValidateDelete() error { +func (r *Heat) ValidateDelete() (admission.Warnings, error) { heatlog.Info("validate delete", "name", r.Name) // TODO(user): fill in your validation logic upon object deletion. - return nil + return nil, nil }