Skip to content
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

Bump CAPI to v1.5.0 #3707

Merged
merged 1 commit into from
Aug 14, 2023
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook
RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
ASO_CRDS_PATH := $(MANIFEST_ROOT)/aso/crds.yaml
ASO_VERSION := v2.1.0
ASO_VERSION := v2.2.0
ASO_CRDS := resourcegroups.resources.azure.com

# Allow overriding the imagePullPolicy
Expand Down Expand Up @@ -301,7 +301,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.5/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/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.5",
"capi_version": "v1.5.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/ptr"
"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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is really cool! we should use those, there are a few places where I'm sure they'd be useful

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 @@
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 @@
}

// 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 @@
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 @@
}

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

Check warning on line 192 in api/v1beta1/azurecluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azurecluster_webhook.go#L191-L192

Added lines #L191 - L192 were not covered by tests
}
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 @@
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 @@
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 @@
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

Check warning on line 63 in api/v1beta1/azureclusteridentity_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclusteridentity_webhook.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}
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 @@
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) {

Check warning on line 28 in api/v1beta1/azureclustertemplate_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_validation.go#L28

Added line #L28 was not covered by tests
var allErrs field.ErrorList
allErrs = append(allErrs, c.validateClusterTemplateSpec()...)

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

Check warning on line 33 in api/v1beta1/azureclustertemplate_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_validation.go#L33

Added line #L33 was not covered by tests
}

return apierrors.NewInvalid(
return nil, apierrors.NewInvalid(

Check warning on line 36 in api/v1beta1/azureclustertemplate_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_validation.go#L36

Added line #L36 was not covered by tests
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 @@
"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 @@
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) {

Check warning on line 53 in api/v1beta1/azureclustertemplate_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_webhook.go#L53

Added line #L53 was not covered by tests
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 @@
}

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

Check warning on line 68 in api/v1beta1/azureclustertemplate_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_webhook.go#L68

Added line #L68 was not covered by tests
}
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

Check warning on line 75 in api/v1beta1/azureclustertemplate_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azureclustertemplate_webhook.go#L74-L75

Added lines #L74 - L75 were not covered by tests
}
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 @@
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 @@
}

// 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")

Check warning on line 54 in api/v1beta1/azuremachine_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremachine_webhook.go#L54

Added line #L54 was not covered by tests
}
spec := m.Spec

Expand All @@ -66,22 +67,22 @@
}

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")

Check warning on line 81 in api/v1beta1/azuremachine_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremachine_webhook.go#L81

Added line #L81 was not covered by tests
}
m, ok := newObj.(*AzureMachine)
if !ok {
return apierrors.NewBadRequest("expected an AzureMachine resource")
return nil, apierrors.NewBadRequest("expected an AzureMachine resource")

Check warning on line 85 in api/v1beta1/azuremachine_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremachine_webhook.go#L85

Added line #L85 was not covered by tests
}

if err := webhookutils.ValidateImmutable(
Expand Down Expand Up @@ -206,14 +207,14 @@
}

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

Check warning on line 217 in api/v1beta1/azuremachine_webhook.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta1/azuremachine_webhook.go#L216-L217

Added lines #L216 - L217 were not covered by tests
}

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