Skip to content

Commit

Permalink
fix: Make .spec.subscriptionID mutable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlipovetsky committed Feb 16, 2024
1 parent 739b0f2 commit 7e140f9
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 24 deletions.
7 changes: 0 additions & 7 deletions api/v1beta1/azurecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/azuremanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -1593,7 +1593,7 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
},
},
},
wantErr: true,
wantErr: false,
},
{
name: "AzureManagedControlPlane ResourceGroupName is immutable",
Expand Down
6 changes: 0 additions & 6 deletions api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7e140f9

Please sign in to comment.