Skip to content
Closed
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
5 changes: 4 additions & 1 deletion api/v1beta1/azurecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (c *AzureCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings
field.NewPath("Spec", "SubscriptionID"),
old.Spec.SubscriptionID,
c.Spec.SubscriptionID); err != nil {
allErrs = append(allErrs, err)
_, updateAllowed := c.Annotations[AzureClusterAllowMutateSubscriptionIDAnnotation]
if !updateAllowed {
allErrs = append(allErrs, err)
}
}

if err := webhookutils.ValidateImmutable(
Expand Down
53 changes: 26 additions & 27 deletions api/v1beta1/azurecluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,36 +220,35 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
wantErr: true,
},
{
name: "azurecluster resource group is immutable",
oldCluster: &AzureCluster{
Spec: AzureClusterSpec{
ResourceGroup: "demoResourceGroup",
},
},
cluster: &AzureCluster{
Spec: AzureClusterSpec{
ResourceGroup: "demoResourceGroup-2",
},
},
name: "azurecluster subscription ID is immutable without annotation",
oldCluster: func() *AzureCluster {
ac := createValidCluster()
ac.Spec.SubscriptionID = "212ec1q8"
return ac
}(),
cluster: func() *AzureCluster {
ac := createValidCluster()
ac.Spec.SubscriptionID = "212ec1q9"
return ac
}(),
Comment on lines +223 to +233
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this test did not create a valid cluster, which is bad, because that means it can return a false negative. I changed it to create a valid cluster.

Some other tests in this file have the same issue. I can fix these in a separate PR.

wantErr: true,
},
{
name: "azurecluster subscription ID is immutable",
oldCluster: &AzureCluster{
Spec: AzureClusterSpec{
AzureClusterClassSpec: AzureClusterClassSpec{
SubscriptionID: "212ec1q8",
},
},
},
cluster: &AzureCluster{
Spec: AzureClusterSpec{
AzureClusterClassSpec: AzureClusterClassSpec{
SubscriptionID: "212ec1q9",
},
},
},
wantErr: true,
name: "azurecluster subscription ID is mutable with annotation",
oldCluster: func() *AzureCluster {
ac := createValidCluster()
ac.Spec.SubscriptionID = "212ec1q8"
return ac
}(),
cluster: func() *AzureCluster {
ac := createValidCluster()
ac.Annotations = map[string]string{
AzureClusterAllowMutateSubscriptionIDAnnotation: "",
}
ac.Spec.SubscriptionID = "212ec1q9"
return ac
}(),
wantErr: false,
},
{
name: "azurecluster location is immutable",
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@ const (
// AzureClusterIdentityKind indicates the kind of an AzureClusterIdentity.
AzureClusterIdentityKind = "AzureClusterIdentity"
)

const (
// AzureClusterAllowMutateSubscriptionIDAnnotation is the key for the Azure Cluster object annotation
// which allows the AzureCluster spec.subscriptionID field to be updated.
AzureClusterAllowMutateSubscriptionIDAnnotation = "sigs.k8s.io/cluster-api-provider-azure-allow-mutate-subscription-id"
)