Skip to content

Bump CAPI to v1.10.2 #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export GOPROXY
export GO111MODULE=on

# Go version
GOLANG_VERSION := 1.22.11
GOLANG_VERSION := 1.23.9

# Kubebuilder
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.31.0
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.32.0
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?=60s
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?=60s

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

CONTROLLER_GEN_VER := v0.17.1
CONTROLLER_GEN_VER := v0.17.3
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)

CONVERSION_GEN_VER := v0.31.5
CONVERSION_GEN_VER := v0.32.0
CONVERSION_GEN_BIN := conversion-gen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)-$(CONVERSION_GEN_VER)

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

KIND_VER := v0.26.0
KIND_VER := v0.27.0
KIND_BIN := kind
KIND := $(TOOLS_BIN_DIR)/$(KIND_BIN)-$(KIND_VER)

Expand Down
40 changes: 24 additions & 16 deletions api/v1beta1/gcpcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta1

import (
"context"
"fmt"
"reflect"

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

// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (c *GCPCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
w := new(gcpClusterWebhook)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move the webhooks to internal/webhooks so that we start brining the structure in line with upstream CAPI and also kubebuilder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds reasonable. But can this be done in a separate pr (preferrably by project maintainers), as this will look like a lot of change in the pr and mask the actual change needed to make things work with the kubebuilder api breakage?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah +1 for doing this, but probably best to do it in a follow up PR to avoid polluting this one

return ctrl.NewWebhookManagedBy(mgr).
For(c).
WithValidator(w).
WithDefaulter(w).
Complete()
}

// +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
// +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

type gcpClusterWebhook struct{}

var (
_ webhook.Validator = &GCPCluster{}
_ webhook.Defaulter = &GCPCluster{}
_ webhook.CustomValidator = &gcpClusterWebhook{}
_ webhook.CustomDefaulter = &gcpClusterWebhook{}
)

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (c *GCPCluster) Default() {
clusterlog.Info("default", "name", c.Name)
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
func (*gcpClusterWebhook) Default(_ context.Context, _ runtime.Object) error {
return nil
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *GCPCluster) ValidateCreate() (admission.Warnings, error) {
clusterlog.Info("validate create", "name", c.Name)

// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
func (*gcpClusterWebhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
func (*gcpClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
c, ok := newObj.(*GCPCluster)
if !ok {
return nil, fmt.Errorf("expected an GCPCluster object but got %T", c)
}

clusterlog.Info("validate update", "name", c.Name)
var allErrs field.ErrorList
old := oldRaw.(*GCPCluster)
old := oldObj.(*GCPCluster)

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

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *GCPCluster) ValidateDelete() (admission.Warnings, error) {
clusterlog.Info("validate delete", "name", c.Name)

// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
func (*gcpClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
3 changes: 2 additions & 1 deletion api/v1beta1/gcpcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestGCPCluster_ValidateUpdate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
warn, err := test.newCluster.ValidateUpdate(test.oldCluster)
warn, err := (&gcpClusterWebhook{}).ValidateUpdate(context.Background(), test.oldCluster, test.newCluster)
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
47 changes: 26 additions & 21 deletions api/v1beta1/gcpclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,56 @@ limitations under the License.
package v1beta1

import (
"context"
"fmt"
"reflect"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
var gcpclustertemplatelog = logf.Log.WithName("gcpclustertemplate-resource")

func (r *GCPClusterTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
w := new(gcpClusterTemplateWebhook)
return ctrl.NewWebhookManagedBy(mgr).
For(r).
WithValidator(w).
WithDefaulter(w).
Complete()
}

//+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
//+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

var _ webhook.Defaulter = &GCPClusterTemplate{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *GCPClusterTemplate) Default() {
gcpclustertemplatelog.Info("default", "name", r.Name)
}
type gcpClusterTemplateWebhook struct{}

var _ webhook.Validator = &GCPClusterTemplate{}
var (
_ webhook.CustomDefaulter = &gcpClusterTemplateWebhook{}
_ webhook.CustomValidator = &gcpClusterTemplateWebhook{}
)

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

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

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
old, ok := oldRaw.(*GCPClusterTemplate)
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
func (*gcpClusterTemplateWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
r, ok := newObj.(*GCPClusterTemplate)
if !ok {
return nil, fmt.Errorf("expected an GCPClusterTemplate object but got %T", r)
}

old, ok := oldObj.(*GCPClusterTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldRaw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldObj))
}

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

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPClusterTemplate) ValidateDelete() (admission.Warnings, error) {
gcpclustertemplatelog.Info("validate delete", "name", r.Name)
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
func (*gcpClusterTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
3 changes: 2 additions & 1 deletion api/v1beta1/gcpclustertemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
warn, err := test.newTemplate.ValidateUpdate(test.oldTemplate)
warn, err := (&gcpClusterTemplateWebhook{}).ValidateUpdate(context.Background(), test.oldTemplate, test.newTemplate)
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
35 changes: 26 additions & 9 deletions api/v1beta1/gcpmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"context"
"fmt"
"reflect"
"strings"
Expand All @@ -37,18 +38,31 @@ import (
var _ = logf.Log.WithName("gcpmachine-resource")

func (m *GCPMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
w := new(gcpMachineWebhook)
return ctrl.NewWebhookManagedBy(mgr).
For(m).
WithValidator(w).
WithDefaulter(w).
Complete()
}

// +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
// +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

var _ webhook.Validator = &GCPMachine{}
type gcpMachineWebhook struct{}

var (
_ webhook.CustomValidator = &gcpMachineWebhook{}
_ webhook.CustomDefaulter = &gcpMachineWebhook{}
)

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
func (*gcpMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
m, ok := obj.(*GCPMachine)
if !ok {
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
}

clusterlog.Info("validate create", "name", m.Name)

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

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (*gcpMachineWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
m, ok := newObj.(*GCPMachine)
if !ok {
return nil, fmt.Errorf("expected an GCPMachine object but got %T", m)
}

newGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
if err != nil {
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachine to unstructured object")),
})
}
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(oldObj)
if err != nil {
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachine to unstructured object")),
Expand Down Expand Up @@ -97,15 +116,13 @@ func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateDelete() (admission.Warnings, error) {
clusterlog.Info("validate delete", "name", m.Name)

func (*gcpMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

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

func validateConfidentialCompute(spec GCPMachineSpec) error {
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/gcpmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -272,7 +273,7 @@ func TestGCPMachine_ValidateCreate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
warn, err := test.GCPMachine.ValidateCreate()
warn, err := (&gcpMachineWebhook{}).ValidateCreate(context.Background(), test.GCPMachine)
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
Loading