@@ -40,35 +40,38 @@ const (
4040
4141// SetupWebhookWithManager sets up and registers the webhook with the manager. 
4242func  (r  * AzureMachineTemplate ) SetupWebhookWithManager (mgr  ctrl.Manager ) error  {
43+ 	w  :=  new (azureMachineTemplateWebhook )
4344	return  ctrl .NewWebhookManagedBy (mgr ).
4445		For (r ).
45- 		WithValidator (r ).
46- 		WithDefaulter (r ).
46+ 		WithValidator (w ).
47+ 		WithDefaulter (w ).
4748		Complete ()
4849}
4950
5051// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-azuremachinetemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azuremachinetemplates,versions=v1beta1,name=default.azuremachinetemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 
5152// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azuremachinetemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azuremachinetemplates,versions=v1beta1,name=validation.azuremachinetemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1 
5253
53- var  _  webhook.CustomDefaulter  =  & AzureMachineTemplate {}
54- var  _  webhook.CustomValidator  =  & AzureMachineTemplate {}
54+ type  azureMachineTemplateWebhook  struct {}
55+ 
56+ var  _  webhook.CustomDefaulter  =  & azureMachineTemplateWebhook {}
57+ var  _  webhook.CustomValidator  =  & azureMachineTemplateWebhook {}
5558
5659// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type. 
57- func  (r   * AzureMachineTemplate ) ValidateCreate (_  context.Context , obj  runtime.Object ) (admission.Warnings , error ) {
58- 	t  :=  obj .(* AzureMachineTemplate )
59- 	spec  :=  t .Spec .Template .Spec 
60+ func  (_   * azureMachineTemplateWebhook ) ValidateCreate (_  context.Context , obj  runtime.Object ) (admission.Warnings , error ) {
61+ 	r  :=  obj .(* AzureMachineTemplate )
62+ 	spec  :=  r .Spec .Template .Spec 
6063
6164	allErrs  :=  ValidateAzureMachineSpec (spec )
6265
6366	if  spec .RoleAssignmentName  !=  ""  {
6467		allErrs  =  append (allErrs ,
65- 			field .Invalid (field .NewPath ("AzureMachineTemplate" , "spec" , "template" , "spec" , "roleAssignmentName" ), t , AzureMachineTemplateRoleAssignmentNameMsg ),
68+ 			field .Invalid (field .NewPath ("AzureMachineTemplate" , "spec" , "template" , "spec" , "roleAssignmentName" ), r , AzureMachineTemplateRoleAssignmentNameMsg ),
6669		)
6770	}
6871
6972	if  spec .SystemAssignedIdentityRole  !=  nil  &&  spec .SystemAssignedIdentityRole .Name  !=  ""  {
7073		allErrs  =  append (allErrs ,
71- 			field .Invalid (field .NewPath ("AzureMachineTemplate" , "spec" , "template" , "spec" , "systemAssignedIdentityRole" , "name" ), t , AzureMachineTemplateSystemAssignedIdentityRoleNameMsg ),
74+ 			field .Invalid (field .NewPath ("AzureMachineTemplate" , "spec" , "template" , "spec" , "systemAssignedIdentityRole" , "name" ), r , AzureMachineTemplateSystemAssignedIdentityRoleNameMsg ),
7275		)
7376	}
7477
@@ -94,11 +97,11 @@ func (r *AzureMachineTemplate) ValidateCreate(_ context.Context, obj runtime.Obj
9497		return  nil , nil 
9598	}
9699
97- 	return  nil , apierrors .NewInvalid (GroupVersion .WithKind (AzureMachineTemplateKind ).GroupKind (), t .Name , allErrs )
100+ 	return  nil , apierrors .NewInvalid (GroupVersion .WithKind (AzureMachineTemplateKind ).GroupKind (), r .Name , allErrs )
98101}
99102
100103// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. 
101- func  (r  * AzureMachineTemplate ) ValidateUpdate (ctx  context.Context , oldRaw  runtime.Object , newRaw  runtime.Object ) (admission.Warnings , error ) {
104+ func  (r  * azureMachineTemplateWebhook ) ValidateUpdate (ctx  context.Context , oldRaw  runtime.Object , newRaw  runtime.Object ) (admission.Warnings , error ) {
102105	var  allErrs  field.ErrorList 
103106	old  :=  oldRaw .(* AzureMachineTemplate )
104107	t  :=  newRaw .(* AzureMachineTemplate )
@@ -123,7 +126,7 @@ func (r *AzureMachineTemplate) ValidateUpdate(ctx context.Context, oldRaw runtim
123126
124127		if  err  :=  r .Default (ctx , old ); err  !=  nil  {
125128			allErrs  =  append (allErrs ,
126- 				field .Invalid (field .NewPath ("AzureMachineTemplate" ), r , fmt .Sprintf ("Unable to apply defaults: %v" , err )),
129+ 				field .Invalid (field .NewPath ("AzureMachineTemplate" ), t , fmt .Sprintf ("Unable to apply defaults: %v" , err )),
127130			)
128131		}
129132
@@ -142,12 +145,12 @@ func (r *AzureMachineTemplate) ValidateUpdate(ctx context.Context, oldRaw runtim
142145}
143146
144147// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. 
145- func  (r   * AzureMachineTemplate ) ValidateDelete (_  context.Context , _  runtime.Object ) (admission.Warnings , error ) {
148+ func  (_   * azureMachineTemplateWebhook ) ValidateDelete (_  context.Context , _  runtime.Object ) (admission.Warnings , error ) {
146149	return  nil , nil 
147150}
148151
149152// Default implements webhookutil.defaulter so a webhook will be registered for the type. 
150- func  (r   * AzureMachineTemplate ) Default (_  context.Context , obj  runtime.Object ) error  {
153+ func  (_   * azureMachineTemplateWebhook ) Default (_  context.Context , obj  runtime.Object ) error  {
151154	t  :=  obj .(* AzureMachineTemplate )
152155	if  err  :=  t .Spec .Template .Spec .SetDefaultSSHPublicKey (); err  !=  nil  {
153156		ctrl .Log .WithName ("SetDefault" ).Error (err , "SetDefaultSSHPublicKey failed" )
0 commit comments