Skip to content

Commit

Permalink
Merge pull request #3554 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…3551-to-release-1.9

[release-1.9] allow setting the NatGateway name if it's empty when update AzureCluster
  • Loading branch information
k8s-ci-robot authored May 12, 2023
2 parents 0acc847 + b0c046f commit efaae42
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/v1beta1/azurecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (c *AzureCluster) validateSubnetUpdate(old *AzureCluster) field.ErrorList {
c.Spec.NetworkSpec.Subnets[i].RouteTable.Name, "field is immutable"),
)
}
if subnet.NatGateway.Name != oldSubnet.NatGateway.Name {
if (subnet.NatGateway.Name != oldSubnet.NatGateway.Name) && (oldSubnet.NatGateway.Name != "") {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec", "networkSpec", "subnets").Index(oldSubnetIndex[subnet.Name]).Child("NatGateway").Child("Name"),
c.Spec.NetworkSpec.Subnets[i].NatGateway.Name, "field is immutable"),
Expand Down
24 changes: 24 additions & 0 deletions api/v1beta1/azurecluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,30 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
},
wantErr: true,
},
{
name: "natGateway name is immutable",
oldCluster: func() *AzureCluster {
cluster := createValidCluster()
cluster.Spec.NetworkSpec.Subnets[0].NatGateway.Name = "cluster-test-node-natgw-0"
return cluster
}(),
cluster: func() *AzureCluster {
cluster := createValidCluster()
cluster.Spec.NetworkSpec.Subnets[0].NatGateway.Name = "cluster-test-node-natgw-1"
return cluster
}(),
wantErr: true,
},
{
name: "natGateway name can be empty before AzureCluster is updated",
oldCluster: createValidCluster(),
cluster: func() *AzureCluster {
cluster := createValidCluster()
cluster.Spec.NetworkSpec.Subnets[0].NatGateway.Name = "cluster-test-node-natgw"
return cluster
}(),
wantErr: false,
},
}
for _, tc := range tests {
tc := tc
Expand Down

0 comments on commit efaae42

Please sign in to comment.