Skip to content

Commit 427f450

Browse files
authored
Bump CAPI to v1.10.2 (#5447)
Signed-off-by: Tamal Saha <[email protected]>
1 parent a65a2f6 commit 427f450

File tree

84 files changed

+1716
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1716
-1056
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include $(ROOT_DIR_RELATIVE)/common.mk
2020
# https://suva.sh/posts/well-documented-makefiles
2121

2222
# Go
23-
GO_VERSION ?=1.23.7
23+
GO_VERSION ?=1.23.9
2424
GO_CONTAINER_IMAGE ?= golang:$(GO_VERSION)
2525

2626
# Directories.
@@ -151,8 +151,8 @@ E2E_SKIP_EKS_UPGRADE ?= "false"
151151
EKS_SOURCE_TEMPLATE ?= eks/cluster-template-eks-control-plane-only.yaml
152152

153153
# set up `setup-envtest` to install kubebuilder dependency
154-
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.31.0
155-
SETUP_ENVTEST_VER := release-0.19
154+
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.32.0
155+
SETUP_ENVTEST_VER := release-0.20
156156
SETUP_ENVTEST_BIN := setup-envtest
157157
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
158158
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest

api/v1beta1/zz_generated.conversion.go

Lines changed: 98 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_webhook.go

Lines changed: 34 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 {
@@ -227,6 +243,17 @@ func (r *AWSCluster) validateControlPlaneLoadBalancerUpdate(oldlb, newlb *AWSLoa
227243
return allErrs
228244
}
229245

246+
// 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+
230257
// Default satisfies the defaulting webhook interface.
231258
func (r *AWSCluster) Default() {
232259
SetObjectDefaults_AWSCluster(r)

api/v1beta2/awscluster_webhook_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ import (
2626
"github.com/aws/aws-sdk-go/aws"
2727
. "github.com/onsi/gomega"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/runtime"
2930
utilfeature "k8s.io/component-base/featuregate/testing"
3031
"k8s.io/utils/ptr"
3132
"sigs.k8s.io/controller-runtime/pkg/client"
3233

3334
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
35+
"sigs.k8s.io/cluster-api-provider-aws/v2/util/defaulting"
3436
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
35-
"sigs.k8s.io/cluster-api/util/defaulting"
3637
)
3738

3839
func TestAWSClusterDefault(t *testing.T) {
3940
cluster := &AWSCluster{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
40-
t.Run("for AWSCluster", defaultValidateTest(cluster, true))
41+
t.Run("for AWSCluster", defaultValidateTest(context.Background(), cluster, &awsClusterWebhook{}, true))
4142
cluster.Default()
4243
g := NewWithT(t)
4344
g.Expect(cluster.Spec.IdentityRef).NotTo(BeNil())
@@ -1494,38 +1495,38 @@ func TestAWSClusterDefaultAllowedCIDRBlocks(t *testing.T) {
14941495
// update and delete.
14951496
// NOTE: This is a copy of the DefaultValidateTest function in the cluster-api
14961497
// package, but it has been modified to allow warnings to be returned.
1497-
func defaultValidateTest(object defaulting.DefaultingValidator, allowWarnings bool) func(*testing.T) {
1498+
func defaultValidateTest(ctx context.Context, object runtime.Object, webhook defaulting.DefaulterValidator, allowWarnings bool) func(*testing.T) {
14981499
return func(t *testing.T) {
14991500
t.Helper()
15001501

1501-
createCopy := object.DeepCopyObject().(defaulting.DefaultingValidator)
1502-
updateCopy := object.DeepCopyObject().(defaulting.DefaultingValidator)
1503-
deleteCopy := object.DeepCopyObject().(defaulting.DefaultingValidator)
1504-
defaultingUpdateCopy := updateCopy.DeepCopyObject().(defaulting.DefaultingValidator)
1502+
createCopy := object.DeepCopyObject()
1503+
updateCopy := object.DeepCopyObject()
1504+
deleteCopy := object.DeepCopyObject()
1505+
defaultingUpdateCopy := updateCopy.DeepCopyObject()
15051506

15061507
t.Run("validate-on-create", func(t *testing.T) {
15071508
g := NewWithT(t)
1508-
createCopy.Default()
1509-
warnings, err := createCopy.ValidateCreate()
1509+
g.Expect(webhook.Default(ctx, createCopy)).To(Succeed())
1510+
warnings, err := webhook.ValidateCreate(ctx, createCopy)
15101511
g.Expect(err).ToNot(HaveOccurred())
15111512
if !allowWarnings {
15121513
g.Expect(warnings).To(BeEmpty())
15131514
}
15141515
})
15151516
t.Run("validate-on-update", func(t *testing.T) {
15161517
g := NewWithT(t)
1517-
defaultingUpdateCopy.Default()
1518-
updateCopy.Default()
1519-
warnings, err := defaultingUpdateCopy.ValidateUpdate(updateCopy)
1518+
g.Expect(webhook.Default(ctx, defaultingUpdateCopy)).To(Succeed())
1519+
g.Expect(webhook.Default(ctx, updateCopy)).To(Succeed())
1520+
warnings, err := webhook.ValidateUpdate(ctx, updateCopy, defaultingUpdateCopy)
15201521
g.Expect(err).ToNot(HaveOccurred())
15211522
if !allowWarnings {
15221523
g.Expect(warnings).To(BeEmpty())
15231524
}
15241525
})
15251526
t.Run("validate-on-delete", func(t *testing.T) {
15261527
g := NewWithT(t)
1527-
deleteCopy.Default()
1528-
warnings, err := deleteCopy.ValidateDelete()
1528+
g.Expect(webhook.Default(ctx, deleteCopy)).To(Succeed())
1529+
warnings, err := webhook.ValidateDelete(ctx, deleteCopy)
15291530
g.Expect(err).ToNot(HaveOccurred())
15301531
if !allowWarnings {
15311532
g.Expect(warnings).To(BeEmpty())

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
}

0 commit comments

Comments
 (0)