diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index 7bce885162e..e9d781fc954 100644 --- a/azure/scope/cluster.go +++ b/azure/scope/cluster.go @@ -314,7 +314,7 @@ func (s *ClusterScope) RouteTableSpecs() []azure.ResourceSpecGetter { specs = append(specs, &routetables.RouteTableSpec{ Name: subnet.RouteTable.Name, Location: s.Location(), - ResourceGroup: s.ResourceGroup(), + ResourceGroup: s.Vnet().ResourceGroup, ClusterName: s.ClusterName(), AdditionalTags: s.AdditionalTags(), }) @@ -359,7 +359,7 @@ func (s *ClusterScope) NSGSpecs() []azure.ResourceSpecGetter { nsgspecs[i] = &securitygroups.NSGSpec{ Name: subnet.SecurityGroup.Name, SecurityRules: subnet.SecurityGroup.SecurityRules, - ResourceGroup: s.ResourceGroup(), + ResourceGroup: s.Vnet().ResourceGroup, Location: s.Location(), ClusterName: s.ClusterName(), AdditionalTags: s.AdditionalTags(), diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index b726a93f1b2..08259e69285 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -809,11 +809,13 @@ func TestRouteTableSpecs(t *testing.T) { }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ - ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", }, NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + ResourceGroup: "my-rg", + }, Subnets: infrav1.Subnets{ { RouteTable: infrav1.RouteTable{ @@ -1140,11 +1142,13 @@ func TestNSGSpecs(t *testing.T) { }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ - ResourceGroup: "my-rg", AzureClusterClassSpec: infrav1.AzureClusterClassSpec{ Location: "centralIndia", }, NetworkSpec: infrav1.NetworkSpec{ + Vnet: infrav1.VnetSpec{ + ResourceGroup: "my-rg", + }, Subnets: infrav1.Subnets{ { SecurityGroup: infrav1.SecurityGroup{ diff --git a/templates/test/ci/cluster-template-prow-custom-vnet.yaml b/templates/test/ci/cluster-template-prow-custom-vnet.yaml index 877f8c4521e..e36a05b1eba 100644 --- a/templates/test/ci/cluster-template-prow-custom-vnet.yaml +++ b/templates/test/ci/cluster-template-prow-custom-vnet.yaml @@ -46,7 +46,7 @@ spec: name: node-nsg vnet: name: ${AZURE_CUSTOM_VNET_NAME} - resourceGroup: ${AZURE_RESOURCE_GROUP} + resourceGroup: ${AZURE_CUSTOM_VNET_RESOURCE_GROUP} resourceGroup: ${AZURE_RESOURCE_GROUP:=${CLUSTER_NAME}} subscriptionID: ${AZURE_SUBSCRIPTION_ID} --- diff --git a/templates/test/ci/cluster-template-prow-private.yaml b/templates/test/ci/cluster-template-prow-private.yaml index ad9f070ff2b..4f73813f67d 100644 --- a/templates/test/ci/cluster-template-prow-private.yaml +++ b/templates/test/ci/cluster-template-prow-private.yaml @@ -72,7 +72,7 @@ spec: name: ${AZURE_VNET_NAME} peerings: - remoteVnetName: ${AZURE_CUSTOM_VNET_NAME} - resourceGroup: ${AZURE_RESOURCE_GROUP} + resourceGroup: ${AZURE_CUSTOM_VNET_RESOURCE_GROUP} resourceGroup: ${AZURE_RESOURCE_GROUP:=${CLUSTER_NAME}} subscriptionID: ${AZURE_SUBSCRIPTION_ID} --- diff --git a/templates/test/ci/prow-custom-vnet/patches/custom-vnet.yaml b/templates/test/ci/prow-custom-vnet/patches/custom-vnet.yaml index 7ab60e71a92..d265d8ef201 100644 --- a/templates/test/ci/prow-custom-vnet/patches/custom-vnet.yaml +++ b/templates/test/ci/prow-custom-vnet/patches/custom-vnet.yaml @@ -5,7 +5,7 @@ metadata: spec: networkSpec: vnet: - resourceGroup: ${AZURE_RESOURCE_GROUP} + resourceGroup: ${AZURE_CUSTOM_VNET_RESOURCE_GROUP} name: ${AZURE_CUSTOM_VNET_NAME} subnets: - name: ${AZURE_CUSTOM_VNET_NAME}-controlplane-subnet diff --git a/templates/test/ci/prow-private/patches/vnet-peerings.yaml b/templates/test/ci/prow-private/patches/vnet-peerings.yaml index 7eb9ff1c6ea..fc51c6a5d5e 100644 --- a/templates/test/ci/prow-private/patches/vnet-peerings.yaml +++ b/templates/test/ci/prow-private/patches/vnet-peerings.yaml @@ -15,7 +15,7 @@ spec: cidrBlocks: - ${AZURE_PRIVATE_VNET_CIDR} peerings: - - resourceGroup: ${AZURE_RESOURCE_GROUP} + - resourceGroup: ${AZURE_CUSTOM_VNET_RESOURCE_GROUP} remoteVnetName: ${AZURE_CUSTOM_VNET_NAME} subnets: - name: private-cp-subnet diff --git a/test/e2e/azure_privatecluster.go b/test/e2e/azure_privatecluster.go index 4e034352867..50e8899ba31 100644 --- a/test/e2e/azure_privatecluster.go +++ b/test/e2e/azure_privatecluster.go @@ -227,7 +227,7 @@ func SetupExistingVNet(ctx context.Context, vnetCidr string, cpSubnetCidrs, node routetableClient.Authorizer = authorizer By("creating a resource group") - groupName := os.Getenv(AzureResourceGroup) + groupName := os.Getenv(AzureCustomVnetResourceGroup) _, err = groupClient.CreateOrUpdate(ctx, groupName, resources.Group{ Location: ptr.To(os.Getenv(AzureLocation)), Tags: map[string]*string{ diff --git a/test/e2e/azure_test.go b/test/e2e/azure_test.go index 3a564228220..ceb4b75e591 100644 --- a/test/e2e/azure_test.go +++ b/test/e2e/azure_test.go @@ -135,6 +135,7 @@ var _ = Describe("Workload cluster creation", func() { } dumpSpecResourcesAndCleanup(ctx, cleanInput) Expect(os.Unsetenv(AzureResourceGroup)).To(Succeed()) + Expect(os.Unsetenv(AzureCustomVnetResourceGroup)).To(Succeed()) Expect(os.Unsetenv(AzureVNetName)).To(Succeed()) Expect(os.Unsetenv(ClusterIdentityName)).To(Succeed()) Expect(os.Unsetenv(ClusterIdentityNamespace)).To(Succeed()) @@ -155,6 +156,7 @@ var _ = Describe("Workload cluster creation", func() { clusterName = getClusterName(clusterNamePrefix, "public-custom-vnet") By("Creating a custom virtual network", func() { Expect(os.Setenv(AzureCustomVNetName, "custom-vnet")).To(Succeed()) + Expect(os.Setenv(AzureCustomVnetResourceGroup, clusterName+"-vnetrg")).To(Succeed()) additionalCleanup = SetupExistingVNet(ctx, "10.0.0.0/16", map[string]string{fmt.Sprintf("%s-controlplane-subnet", os.Getenv(AzureCustomVNetName)): "10.0.0.0/24"}, diff --git a/test/e2e/common.go b/test/e2e/common.go index 30674d3e79b..00136e6cab6 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -58,6 +58,7 @@ const ( AzureExtendedLocationType = "AZURE_EXTENDEDLOCATION_TYPE" AzureExtendedLocationName = "AZURE_EXTENDEDLOCATION_NAME" AzureResourceGroup = "AZURE_RESOURCE_GROUP" + AzureCustomVnetResourceGroup = "AZURE_CUSTOM_VNET_RESOURCE_GROUP" AzureVNetName = "AZURE_VNET_NAME" AzureCustomVNetName = "AZURE_CUSTOM_VNET_NAME" AzureInternalLBIP = "AZURE_INTERNAL_LB_IP"