diff --git a/api/v1beta2/awsclusterroleidentity_webhook.go b/api/v1beta2/awsclusterroleidentity_webhook.go index b63cd75f40..0919391a29 100644 --- a/api/v1beta2/awsclusterroleidentity_webhook.go +++ b/api/v1beta2/awsclusterroleidentity_webhook.go @@ -35,6 +35,8 @@ var _ = ctrl.Log.WithName("awsclusterroleidentity-resource") func (r *AWSClusterRoleIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). + WithDefaulter(r). // registers webhook.CustomDefaulter + WithValidator(r). // registers webhook.CustomValidator Complete() } @@ -48,6 +50,11 @@ var ( // ValidateCreate will do any extra validation when creating an AWSClusterRoleIdentity. func (r *AWSClusterRoleIdentity) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) { + r, ok := obj.(*AWSClusterRoleIdentity) + if !ok { + return nil, fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", r) + } + if r.Spec.SourceIdentityRef == nil { return nil, field.Invalid(field.NewPath("spec", "sourceIdentityRef"), r.Spec.SourceIdentityRef, "field cannot be set to nil") @@ -71,6 +78,11 @@ func (r *AWSClusterRoleIdentity) ValidateDelete(ctx context.Context, obj runtime // ValidateUpdate will do any extra validation when updating an AWSClusterRoleIdentity. func (r *AWSClusterRoleIdentity) ValidateUpdate(ctx context.Context, old runtime.Object, new runtime.Object) (warnings admission.Warnings, err error) { + r, ok := new.(*AWSClusterRoleIdentity) + if !ok { + return nil, fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", new) + } + oldP, ok := old.(*AWSClusterRoleIdentity) if !ok { 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 // Default will set default values for the AWSClusterRoleIdentity. func (r *AWSClusterRoleIdentity) Default(ctx context.Context, obj runtime.Object) error { + r, ok := obj.(*AWSClusterRoleIdentity) + if !ok { + return fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", r) + } SetDefaults_Labels(&r.ObjectMeta) return nil } diff --git a/controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go b/controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go index a84ede257e..12fc8b9ec3 100644 --- a/controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go +++ b/controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go @@ -2,6 +2,7 @@ package v1beta2 import ( "context" + "fmt" "net" "github.com/blang/semver" @@ -18,6 +19,8 @@ import ( func (r *ROSAControlPlane) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(r). + WithDefaulter(r). // registers webhook.CustomDefaulter + WithValidator(r). // registers webhook.CustomValidator Complete() } @@ -29,6 +32,11 @@ var _ webhook.CustomValidator = &ROSAControlPlane{} // ValidateCreate implements admission.Validator. func (r *ROSAControlPlane) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) { + r, ok := obj.(*ROSAControlPlane) + if !ok { + return nil, fmt.Errorf("expected *ROSAControlPlane, got %T", obj) + } + var allErrs field.ErrorList if err := r.validateVersion(); err != nil { @@ -75,6 +83,11 @@ func (r *ROSAControlPlane) validateClusterRegistryConfig() *field.Error { // ValidateUpdate implements admission.Validator. func (r *ROSAControlPlane) ValidateUpdate(ctx context.Context, old runtime.Object, new runtime.Object) (warnings admission.Warnings, err error) { + r, ok := new.(*ROSAControlPlane) + if !ok { + return nil, fmt.Errorf("expected *ROSAControlPlane, got %T", new) + } + var allErrs field.ErrorList if err := r.validateVersion(); err != nil { @@ -165,6 +178,10 @@ func (r *ROSAControlPlane) validateExternalAuthProviders() *field.Error { // Default implements admission.Defaulter. func (r *ROSAControlPlane) Default(ctx context.Context, obj runtime.Object) error { + r, ok := obj.(*ROSAControlPlane) + if !ok { + return fmt.Errorf("expected *ROSAControlPlane, got %T", obj) + } SetObjectDefaults_ROSAControlPlane(r) return nil }