@@ -22,39 +22,48 @@ import (
22
22
"github.com/pkg/errors"
23
23
"k8s.io/apimachinery/pkg/runtime"
24
24
ctrl "sigs.k8s.io/controller-runtime"
25
+ "sigs.k8s.io/controller-runtime/pkg/webhook"
25
26
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
26
27
)
27
28
28
29
// SetupWebhookWithManager sets up and registers the webhook with the manager.
29
30
func (ampm * AzureMachinePoolMachine ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
31
+ w := new (azureMachinePoolMachineWebhook )
30
32
return ctrl .NewWebhookManagedBy (mgr ).
31
33
For (ampm ).
32
- WithValidator (& AzureMachinePoolMachine {} ).
34
+ WithValidator (w ).
33
35
Complete ()
34
36
}
35
37
36
38
// +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
37
39
40
+ type azureMachinePoolMachineWebhook struct {}
41
+
42
+ var (
43
+ _ webhook.CustomValidator = & azureMachinePoolMachineWebhook {}
44
+ )
45
+
38
46
// 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 ) {
40
48
return nil , nil
41
49
}
42
50
43
51
// 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 )
46
55
if ! ok {
47
56
return nil , errors .New ("expected and AzureMachinePoolMachine" )
48
57
}
49
58
50
- if oldMachine .Spec .ProviderID != "" && ampm .Spec .ProviderID != oldMachine .Spec .ProviderID {
59
+ if oldMachine .Spec .ProviderID != "" && newMachine .Spec .ProviderID != oldMachine .Spec .ProviderID {
51
60
return nil , errors .New ("providerID is immutable" )
52
61
}
53
62
54
63
return nil , nil
55
64
}
56
65
57
66
// 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 ) {
59
68
return nil , nil
60
69
}
0 commit comments