From 7e140f98fd36e0783b0f372136d08db150c11333 Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Fri, 16 Feb 2024 09:18:12 -0800 Subject: [PATCH] fix: Make .spec.subscriptionID mutable The field is effectively required, because the former alternative source, the manager credential, was removed in v1.11.0. To allow newer releases to reconcile existing resources, we need to update their .spec.subscriptionID. This change allows the field to be updated. --- api/v1beta1/azurecluster_webhook.go | 7 ------- api/v1beta1/azuremanagedcontrolplane_webhook.go | 7 ------- api/v1beta1/azuremanagedcontrolplane_webhook_test.go | 4 ++-- api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go | 6 ------ .../azuremanagedcontrolplanetemplate_webhook_test.go | 4 ++-- 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/api/v1beta1/azurecluster_webhook.go b/api/v1beta1/azurecluster_webhook.go index 49cc7c7fe00..9fd7e6fe64a 100644 --- a/api/v1beta1/azurecluster_webhook.go +++ b/api/v1beta1/azurecluster_webhook.go @@ -63,13 +63,6 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings allErrs = append(allErrs, err) } - if err := webhookutils.ValidateImmutable( - field.NewPath("Spec", "SubscriptionID"), - old.Spec.SubscriptionID, - c.Spec.SubscriptionID); err != nil { - allErrs = append(allErrs, err) - } - if err := webhookutils.ValidateImmutable( field.NewPath("Spec", "Location"), old.Spec.Location, diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go index 4c9da179082..193b5ef3857 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -131,13 +131,6 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o return nil, apierrors.NewBadRequest("expected an AzureManagedControlPlane") } - if err := webhookutils.ValidateImmutable( - field.NewPath("Spec", "SubscriptionID"), - old.Spec.SubscriptionID, - m.Spec.SubscriptionID); err != nil { - allErrs = append(allErrs, err) - } - if err := webhookutils.ValidateImmutable( field.NewPath("Spec", "ResourceGroupName"), old.Spec.ResourceGroupName, diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go index bca8dd29efd..d2f43672f90 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go @@ -1574,7 +1574,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { wantErr: true, }, { - name: "AzureManagedControlPlane SubscriptionID is immutable", + name: "AzureManagedControlPlane SubscriptionID is mutable", oldAMCP: &AzureManagedControlPlane{ Spec: AzureManagedControlPlaneSpec{ AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{ @@ -1593,7 +1593,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) { }, }, }, - wantErr: true, + wantErr: false, }, { name: "AzureManagedControlPlane ResourceGroupName is immutable", diff --git a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go index 245d18113e1..1daa717f0a4 100644 --- a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go @@ -87,12 +87,6 @@ func (mcpw *azureManagedControlPlaneTemplateWebhook) ValidateUpdate(ctx context. if !ok { return nil, apierrors.NewBadRequest("expected an AzureManagedControlPlaneTemplate") } - if err := webhookutils.ValidateImmutable( - field.NewPath("Spec", "Template", "Spec", "SubscriptionID"), - old.Spec.Template.Spec.SubscriptionID, - mcp.Spec.Template.Spec.SubscriptionID); err != nil { - allErrs = append(allErrs, err) - } if err := webhookutils.ValidateImmutable( field.NewPath("Spec", "Template", "Spec", "Location"), diff --git a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go index 326d9c40eeb..a4424b98fec 100644 --- a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go +++ b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go @@ -79,14 +79,14 @@ func TestControlPlaneTemplateUpdateWebhook(t *testing.T) { wantErr: false, }, { - name: "azuremanagedcontrolplanetemplate subscriptionID is immutable", + name: "azuremanagedcontrolplanetemplate subscriptionID is mutable", oldControlPlaneTemplate: getAzureManagedControlPlaneTemplate(func(cpt *AzureManagedControlPlaneTemplate) { cpt.Spec.Template.Spec.SubscriptionID = "foo" }), controlPlaneTemplate: getAzureManagedControlPlaneTemplate(func(cpt *AzureManagedControlPlaneTemplate) { cpt.Spec.Template.Spec.SubscriptionID = "bar" }), - wantErr: true, + wantErr: false, }, { name: "azuremanagedcontrolplanetemplate location is immutable",