Skip to content

Commit 7aa05f2

Browse files
authored
Merge pull request #1459 from kluster-api/k132
Bump CAPI to v1.10.2
2 parents a566ae6 + df341e6 commit 7aa05f2

34 files changed

+594
-459
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export GOPROXY
3333
export GO111MODULE=on
3434

3535
# Go version
36-
GOLANG_VERSION := 1.22.11
36+
GOLANG_VERSION := 1.23.9
3737

3838
# Kubebuilder
39-
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.31.0
39+
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.32.0
4040
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?=60s
4141
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?=60s
4242

@@ -62,11 +62,11 @@ CONVERSION_VERIFIER:= $(TOOLS_BIN_DIR)/conversion-verifier
6262
# Binaries.
6363
CLUSTERCTL := $(BIN_DIR)/clusterctl
6464

65-
CONTROLLER_GEN_VER := v0.17.1
65+
CONTROLLER_GEN_VER := v0.17.3
6666
CONTROLLER_GEN_BIN := controller-gen
6767
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
6868

69-
CONVERSION_GEN_VER := v0.31.5
69+
CONVERSION_GEN_VER := v0.32.0
7070
CONVERSION_GEN_BIN := conversion-gen
7171
CONVERSION_GEN := $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)-$(CONVERSION_GEN_VER)
7272

@@ -78,7 +78,7 @@ GOLANGCI_LINT_VER := v1.63.4
7878
GOLANGCI_LINT_BIN := golangci-lint
7979
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
8080

81-
KIND_VER := v0.26.0
81+
KIND_VER := v0.27.0
8282
KIND_BIN := kind
8383
KIND := $(TOOLS_BIN_DIR)/$(KIND_BIN)-$(KIND_VER)
8484

api/v1beta1/gcpcluster_webhook.go

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

