Skip to content

Commit

Permalink
[webhook] Update webhook functions for CR update
Browse files Browse the repository at this point in the history
This change updates the webhook functions to comply with the new
standard for controller-runtime.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Feb 14, 2024
1 parent 97b0a95 commit e2e053a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions api/v1beta1/heat_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -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))
}

Expand All @@ -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
}

0 comments on commit e2e053a

Please sign in to comment.