Skip to content

Commit 84f08a3

Browse files
authored
PCP-5293 Adding missing controller-runtime change to webhook (#986)
1 parent 053b94e commit 84f08a3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

api/v1beta2/awsclusterroleidentity_webhook.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var _ = ctrl.Log.WithName("awsclusterroleidentity-resource")
3535
func (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

@@ -48,6 +50,11 @@ var (
4850

4951
// ValidateCreate will do any extra validation when creating an AWSClusterRoleIdentity.
5052
func (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.
7380
func (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.
97109
func (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
}

controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1beta2
22

33
import (
44
"context"
5+
"fmt"
56
"net"
67

78
"github.com/blang/semver"
@@ -18,6 +19,8 @@ import (
1819
func (r *ROSAControlPlane) SetupWebhookWithManager(mgr ctrl.Manager) error {
1920
return ctrl.NewWebhookManagedBy(mgr).
2021
For(r).
22+
WithDefaulter(r). // registers webhook.CustomDefaulter
23+
WithValidator(r). // registers webhook.CustomValidator
2124
Complete()
2225
}
2326

@@ -29,6 +32,11 @@ var _ webhook.CustomValidator = &ROSAControlPlane{}
2932

3033
// ValidateCreate implements admission.Validator.
3134
func (r *ROSAControlPlane) ValidateCreate(ctx context.Context, obj runtime.Object) (warnings admission.Warnings, err error) {
35+
r, ok := obj.(*ROSAControlPlane)
36+
if !ok {
37+
return nil, fmt.Errorf("expected *ROSAControlPlane, got %T", obj)
38+
}
39+
3240
var allErrs field.ErrorList
3341

3442
if err := r.validateVersion(); err != nil {
@@ -75,6 +83,11 @@ func (r *ROSAControlPlane) validateClusterRegistryConfig() *field.Error {
7583

7684
// ValidateUpdate implements admission.Validator.
7785
func (r *ROSAControlPlane) ValidateUpdate(ctx context.Context, old runtime.Object, new runtime.Object) (warnings admission.Warnings, err error) {
86+
r, ok := new.(*ROSAControlPlane)
87+
if !ok {
88+
return nil, fmt.Errorf("expected *ROSAControlPlane, got %T", new)
89+
}
90+
7891
var allErrs field.ErrorList
7992

8093
if err := r.validateVersion(); err != nil {
@@ -165,6 +178,10 @@ func (r *ROSAControlPlane) validateExternalAuthProviders() *field.Error {
165178

166179
// Default implements admission.Defaulter.
167180
func (r *ROSAControlPlane) Default(ctx context.Context, obj runtime.Object) error {
181+
r, ok := obj.(*ROSAControlPlane)
182+
if !ok {
183+
return fmt.Errorf("expected *ROSAControlPlane, got %T", obj)
184+
}
168185
SetObjectDefaults_ROSAControlPlane(r)
169186
return nil
170187
}

0 commit comments

Comments
 (0)