Skip to content

Commit 55d0e32

Browse files
authored
Remove usage of deprecated webhook.Validator and webhook.Defaulter interfaces (#2289)
1 parent f730dfe commit 55d0e32

13 files changed

+238
-227
lines changed

Diff for: api/v1beta2/ibmpowervscluster_webhook.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"strconv"
2223

@@ -28,51 +29,51 @@ import (
2829
"k8s.io/apimachinery/pkg/util/validation/field"
2930

3031
ctrl "sigs.k8s.io/controller-runtime"
31-
logf "sigs.k8s.io/controller-runtime/pkg/log"
3232
"sigs.k8s.io/controller-runtime/pkg/webhook"
3333
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3434

3535
genUtil "sigs.k8s.io/cluster-api-provider-ibmcloud/util"
3636
)
3737

38-
// log is for logging in this package.
39-
var ibmpowervsclusterlog = logf.Log.WithName("ibmpowervscluster-resource")
38+
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervscluster,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclusters,verbs=create;update,versions=v1beta2,name=mibmpowervscluster.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
39+
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervscluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclusters,versions=v1beta2,name=vibmpowervscluster.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4040

4141
func (r *IBMPowerVSCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
4242
return ctrl.NewWebhookManagedBy(mgr).
43-
For(r).
43+
For(&IBMPowerVSCluster{}).
44+
WithValidator(r).
45+
WithDefaulter(r).
4446
Complete()
4547
}
4648

47-
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervscluster,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclusters,verbs=create;update,versions=v1beta2,name=mibmpowervscluster.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
49+
var _ webhook.CustomDefaulter = &IBMPowerVSCluster{}
50+
var _ webhook.CustomValidator = &IBMPowerVSCluster{}
4851

49-
var _ webhook.Defaulter = &IBMPowerVSCluster{}
50-
51-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
52-
func (r *IBMPowerVSCluster) Default() {
53-
ibmpowervsclusterlog.Info("default", "name", r.Name)
52+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
53+
func (r *IBMPowerVSCluster) Default(_ context.Context, _ runtime.Object) error {
54+
return nil
5455
}
5556

56-
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
57-
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervscluster,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclusters,versions=v1beta2,name=vibmpowervscluster.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
58-
59-
var _ webhook.Validator = &IBMPowerVSCluster{}
60-
61-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
62-
func (r *IBMPowerVSCluster) ValidateCreate() (admission.Warnings, error) {
63-
ibmpowervsclusterlog.Info("validate create", "name", r.Name)
64-
return r.validateIBMPowerVSCluster()
57+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
58+
func (r *IBMPowerVSCluster) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
59+
objValue, ok := obj.(*IBMPowerVSCluster)
60+
if !ok {
61+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a IBMPowerVSCluster but got a %T", obj))
62+
}
63+
return objValue.validateIBMPowerVSCluster()
6564
}
6665

67-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
68-
func (r *IBMPowerVSCluster) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
69-
ibmpowervsclusterlog.Info("validate update", "name", r.Name)
70-
return r.validateIBMPowerVSCluster()
66+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
67+
func (r *IBMPowerVSCluster) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (warnings admission.Warnings, err error) {
68+
objValue, ok := newObj.(*IBMPowerVSCluster)
69+
if !ok {
70+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a IBMPowerVSCluster but got a %T", newObj))
71+
}
72+
return objValue.validateIBMPowerVSCluster()
7173
}
7274

73-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
74-
func (r *IBMPowerVSCluster) ValidateDelete() (admission.Warnings, error) {
75-
ibmpowervsclusterlog.Info("validate delete", "name", r.Name)
75+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
76+
func (r *IBMPowerVSCluster) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
7677
return nil, nil
7778
}
7879

Diff for: api/v1beta2/ibmpowervsclustertemplate_webhook.go

+24-28
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,59 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"reflect"
2223

2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/runtime"
2526

2627
ctrl "sigs.k8s.io/controller-runtime"
27-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2828
"sigs.k8s.io/controller-runtime/pkg/webhook"
2929
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3030
)
3131

32-
// log is for logging in this package.
33-
var ibmpowervsclustertemplatelog = logf.Log.WithName("ibmpowervsclustertemplate-resource")
32+
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsclustertemplate,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclustertemplates,verbs=create;update,versions=v1beta2,name=mibmpowervsclustertemplate.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
33+
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsclustertemplate,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclustertemplates,versions=v1beta2,name=vibmpowervsclustertemplate.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3434

3535
func (r *IBMPowerVSClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
3636
return ctrl.NewWebhookManagedBy(mgr).
37-
For(r).
37+
For(&IBMPowerVSClusterTemplate{}).
38+
WithValidator(r).
39+
WithDefaulter(r).
3840
Complete()
3941
}
4042

41-
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsclustertemplate,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclustertemplates,verbs=create;update,versions=v1beta2,name=mibmpowervsclustertemplate.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
42-
43-
var _ webhook.Defaulter = &IBMPowerVSClusterTemplate{}
43+
var _ webhook.CustomDefaulter = &IBMPowerVSClusterTemplate{}
44+
var _ webhook.CustomValidator = &IBMPowerVSClusterTemplate{}
4445

45-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
46-
func (r *IBMPowerVSClusterTemplate) Default() {
47-
ibmpowervsclustertemplatelog.Info("default", "name", r.Name)
46+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
47+
func (r *IBMPowerVSClusterTemplate) Default(_ context.Context, _ runtime.Object) error {
48+
return nil
4849
}
4950

50-
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsclustertemplate,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsclustertemplates,versions=v1beta2,name=vibmpowervsclustertemplate.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
51-
52-
var _ webhook.Validator = &IBMPowerVSClusterTemplate{}
53-
54-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
55-
func (r *IBMPowerVSClusterTemplate) ValidateCreate() (admission.Warnings, error) {
56-
ibmpowervsclustertemplatelog.Info("validate create", "name", r.Name)
57-
51+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
52+
func (r *IBMPowerVSClusterTemplate) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5853
return nil, nil
5954
}
6055

61-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
62-
func (r *IBMPowerVSClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
63-
ibmpowervsclustertemplatelog.Info("validate update", "name", r.Name)
64-
old, ok := oldRaw.(*IBMPowerVSClusterTemplate)
56+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
57+
func (r *IBMPowerVSClusterTemplate) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (warnings admission.Warnings, err error) {
58+
oldObjValue, ok := oldObj.(*IBMPowerVSClusterTemplate)
6559
if !ok {
66-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an IBMPowerVSClusterTemplate but got a %T", oldRaw))
60+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an IBMPowerVSClusterTemplate but got a %T", oldObj))
6761
}
68-
if !reflect.DeepEqual(r.Spec, old.Spec) {
62+
newObjValue, ok := newObj.(*IBMPowerVSClusterTemplate)
63+
if !ok {
64+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an IBMPowerVSClusterTemplate but got a %T", newObj))
65+
}
66+
if !reflect.DeepEqual(newObjValue.Spec, oldObjValue.Spec) {
6967
return nil, apierrors.NewBadRequest("IBMPowerVSClusterTemplate.Spec is immutable")
7068
}
7169
return nil, nil
7270
}
7371

74-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
75-
func (r *IBMPowerVSClusterTemplate) ValidateDelete() (admission.Warnings, error) {
76-
ibmpowervsclustertemplatelog.Info("validate delete", "name", r.Name)
77-
72+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
73+
func (r *IBMPowerVSClusterTemplate) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
7874
return nil, nil
7975
}

Diff for: api/v1beta2/ibmpowervsclustertemplate_webhook_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestIBMPowerVSClusterTemplate_ValidateUpdate(t *testing.T) {
7878
}
7979
for _, test := range tests {
8080
t.Run(test.name, func(_ *testing.T) {
81-
_, err := test.newTemplate.ValidateUpdate(test.oldTemplate)
81+
_, err := test.newTemplate.ValidateUpdate(ctx, test.oldTemplate, test.newTemplate)
8282
if test.wantErr {
8383
g.Expect(err).To(HaveOccurred())
8484
} else {

Diff for: api/v1beta2/ibmpowervsimage_webhook.go

+18-24
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,45 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
21+
2022
"k8s.io/apimachinery/pkg/runtime"
2123

2224
ctrl "sigs.k8s.io/controller-runtime"
23-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2425
"sigs.k8s.io/controller-runtime/pkg/webhook"
2526
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2627
)
2728

28-
// log is for logging in this package.
29-
var ibmpowervsimagelog = logf.Log.WithName("ibmpowervsimage-resource")
29+
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsimage,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,verbs=create;update,versions=v1beta2,name=mibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
30+
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsimage,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,versions=v1beta2,name=vibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3031

3132
func (r *IBMPowerVSImage) SetupWebhookWithManager(mgr ctrl.Manager) error {
3233
return ctrl.NewWebhookManagedBy(mgr).
33-
For(r).
34+
For(&IBMPowerVSImage{}).
35+
WithValidator(r).
36+
WithDefaulter(r).
3437
Complete()
3538
}
3639

37-
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsimage,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,verbs=create;update,versions=v1beta2,name=mibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
38-
39-
var _ webhook.Defaulter = &IBMPowerVSImage{}
40+
var _ webhook.CustomDefaulter = &IBMPowerVSImage{}
41+
var _ webhook.CustomValidator = &IBMPowerVSImage{}
4042

41-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
42-
func (r *IBMPowerVSImage) Default() {
43-
ibmpowervsimagelog.Info("default", "name", r.Name)
43+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
44+
func (r *IBMPowerVSImage) Default(_ context.Context, _ runtime.Object) error {
45+
return nil
4446
}
4547

46-
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
47-
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsimage,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,versions=v1beta2,name=vibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
48-
49-
var _ webhook.Validator = &IBMPowerVSImage{}
50-
51-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
52-
func (r *IBMPowerVSImage) ValidateCreate() (admission.Warnings, error) {
53-
ibmpowervsimagelog.Info("validate create", "name", r.Name)
48+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
49+
func (r *IBMPowerVSImage) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5450
return nil, nil
5551
}
5652

57-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
58-
func (r *IBMPowerVSImage) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
59-
ibmpowervsimagelog.Info("validate update", "name", r.Name)
53+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
54+
func (r *IBMPowerVSImage) ValidateUpdate(_ context.Context, _, _ runtime.Object) (warnings admission.Warnings, err error) {
6055
return nil, nil
6156
}
6257

63-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
64-
func (r *IBMPowerVSImage) ValidateDelete() (admission.Warnings, error) {
65-
ibmpowervsimagelog.Info("validate delete", "name", r.Name)
58+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
59+
func (r *IBMPowerVSImage) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
6660
return nil, nil
6761
}

Diff for: api/v1beta2/ibmpowervsmachine_webhook.go

+34-26
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,63 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
21+
"fmt"
22+
2023
apierrors "k8s.io/apimachinery/pkg/api/errors"
2124
"k8s.io/apimachinery/pkg/runtime"
2225
"k8s.io/apimachinery/pkg/runtime/schema"
2326
"k8s.io/apimachinery/pkg/util/validation/field"
2427

2528
ctrl "sigs.k8s.io/controller-runtime"
26-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2729
"sigs.k8s.io/controller-runtime/pkg/webhook"
2830
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2931
)
3032

31-
// log is for logging in this package.
32-
var ibmpowervsmachinelog = logf.Log.WithName("ibmpowervsmachine-resource")
33+
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsmachine,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsmachines,verbs=create;update,versions=v1beta2,name=mibmpowervsmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
34+
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsmachine,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsmachines,versions=v1beta2,name=vibmpowervsmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3335

3436
func (r *IBMPowerVSMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
3537
return ctrl.NewWebhookManagedBy(mgr).
36-
For(r).
38+
For(&IBMPowerVSMachine{}).
39+
WithValidator(r).
40+
WithDefaulter(r).
3741
Complete()
3842
}
3943

40-
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsmachine,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsmachines,verbs=create;update,versions=v1beta2,name=mibmpowervsmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
41-
42-
var _ webhook.Defaulter = &IBMPowerVSMachine{}
44+
var _ webhook.CustomDefaulter = &IBMPowerVSMachine{}
45+
var _ webhook.CustomValidator = &IBMPowerVSMachine{}
4346

44-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
45-
func (r *IBMPowerVSMachine) Default() {
46-
ibmpowervsmachinelog.Info("default", "name", r.Name)
47-
defaultIBMPowerVSMachineSpec(&r.Spec)
47+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
48+
func (r *IBMPowerVSMachine) Default(_ context.Context, obj runtime.Object) error {
49+
objValue, ok := obj.(*IBMPowerVSMachine)
50+
if !ok {
51+
return apierrors.NewBadRequest(fmt.Sprintf("expected a IBMPowerVSMachine but got a %T", obj))
52+
}
53+
defaultIBMPowerVSMachineSpec(&objValue.Spec)
54+
return nil
4855
}
4956

50-
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-ibmpowervsmachine,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsmachines,versions=v1beta2,name=vibmpowervsmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
51-
52-
var _ webhook.Validator = &IBMPowerVSMachine{}
53-
54-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
55-
func (r *IBMPowerVSMachine) ValidateCreate() (admission.Warnings, error) {
56-
ibmpowervsmachinelog.Info("validate create", "name", r.Name)
57-
return r.validateIBMPowerVSMachine()
57+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
58+
func (r *IBMPowerVSMachine) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
59+
objValue, ok := obj.(*IBMPowerVSMachine)
60+
if !ok {
61+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a IBMPowerVSMachine but got a %T", obj))
62+
}
63+
return objValue.validateIBMPowerVSMachine()
5864
}
5965

60-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
61-
func (r *IBMPowerVSMachine) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
62-
ibmpowervsmachinelog.Info("validate update", "name", r.Name)
63-
return r.validateIBMPowerVSMachine()
66+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
67+
func (r *IBMPowerVSMachine) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (warnings admission.Warnings, err error) {
68+
newObjValue, ok := newObj.(*IBMPowerVSMachine)
69+
if !ok {
70+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a IBMPowerVSMachine but got a %T", newObj))
71+
}
72+
return newObjValue.validateIBMPowerVSMachine()
6473
}
6574

66-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
67-
func (r *IBMPowerVSMachine) ValidateDelete() (admission.Warnings, error) {
68-
ibmpowervsmachinelog.Info("validate delete", "name", r.Name)
75+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
76+
func (r *IBMPowerVSMachine) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
6977
return nil, nil
7078
}
7179

Diff for: api/v1beta2/ibmpowervsmachine_webhook_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"testing"
2122

2223
. "github.com/onsi/gomega"
2324
corev1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/util/intstr"
2627
"k8s.io/utils/ptr"
27-
"sigs.k8s.io/cluster-api/util/defaulting"
2828
)
2929

3030
func TestIBMPowerVSMachine_default(t *testing.T) {
@@ -42,8 +42,7 @@ func TestIBMPowerVSMachine_default(t *testing.T) {
4242
},
4343
},
4444
}
45-
t.Run("Defaults for IBMPowerVSMachine", defaulting.DefaultValidateTest(powervsMachine))
46-
powervsMachine.Default()
45+
g.Expect(powervsMachine.Default(context.Background(), powervsMachine)).ToNot(HaveOccurred())
4746
g.Expect(powervsMachine.Spec.SystemType).To(BeEquivalentTo("s922"))
4847
g.Expect(powervsMachine.Spec.ProcessorType).To(BeEquivalentTo(PowerVSProcessorTypeShared))
4948
}

0 commit comments

Comments
 (0)