@@ -23,43 +23,53 @@ import (
2323 "k8s.io/apimachinery/pkg/runtime"
2424 "k8s.io/apimachinery/pkg/util/validation/field"
2525 ctrl "sigs.k8s.io/controller-runtime"
26+ "sigs.k8s.io/controller-runtime/pkg/webhook"
2627 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2728
2829 webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook"
2930)
3031
3132// SetupWebhookWithManager sets up and registers the webhook with the manager.
3233func (c * AzureClusterIdentity ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
34+ w := new (azureClusterIdentityWebhook )
3335 return ctrl .NewWebhookManagedBy (mgr ).
3436 For (c ).
35- WithValidator (& AzureClusterIdentity {} ).
37+ WithValidator (w ).
3638 Complete ()
3739}
3840
3941// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-azureclusteridentity,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=azureclusteridentities,versions=v1beta1,name=validation.azureclusteridentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4042
43+ type azureClusterIdentityWebhook struct {}
44+
45+ var (
46+ _ webhook.CustomValidator = & azureClusterIdentityWebhook {}
47+ )
48+
4149// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
42- func (c * AzureClusterIdentity ) ValidateCreate (_ context.Context , _ runtime.Object ) (admission.Warnings , error ) {
50+ func (_ * azureClusterIdentityWebhook ) ValidateCreate (_ context.Context , newObj runtime.Object ) (admission.Warnings , error ) {
51+ c := newObj .(* AzureClusterIdentity )
4352 return c .validateClusterIdentity ()
4453}
4554
4655// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
47- func (c * AzureClusterIdentity ) ValidateUpdate (_ context.Context , _ runtime. Object , oldRaw runtime.Object ) (admission.Warnings , error ) {
56+ func (_ * azureClusterIdentityWebhook ) ValidateUpdate (_ context.Context , oldObj , newObj runtime.Object ) (admission.Warnings , error ) {
4857 var allErrs field.ErrorList
49- old := oldRaw .(* AzureClusterIdentity )
58+ oldAzureClusterIdentity := oldObj .(* AzureClusterIdentity )
59+ newAzureClusterIdentity := newObj .(* AzureClusterIdentity )
5060 if err := webhookutils .ValidateImmutable (
5161 field .NewPath ("Spec" , "Type" ),
52- old .Spec .Type ,
53- c .Spec .Type ); err != nil {
62+ oldAzureClusterIdentity .Spec .Type ,
63+ newAzureClusterIdentity .Spec .Type ); err != nil {
5464 allErrs = append (allErrs , err )
5565 }
5666 if len (allErrs ) == 0 {
57- return c .validateClusterIdentity ()
67+ return newAzureClusterIdentity .validateClusterIdentity ()
5868 }
59- return nil , apierrors .NewInvalid (GroupVersion .WithKind (AzureClusterIdentityKind ).GroupKind (), c .Name , allErrs )
69+ return nil , apierrors .NewInvalid (GroupVersion .WithKind (AzureClusterIdentityKind ).GroupKind (), newAzureClusterIdentity .Name , allErrs )
6070}
6171
6272// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
63- func (c * AzureClusterIdentity ) ValidateDelete (_ context.Context , _ runtime.Object ) (admission.Warnings , error ) {
73+ func (_ * azureClusterIdentityWebhook ) ValidateDelete (_ context.Context , _ runtime.Object ) (admission.Warnings , error ) {
6474 return nil , nil
6575}
0 commit comments