Skip to content

Commit 9722c3a

Browse files
committed
fix AzureMachinePoolMachine webhooks
1 parent 2744344 commit 9722c3a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

exp/api/v1beta1/azuremachinepoolmachine_webhook.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,48 @@ import (
2222
"github.com/pkg/errors"
2323
"k8s.io/apimachinery/pkg/runtime"
2424
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/webhook"
2526
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2627
)
2728

2829
// SetupWebhookWithManager sets up and registers the webhook with the manager.
2930
func (ampm *AzureMachinePoolMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
31+
w := new(azureMachinePoolMachineWebhook)
3032
return ctrl.NewWebhookManagedBy(mgr).
3133
For(ampm).
32-
WithValidator(&AzureMachinePoolMachine{}).
34+
WithValidator(w).
3335
Complete()
3436
}
3537

3638
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremachinepoolmachine,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=azuremachinepoolmachines,versions=v1beta1,name=azuremachinepoolmachine.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
3739

40+
type azureMachinePoolMachineWebhook struct{}
41+
42+
var (
43+
_ webhook.CustomValidator = &azureMachinePoolMachineWebhook{}
44+
)
45+
3846
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
39-
func (ampm *AzureMachinePoolMachine) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
47+
func (_ *azureMachinePoolMachineWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
4048
return nil, nil
4149
}
4250

4351
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
44-
func (ampm *AzureMachinePoolMachine) ValidateUpdate(_ context.Context, _ runtime.Object, old runtime.Object) (admission.Warnings, error) {
45-
oldMachine, ok := old.(*AzureMachinePoolMachine)
52+
func (_ *azureMachinePoolMachineWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
53+
oldMachine, ok := oldObj.(*AzureMachinePoolMachine)
54+
newMachine, ok := newObj.(*AzureMachinePoolMachine)
4655
if !ok {
4756
return nil, errors.New("expected and AzureMachinePoolMachine")
4857
}
4958

50-
if oldMachine.Spec.ProviderID != "" && ampm.Spec.ProviderID != oldMachine.Spec.ProviderID {
59+
if oldMachine.Spec.ProviderID != "" && newMachine.Spec.ProviderID != oldMachine.Spec.ProviderID {
5160
return nil, errors.New("providerID is immutable")
5261
}
5362

5463
return nil, nil
5564
}
5665

5766
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
58-
func (ampm *AzureMachinePoolMachine) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
67+
func (_ *azureMachinePoolMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5968
return nil, nil
6069
}

0 commit comments

Comments
 (0)