1919
import (
20+
"context"
21+
"fmt"
2022
"reflect"
2123

2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -33,36 +35,44 @@ var clusterlog = logf.Log.WithName("gcpcluster-resource")
3335

3436
// SetupWebhookWithManager sets up and registers the webhook with the manager.
3537
func (c *GCPCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
38+
w := new(gcpClusterWebhook)
3639
return ctrl.NewWebhookManagedBy(mgr).
3740
For(c).
41+
WithValidator(w).
42+
WithDefaulter(w).
3843
Complete()
3944
}
4045

4146
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=validation.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4247
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=default.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4348

49+
type gcpClusterWebhook struct{}
50+
4451
var (
45-
_ webhook.Validator = &GCPCluster{}
46-
_ webhook.Defaulter = &GCPCluster{}
52+
_ webhook.CustomValidator = &gcpClusterWebhook{}
53+
_ webhook.CustomDefaulter = &gcpClusterWebhook{}
4754
)
4855

49-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
50-
func (c *GCPCluster) Default() {
51-
clusterlog.Info("default", "name", c.Name)
56+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
57+
func (*gcpClusterWebhook) Default(_ context.Context, _ runtime.Object) error {
58+
return nil
5259
}
5360

54-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
55-
func (c *GCPCluster) ValidateCreate() (admission.Warnings, error) {
56-
clusterlog.Info("validate create", "name", c.Name)
57-
61+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
62+
func (*gcpClusterWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5863
return nil, nil
5964
}
6065

61-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
62-
func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
66+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
67+
func (*gcpClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
68+
c, ok := newObj.(*GCPCluster)
69+
if !ok {
70+
return nil, fmt.Errorf("expected an GCPCluster object but got %T", c)
71+
}
72+
6373
clusterlog.Info("validate update", "name", c.Name)
6474
var allErrs field.ErrorList
65-
old := oldRaw.(*GCPCluster)
75+
old := oldObj.(*GCPCluster)
6676

6777
if !reflect.DeepEqual(c.Spec.Project, old.Spec.Project) {
6878
allErrs = append(allErrs,
@@ -113,9 +123,7 @@ func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings,
113123
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPCluster").GroupKind(), c.Name, allErrs)
114124
}
115125

116-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
117-
func (c *GCPCluster) ValidateDelete() (admission.Warnings, error) {
118-
clusterlog.Info("validate delete", "name", c.Name)
119-
126+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
127+
func (*gcpClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
120128
return nil, nil
121129
}

api/v1beta1/gcpcluster_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

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

2223
. "github.com/onsi/gomega"
@@ -89,7 +90,7 @@ func TestGCPCluster_ValidateUpdate(t *testing.T) {
8990
for _, test := range tests {
9091
t.Run(test.name, func(t *testing.T) {
9192
t.Parallel()
92-
warn, err := test.newCluster.ValidateUpdate(test.oldCluster)
93+
warn, err := (&gcpClusterWebhook{}).ValidateUpdate(context.Background(), test.oldCluster, test.newCluster)
9394
if test.wantErr {
9495
g.Expect(err).To(HaveOccurred())
9596
} else {

api/v1beta1/gcpclustertemplate_webhook.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,56 @@ limitations under the License.
1717
package v1beta1
1818

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

2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/runtime"
2526
ctrl "sigs.k8s.io/controller-runtime"
26-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2727
"sigs.k8s.io/controller-runtime/pkg/webhook"
2828
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2929
)
3030

31-
// log is for logging in this package.
32-
var gcpclustertemplatelog = logf.Log.WithName("gcpclustertemplate-resource")
33-
3431
func (r *GCPClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
32+
w := new(gcpClusterTemplateWebhook)
3533
return ctrl.NewWebhookManagedBy(mgr).
3634
For(r).
35+
WithValidator(w).
36+
WithDefaulter(w).
3737
Complete()
3838
}
3939

4040
//+kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpclustertemplate,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclustertemplates,versions=v1beta1,name=default.gcpclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4141
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpclustertemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclustertemplates,versions=v1beta1,name=validation.gcpclustertemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4242

43-
var _ webhook.Defaulter = &GCPClusterTemplate{}
44-
45-
// Default implements webhook.Defaulter so a webhook will be registered for the type.
46-
func (r *GCPClusterTemplate) Default() {
47-
gcpclustertemplatelog.Info("default", "name", r.Name)
48-
}
43+
type gcpClusterTemplateWebhook struct{}
4944

50-
var _ webhook.Validator = &GCPClusterTemplate{}
45+
var (
46+
_ webhook.CustomDefaulter = &gcpClusterTemplateWebhook{}
47+
_ webhook.CustomValidator = &gcpClusterTemplateWebhook{}
48+
)
5149

52-
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
53-
func (r *GCPClusterTemplate) ValidateCreate() (admission.Warnings, error) {
54-
gcpclustertemplatelog.Info("validate create", "name", r.Name)
50+
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
51+
func (*gcpClusterTemplateWebhook) Default(_ context.Context, _ runtime.Object) error {
52+
return nil
53+
}
5554

55+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
56+
func (*gcpClusterTemplateWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
5657
return nil, nil
5758
}
5859

59-
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
60-
func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
61-
old, ok := oldRaw.(*GCPClusterTemplate)
60+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
61+
func (*gcpClusterTemplateWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
62+
r, ok := newObj.(*GCPClusterTemplate)
63+
if !ok {
64+
return nil, fmt.Errorf("expected an GCPClusterTemplate object but got %T", r)
65+
}
66+
67+
old, ok := oldObj.(*GCPClusterTemplate)
6268
if !ok {
63-
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldRaw))
69+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldObj))
6470
}
6571

6672
if !reflect.DeepEqual(r.Spec, old.Spec) {
@@ -69,8 +75,7 @@ func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Wa
6975
return nil, nil
7076
}
7177

72-
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
73-
func (r *GCPClusterTemplate) ValidateDelete() (admission.Warnings, error) {
74-
gcpclustertemplatelog.Info("validate delete", "name", r.Name)
78+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
79+
func (*gcpClusterTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
7580
return nil, nil
7681
}

api/v1beta1/gcpclustertemplate_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

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

2223
. "github.com/onsi/gomega"
@@ -83,7 +84,7 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
8384
for _, test := range tests {
8485
t.Run(test.name, func(t *testing.T) {
8586
t.Parallel()
86-
warn, err := test.newTemplate.ValidateUpdate(test.oldTemplate)
87+
warn, err := (&gcpClusterTemplateWebhook{}).ValidateUpdate(context.Background(), test.oldTemplate, test.newTemplate)
8788
if test.wantErr {
8889
g.Expect(err).To(HaveOccurred())
8990
} else {

api/v1beta1/gcpmachine_webhook.go

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

1919
import (
20+
"context"
2021
"fmt"
2122
"reflect"
2223
"strings"
@@ -37,18 +38,31 @@ import (
3738
var _ = logf.Log.WithName("gcpmachine-resource")
3839

3940
func (m *GCPMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
41+
w := new(gcpMachineWebhook)
4042
return ctrl.NewWebhookManagedBy(mgr).
4143
For(m).
44+
WithValidator(w).
45+
WithDefaulter(w).
4246
Complete()
4347
}
4448

4549
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmachine,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpmachines,versions=v1beta1,name=validation.gcpmachine.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4650
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpmachine,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpmachines,versions=v1beta1,name=default.gcpmachine.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4751

48-
var _ webhook.Validator = &GCPMachine{}
52+
type gcpMachineWebhook struct{}
53+
54+
var (
55+
_ webhook.CustomValidator = &gcpMachineWebhook{}
56+
_ webhook.CustomDefaulter = &gcpMachineWebhook{}
57+
)
4958

5059
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
51-
func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
60+
func (*gcpMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
61+
m, ok := obj.(*GCPMachine)
62+
if !ok {
63+
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
64+
}
65+
5266
clusterlog.Info("validate create", "name", m.Name)
5367

5468
if err := validateConfidentialCompute(m.Spec); err != nil {
@@ -58,14 +72,19 @@ func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
5872
}
5973

6074
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
61-
func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
75+
func (*gcpMachineWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
76+
m, ok := newObj.(*GCPMachine)
77+
if !ok {
78+
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
79+
}
80+
6281
newGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
6382
if err != nil {
6483
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
6584
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachine to unstructured object")),
6685
})
6786
}
68-
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
87+
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(oldObj)
6988
if err != nil {
7089
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
7190
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachine to unstructured object")),
@@ -97,15 +116,13 @@ func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
97116
}
98117

99118
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
100-
func (m *GCPMachine) ValidateDelete() (admission.Warnings, error) {
101-
clusterlog.Info("validate delete", "name", m.Name)
102-
119+
func (*gcpMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
103120
return nil, nil
104121
}
105122

106123
// Default implements webhookutil.defaulter so a webhook will be registered for the type.
107-
func (m *GCPMachine) Default() {
108-
clusterlog.Info("default", "name", m.Name)
124+
func (*gcpMachineWebhook) Default(_ context.Context, _ runtime.Object) error {
125+
return nil
109126
}
110127

111128
func validateConfidentialCompute(spec GCPMachineSpec) error {

api/v1beta1/gcpmachine_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

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

2223
. "github.com/onsi/gomega"
@@ -272,7 +273,7 @@ func TestGCPMachine_ValidateCreate(t *testing.T) {
272273
for _, test := range tests {
273274
t.Run(test.name, func(t *testing.T) {
274275
t.Parallel()
275-
warn, err := test.GCPMachine.ValidateCreate()
276+
warn, err := (&gcpMachineWebhook{}).ValidateCreate(context.Background(), test.GCPMachine)
276277
if test.wantErr {
277278
g.Expect(err).To(HaveOccurred())
278279
} else {

0 commit comments

Comments
 (0)