@@ -35,6 +35,8 @@ var _ = ctrl.Log.WithName("awsclusterroleidentity-resource")
3535func (r * AWSClusterRoleIdentity ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
3636 return ctrl .NewWebhookManagedBy (mgr ).
3737 For (r ).
38+ WithDefaulter (r ). // registers webhook.CustomDefaulter
39+ WithValidator (r ). // registers webhook.CustomValidator
3840 Complete ()
3941}
4042
4850
4951// ValidateCreate will do any extra validation when creating an AWSClusterRoleIdentity.
5052func (r * AWSClusterRoleIdentity ) ValidateCreate (ctx context.Context , obj runtime.Object ) (warnings admission.Warnings , err error ) {
53+ r , ok := obj .(* AWSClusterRoleIdentity )
54+ if ! ok {
55+ return nil , fmt .Errorf ("expected an AWSClusterRoleIdentity object but got %T" , r )
56+ }
57+
5158 if r .Spec .SourceIdentityRef == nil {
5259 return nil , field .Invalid (field .NewPath ("spec" , "sourceIdentityRef" ),
5360 r .Spec .SourceIdentityRef , "field cannot be set to nil" )
@@ -71,6 +78,11 @@ func (r *AWSClusterRoleIdentity) ValidateDelete(ctx context.Context, obj runtime
7178
7279// ValidateUpdate will do any extra validation when updating an AWSClusterRoleIdentity.
7380func (r * AWSClusterRoleIdentity ) ValidateUpdate (ctx context.Context , old runtime.Object , new runtime.Object ) (warnings admission.Warnings , err error ) {
81+ r , ok := new .(* AWSClusterRoleIdentity )
82+ if ! ok {
83+ return nil , fmt .Errorf ("expected an AWSClusterRoleIdentity object but got %T" , new )
84+ }
85+
7486 oldP , ok := old .(* AWSClusterRoleIdentity )
7587 if ! ok {
7688 return nil , apierrors .NewBadRequest (fmt .Sprintf ("expected an AWSClusterRoleIdentity but got a %T" , old ))
@@ -95,6 +107,10 @@ func (r *AWSClusterRoleIdentity) ValidateUpdate(ctx context.Context, old runtime
95107
96108// Default will set default values for the AWSClusterRoleIdentity.
97109func (r * AWSClusterRoleIdentity ) Default (ctx context.Context , obj runtime.Object ) error {
110+ r , ok := obj .(* AWSClusterRoleIdentity )
111+ if ! ok {
112+ return fmt .Errorf ("expected an AWSClusterRoleIdentity object but got %T" , r )
113+ }
98114 SetDefaults_Labels (& r .ObjectMeta )
99115 return nil
100116}
0 commit comments