Skip to content

Commit

Permalink
Bump CAPI to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Jul 14, 2023
1 parent 63d4946 commit 6280f45
Show file tree
Hide file tree
Showing 45 changed files with 325 additions and 306 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create
./hack/create-custom-cloud-provider-config.sh

# Deploy CAPI
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.4/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.0-rc.0/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -

# Deploy CAPZ
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=$(KIND_CLUSTER_NAME)
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "capz",
"capi_version": "v1.4.4",
"capi_version": "v1.5.0-rc.0",
"cert_manager_version": "v1.12.2",
"kubernetes_version": "v1.27.2",
"aks_kubernetes_version": "v1.26.3",
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/azurecluster_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api-provider-azure/feature"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

const (
Expand Down Expand Up @@ -68,15 +69,15 @@ var (
)

// validateCluster validates a cluster.
func (c *AzureCluster) validateCluster(old *AzureCluster) error {
func (c *AzureCluster) validateCluster(old *AzureCluster) (admission.Warnings, error) {
var allErrs field.ErrorList
allErrs = append(allErrs, c.validateClusterName()...)
allErrs = append(allErrs, c.validateClusterSpec(old)...)
if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(
return nil, apierrors.NewInvalid(
schema.GroupKind{Group: "infrastructure.cluster.x-k8s.io", Kind: "AzureCluster"},
c.Name, allErrs)
}
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/azurecluster_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestClusterWithPreexistingVnetValid(t *testing.T) {
}

t.Run(testCase.name, func(t *testing.T) {
err := testCase.cluster.validateCluster(nil)
_, err := testCase.cluster.validateCluster(nil)
g.Expect(err).To(BeNil())
})
}
Expand All @@ -142,7 +142,7 @@ func TestClusterWithPreexistingVnetInvalid(t *testing.T) {
}

t.Run(testCase.name, func(t *testing.T) {
err := testCase.cluster.validateCluster(nil)
_, err := testCase.cluster.validateCluster(nil)
g.Expect(err).NotTo(BeNil())
})
}
Expand All @@ -165,7 +165,7 @@ func TestClusterWithoutPreexistingVnetValid(t *testing.T) {
testCase.cluster.Spec.NetworkSpec.Vnet.ResourceGroup = ""

t.Run(testCase.name, func(t *testing.T) {
err := testCase.cluster.validateCluster(nil)
_, err := testCase.cluster.validateCluster(nil)
g.Expect(err).To(BeNil())
})
}
Expand Down
11 changes: 6 additions & 5 deletions api/v1beta1/azurecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// SetupWebhookWithManager sets up and registers the webhook with the manager.
Expand All @@ -46,12 +47,12 @@ func (c *AzureCluster) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureCluster) ValidateCreate() error {
func (c *AzureCluster) ValidateCreate() (admission.Warnings, error) {
return c.validateCluster(nil)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) error {
func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList
old := oldRaw.(*AzureCluster)

Expand Down Expand Up @@ -135,7 +136,7 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) error {
return c.validateCluster(old)
}

return apierrors.NewInvalid(GroupVersion.WithKind("AzureCluster").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureCluster").GroupKind(), c.Name, allErrs)
}

// validateSubnetUpdate validates a ClusterSpec.NetworkSpec.Subnets for immutability.
Expand Down Expand Up @@ -187,6 +188,6 @@ func (c *AzureCluster) validateSubnetUpdate(old *AzureCluster) field.ErrorList {
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureCluster) ValidateDelete() error {
return nil
func (c *AzureCluster) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions api/v1beta1/azurecluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestAzureCluster_ValidateCreate(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.cluster.ValidateCreate()
_, err := tc.cluster.ValidateCreate()
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := tc.cluster.ValidateUpdate(tc.oldCluster)
_, err := tc.cluster.ValidateUpdate(tc.oldCluster)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/azureclusteridentity_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ package v1beta1
import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *AzureClusterIdentity) validateClusterIdentity() error {
func (c *AzureClusterIdentity) validateClusterIdentity() (admission.Warnings, error) {
var allErrs field.ErrorList
if c.Spec.Type == UserAssignedMSI && c.Spec.ResourceID == "" {
allErrs = append(allErrs, field.Required(field.NewPath("spec", "resourceID"), c.Spec.ResourceID))
} else if c.Spec.Type != UserAssignedMSI && c.Spec.ResourceID != "" {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "resourceID"), c.Spec.ResourceID))
}
if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
}
11 changes: 6 additions & 5 deletions api/v1beta1/azureclusteridentity_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// SetupWebhookWithManager sets up and registers the webhook with the manager.
Expand All @@ -37,12 +38,12 @@ func (c *AzureClusterIdentity) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &AzureClusterIdentity{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterIdentity) ValidateCreate() error {
func (c *AzureClusterIdentity) ValidateCreate() (admission.Warnings, error) {
return c.validateClusterIdentity()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) error {
func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList
old := oldRaw.(*AzureClusterIdentity)
if err := webhookutils.ValidateImmutable(
Expand All @@ -54,10 +55,10 @@ func (c *AzureClusterIdentity) ValidateUpdate(oldRaw runtime.Object) error {
if len(allErrs) == 0 {
return c.validateClusterIdentity()
}
return apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterIdentity").GroupKind(), c.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterIdentity) ValidateDelete() error {
return nil
func (c *AzureClusterIdentity) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions api/v1beta1/azureclusteridentity_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestAzureClusterIdentity_ValidateCreate(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.clusterIdentity.ValidateCreate()
_, err := tc.clusterIdentity.ValidateCreate()
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAzureClusterIdentity_ValidateUpdate(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.clusterIdentity.ValidateUpdate(tc.oldClusterIdentity)
_, err := tc.clusterIdentity.ValidateUpdate(tc.oldClusterIdentity)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/azureclustertemplate_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *AzureClusterTemplate) validateClusterTemplate() error {
func (c *AzureClusterTemplate) validateClusterTemplate() (admission.Warnings, error) {
var allErrs field.ErrorList
allErrs = append(allErrs, c.validateClusterTemplateSpec()...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(
return nil, apierrors.NewInvalid(
schema.GroupKind{Group: "infrastructure.cluster.x-k8s.io", Kind: "AzureClusterTemplate"},
c.Name, allErrs)
}
Expand Down
13 changes: 7 additions & 6 deletions api/v1beta1/azureclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// AzureClusterTemplateImmutableMsg is the message used for errors on fields that are immutable.
Expand All @@ -49,12 +50,12 @@ func (c *AzureClusterTemplate) Default() {
var _ webhook.Validator = &AzureClusterTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterTemplate) ValidateCreate() error {
func (c *AzureClusterTemplate) ValidateCreate() (admission.Warnings, error) {
return c.validateClusterTemplate()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList
old := oldRaw.(*AzureClusterTemplate)
if !reflect.DeepEqual(c.Spec.Template.Spec, old.Spec.Template.Spec) {
Expand All @@ -64,12 +65,12 @@ func (c *AzureClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterTemplate").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureClusterTemplate").GroupKind(), c.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *AzureClusterTemplate) ValidateDelete() error {
return nil
func (c *AzureClusterTemplate) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
3 changes: 2 additions & 1 deletion api/v1beta1/azureclustertemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestValidateUpdate(t *testing.T) {

t.Run("template is immutable", func(t *testing.T) {
g := NewWithT(t)
g.Expect(newClusterTemplate.ValidateUpdate(oldClusterTemplate)).NotTo(Succeed())
_, err := newClusterTemplate.ValidateUpdate(oldClusterTemplate)
g.Expect(err).To(HaveOccurred())
})
}
23 changes: 12 additions & 11 deletions api/v1beta1/azuremachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// SetupAzureMachineWebhookWithManager sets up and registers the webhook with the manager.
Expand All @@ -47,10 +48,10 @@ type azureMachineWebhook struct {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (mw *azureMachineWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (mw *azureMachineWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
m, ok := obj.(*AzureMachine)
if !ok {
return apierrors.NewBadRequest("expected an AzureMachine resource")
return nil, apierrors.NewBadRequest("expected an AzureMachine resource")
}
spec := m.Spec

Expand All @@ -66,22 +67,22 @@ func (mw *azureMachineWebhook) ValidateCreate(ctx context.Context, obj runtime.O
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(GroupVersion.WithKind("AzureMachine").GroupKind(), m.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureMachine").GroupKind(), m.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (mw *azureMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (mw *azureMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList
old, ok := oldObj.(*AzureMachine)
if !ok {
return apierrors.NewBadRequest("expected an AzureMachine resource")
return nil, apierrors.NewBadRequest("expected an AzureMachine resource")
}
m, ok := newObj.(*AzureMachine)
if !ok {
return apierrors.NewBadRequest("expected an AzureMachine resource")
return nil, apierrors.NewBadRequest("expected an AzureMachine resource")
}

if err := webhookutils.ValidateImmutable(
Expand Down Expand Up @@ -206,14 +207,14 @@ func (mw *azureMachineWebhook) ValidateUpdate(ctx context.Context, oldObj, newOb
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("AzureMachine").GroupKind(), m.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AzureMachine").GroupKind(), m.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (mw *azureMachineWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) error {
return nil
func (mw *azureMachineWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/azuremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestAzureMachine_ValidateCreate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
mw := &azureMachineWebhook{}
err := mw.ValidateCreate(context.Background(), tc.machine)
_, err := mw.ValidateCreate(context.Background(), tc.machine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestAzureMachine_ValidateUpdate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
mw := &azureMachineWebhook{}
err := mw.ValidateUpdate(context.Background(), tc.oldMachine, tc.newMachine)
_, err := mw.ValidateUpdate(context.Background(), tc.oldMachine, tc.newMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
Loading

0 comments on commit 6280f45

Please sign in to comment.