Skip to content

Commit 5cfae1d

Browse files
committed
Bump CAPI to v1.10.0-rc.0
Signed-off-by: Tamal Saha <[email protected]>
1 parent e9f2823 commit 5cfae1d

28 files changed

+980
-582
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ linters-settings:
178178
alias: yamlserializer
179179
- pkg: "sigs.k8s.io/cluster-api/api/v1beta1"
180180
alias: clusterv1
181-
- pkg: "sigs.k8s.io/cluster-api/util/defaulting"
181+
- pkg: "sigs.k8s.io/cluster-api-provider-aws/v2/util/defaulting"
182182
alias: utildefaulting
183183
- pkg: sigs.k8s.io/controller-runtime
184184
alias: ctrl

api/v1beta2/awscluster_webhook.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"net"
2223
"strings"
@@ -42,21 +43,31 @@ const (
4243
var _ = ctrl.Log.WithName("awscluster-resource")
4344

4445
func (r *AWSCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
46+
w := new(awsClusterWebhook)
4547
return ctrl.NewWebhookManagedBy(mgr).
4648
For(r).
49+
WithValidator(w).
50+
WithDefaulter(w).
4751
Complete()
4852
}
4953

5054
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-awscluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,versions=v1beta2,name=validation.awscluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
5155
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-awscluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusters,versions=v1beta2,name=default.awscluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
5256

57+
type awsClusterWebhook struct{}
58+
5359
var (
54-
_ webhook.Validator = &AWSCluster{}
55-
_ webhook.Defaulter = &AWSCluster{}
60+
_ webhook.CustomValidator = &awsClusterWebhook{}
61+
_ webhook.CustomDefaulter = &awsClusterWebhook{}
5662
)
5763

5864
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
59-
func (r *AWSCluster) ValidateCreate() (admission.Warnings, error) {
65+
func (_ *awsClusterWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
66+
r, ok := obj.(*AWSCluster)
67+
if !ok {
68+
return nil, fmt.Errorf("expected an AWSCluster object but got %T", r)
69+
}
70+
6071
var allErrs field.ErrorList
6172
var allWarnings admission.Warnings
6273

@@ -78,20 +89,25 @@ func (r *AWSCluster) ValidateCreate() (admission.Warnings, error) {
7889
}
7990

8091
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
81-
func (r *AWSCluster) ValidateDelete() (admission.Warnings, error) {
92+
func (_ *awsClusterWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
8293
return nil, nil
8394
}
8495

8596
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
86-
func (r *AWSCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
97+
func (_ *awsClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
98+
r, ok := newObj.(*AWSCluster)
99+
if !ok {
100+
return nil, fmt.Errorf("expected an AWSCluster object but got %T", r)
101+
}
102+
87103
var allErrs field.ErrorList
88104
var allWarnings admission.Warnings
89105

90106
allErrs = append(allErrs, r.validateGCTasksAnnotation()...)
91107

92-
oldC, ok := old.(*AWSCluster)
108+
oldC, ok := oldObj.(*AWSCluster)
93109
if !ok {
94-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSCluster but got a %T", old))
110+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSCluster but got a %T", oldObj))
95111
}
96112

97113
if r.Spec.Region != oldC.Spec.Region {
@@ -228,6 +244,16 @@ func (r *AWSCluster) validateControlPlaneLoadBalancerUpdate(oldlb, newlb *AWSLoa
228244
}
229245

230246
// Default satisfies the defaulting webhook interface.
247+
func (_ *awsClusterWebhook) Default(_ context.Context, obj runtime.Object) error {
248+
r, ok := obj.(*AWSCluster)
249+
if !ok {
250+
return fmt.Errorf("expected an AWSCluster object but got %T", r)
251+
}
252+
253+
r.Default()
254+
return nil
255+
}
256+
231257
func (r *AWSCluster) Default() {
232258
SetObjectDefaults_AWSCluster(r)
233259
}

api/v1beta2/awscluster_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
3434
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
35-
"sigs.k8s.io/cluster-api/util/defaulting"
35+
"sigs.k8s.io/cluster-api-provider-aws/v2/util/defaulting"
3636
)
3737

3838
func TestAWSClusterDefault(t *testing.T) {

api/v1beta2/awsclustercontrolleridentity_webhook.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
"github.com/google/go-cmp/cmp"
@@ -34,21 +35,31 @@ import (
3435
var _ = ctrl.Log.WithName("awsclustercontrolleridentity-resource")
3536

3637
func (r *AWSClusterControllerIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error {
38+
w := new(awsClusterControllerIdentityWebhook)
3739
return ctrl.NewWebhookManagedBy(mgr).
3840
For(r).
41+
WithValidator(w).
42+
WithDefaulter(w).
3943
Complete()
4044
}
4145

4246
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-awsclustercontrolleridentity,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclustercontrolleridentities,versions=v1beta2,name=validation.awsclustercontrolleridentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4347
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-awsclustercontrolleridentity,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclustercontrolleridentities,versions=v1beta2,name=default.awsclustercontrolleridentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4448

49+
type awsClusterControllerIdentityWebhook struct{}
50+
4551
var (
46-
_ webhook.Validator = &AWSClusterControllerIdentity{}
47-
_ webhook.Defaulter = &AWSClusterControllerIdentity{}
52+
_ webhook.CustomValidator = &awsClusterControllerIdentityWebhook{}
53+
_ webhook.CustomDefaulter = &awsClusterControllerIdentityWebhook{}
4854
)
4955

5056
// ValidateCreate will do any extra validation when creating an AWSClusterControllerIdentity.
51-
func (r *AWSClusterControllerIdentity) ValidateCreate() (admission.Warnings, error) {
57+
func (_ *awsClusterControllerIdentityWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
58+
r, ok := obj.(*AWSClusterControllerIdentity)
59+
if !ok {
60+
return nil, fmt.Errorf("expected an AWSClusterControllerIdentity object but got %T", r)
61+
}
62+
5263
// Ensures AWSClusterControllerIdentity being singleton by only allowing "default" as name
5364
if r.Name != AWSClusterControllerIdentityName {
5465
return nil, field.Invalid(field.NewPath("name"),
@@ -67,15 +78,20 @@ func (r *AWSClusterControllerIdentity) ValidateCreate() (admission.Warnings, err
6778
}
6879

6980
// ValidateDelete allows you to add any extra validation when deleting an AWSClusterControllerIdentity.
70-
func (r *AWSClusterControllerIdentity) ValidateDelete() (admission.Warnings, error) {
81+
func (_ *awsClusterControllerIdentityWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
7182
return nil, nil
7283
}
7384

7485
// ValidateUpdate will do any extra validation when updating an AWSClusterControllerIdentity.
75-
func (r *AWSClusterControllerIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
76-
oldP, ok := old.(*AWSClusterControllerIdentity)
86+
func (_ *awsClusterControllerIdentityWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
87+
r, ok := newObj.(*AWSClusterControllerIdentity)
88+
if !ok {
89+
return nil, fmt.Errorf("expected an AWSClusterControllerIdentity object but got %T", r)
90+
}
91+
92+
oldP, ok := oldObj.(*AWSClusterControllerIdentity)
7793
if !ok {
78-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterControllerIdentity but got a %T", old))
94+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterControllerIdentity but got a %T", oldObj))
7995
}
8096

8197
if !cmp.Equal(r.Spec, oldP.Spec) {
@@ -99,6 +115,12 @@ func (r *AWSClusterControllerIdentity) ValidateUpdate(old runtime.Object) (admis
99115
}
100116

101117
// Default will set default values for the AWSClusterControllerIdentity.
102-
func (r *AWSClusterControllerIdentity) Default() {
118+
func (_ *awsClusterControllerIdentityWebhook) Default(_ context.Context, obj runtime.Object) error {
119+
r, ok := obj.(*AWSClusterControllerIdentity)
120+
if !ok {
121+
return fmt.Errorf("expected an AWSClusterControllerIdentity object but got %T", r)
122+
}
123+
103124
SetDefaults_Labels(&r.ObjectMeta)
125+
return nil
104126
}

api/v1beta2/awsclusterroleidentity_webhook.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -32,21 +33,31 @@ import (
3233
var _ = ctrl.Log.WithName("awsclusterroleidentity-resource")
3334

3435
func (r *AWSClusterRoleIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error {
36+
w := new(awsClusterRoleIdentityWebhook)
3537
return ctrl.NewWebhookManagedBy(mgr).
3638
For(r).
39+
WithValidator(w).
40+
WithDefaulter(w).
3741
Complete()
3842
}
3943

4044
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-awsclusterroleidentity,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusterroleidentities,versions=v1beta2,name=validation.awsclusterroleidentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4145
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-awsclusterroleidentity,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusterroleidentities,versions=v1beta2,name=default.awsclusterroleidentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4246

47+
type awsClusterRoleIdentityWebhook struct{}
48+
4349
var (
44-
_ webhook.Validator = &AWSClusterRoleIdentity{}
45-
_ webhook.Defaulter = &AWSClusterRoleIdentity{}
50+
_ webhook.CustomValidator = &awsClusterRoleIdentityWebhook{}
51+
_ webhook.CustomDefaulter = &awsClusterRoleIdentityWebhook{}
4652
)
4753

4854
// ValidateCreate will do any extra validation when creating an AWSClusterRoleIdentity.
49-
func (r *AWSClusterRoleIdentity) ValidateCreate() (admission.Warnings, error) {
55+
func (_ *awsClusterRoleIdentityWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
56+
r, ok := obj.(*AWSClusterRoleIdentity)
57+
if !ok {
58+
return nil, fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", r)
59+
}
60+
5061
if r.Spec.SourceIdentityRef == nil {
5162
return nil, field.Invalid(field.NewPath("spec", "sourceIdentityRef"),
5263
r.Spec.SourceIdentityRef, "field cannot be set to nil")
@@ -64,15 +75,20 @@ func (r *AWSClusterRoleIdentity) ValidateCreate() (admission.Warnings, error) {
6475
}
6576

6677
// ValidateDelete allows you to add any extra validation when deleting an AWSClusterRoleIdentity.
67-
func (r *AWSClusterRoleIdentity) ValidateDelete() (admission.Warnings, error) {
78+
func (_ *awsClusterRoleIdentityWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
6879
return nil, nil
6980
}
7081

7182
// ValidateUpdate will do any extra validation when updating an AWSClusterRoleIdentity.
72-
func (r *AWSClusterRoleIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
73-
oldP, ok := old.(*AWSClusterRoleIdentity)
83+
func (_ *awsClusterRoleIdentityWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
84+
r, ok := newObj.(*AWSClusterRoleIdentity)
7485
if !ok {
75-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterRoleIdentity but got a %T", old))
86+
return nil, fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", r)
87+
}
88+
89+
oldP, ok := oldObj.(*AWSClusterRoleIdentity)
90+
if !ok {
91+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterRoleIdentity but got a %T", oldObj))
7692
}
7793

7894
// If a SourceIdentityRef is set, do not allow removal of it.
@@ -93,6 +109,11 @@ func (r *AWSClusterRoleIdentity) ValidateUpdate(old runtime.Object) (admission.W
93109
}
94110

95111
// Default will set default values for the AWSClusterRoleIdentity.
96-
func (r *AWSClusterRoleIdentity) Default() {
112+
func (_ *awsClusterRoleIdentityWebhook) Default(_ context.Context, obj runtime.Object) error {
113+
r, ok := obj.(*AWSClusterRoleIdentity)
114+
if !ok {
115+
return fmt.Errorf("expected an AWSClusterRoleIdentity object but got %T", r)
116+
}
97117
SetDefaults_Labels(&r.ObjectMeta)
118+
return nil
98119
}

api/v1beta2/awsclusterstaticidentity_webhook.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -32,21 +33,31 @@ import (
3233
var _ = ctrl.Log.WithName("awsclusterstaticidentity-resource")
3334

3435
func (r *AWSClusterStaticIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error {
36+
w := new(awsClusterRoleIdentityWebhook)
3537
return ctrl.NewWebhookManagedBy(mgr).
3638
For(r).
39+
WithValidator(w).
40+
WithDefaulter(w).
3741
Complete()
3842
}
3943

4044
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-awsclusterstaticidentity,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusterstaticidentities,versions=v1beta2,name=validation.awsclusterstaticidentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4145
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta2-awsclusterstaticidentity,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=awsclusterstaticidentities,versions=v1beta2,name=default.awsclusterstaticidentity.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
4246

47+
type awsClusterStaticIdentityWebhook struct{}
48+
4349
var (
44-
_ webhook.Validator = &AWSClusterStaticIdentity{}
45-
_ webhook.Defaulter = &AWSClusterStaticIdentity{}
50+
_ webhook.CustomValidator = &awsClusterStaticIdentityWebhook{}
51+
_ webhook.CustomDefaulter = &awsClusterStaticIdentityWebhook{}
4652
)
4753

48-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
49-
func (r *AWSClusterStaticIdentity) ValidateCreate() (admission.Warnings, error) {
54+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
55+
func (_ *awsClusterStaticIdentityWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
56+
r, ok := obj.(*AWSClusterStaticIdentity)
57+
if !ok {
58+
return nil, fmt.Errorf("expected an AWSClusterStaticIdentity object but got %T", r)
59+
}
60+
5061
// Validate selector parses as Selector
5162
if r.Spec.AllowedNamespaces != nil {
5263
_, err := metav1.LabelSelectorAsSelector(&r.Spec.AllowedNamespaces.Selector)
@@ -58,16 +69,21 @@ func (r *AWSClusterStaticIdentity) ValidateCreate() (admission.Warnings, error)
5869
return nil, nil
5970
}
6071

61-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
62-
func (r *AWSClusterStaticIdentity) ValidateDelete() (admission.Warnings, error) {
72+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
73+
func (_ *awsClusterStaticIdentityWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
6374
return nil, nil
6475
}
6576

66-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
67-
func (r *AWSClusterStaticIdentity) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
68-
oldP, ok := old.(*AWSClusterStaticIdentity)
77+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
78+
func (_ *awsClusterStaticIdentityWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
79+
r, ok := newObj.(*AWSClusterStaticIdentity)
6980
if !ok {
70-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterStaticIdentity but got a %T", old))
81+
return nil, fmt.Errorf("expected an AWSClusterStaticIdentity object but got %T", r)
82+
}
83+
84+
oldP, ok := oldObj.(*AWSClusterStaticIdentity)
85+
if !ok {
86+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an AWSClusterStaticIdentity but got a %T", oldObj))
7187
}
7288

7389
if oldP.Spec.SecretRef != r.Spec.SecretRef {
@@ -87,6 +103,11 @@ func (r *AWSClusterStaticIdentity) ValidateUpdate(old runtime.Object) (admission
87103
}
88104

89105
// Default should return the default AWSClusterStaticIdentity.
90-
func (r *AWSClusterStaticIdentity) Default() {
106+
func (_ *awsClusterStaticIdentityWebhook) Default(_ context.Context, obj runtime.Object) error {
107+
r, ok := obj.(*AWSClusterStaticIdentity)
108+
if !ok {
109+
return fmt.Errorf("expected an AWSClusterStaticIdentity object but got %T", r)
110+
}
91111
SetDefaults_Labels(&r.ObjectMeta)
112+
return nil
92113
}

0 commit comments

Comments
 (0)