|
| 1 | +// Copyright 2025 Microsoft Corporation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package e2e |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "time" |
| 20 | + |
| 21 | + . "github.com/onsi/ginkgo/v2" |
| 22 | + . "github.com/onsi/gomega" |
| 23 | + |
| 24 | + "github.com/Azure/ARO-HCP/test/util/framework" |
| 25 | + "github.com/Azure/ARO-HCP/test/util/labels" |
| 26 | +) |
| 27 | + |
| 28 | +var _ = Describe("Customer", func() { |
| 29 | + |
| 30 | + It("should not be able to reuse subnets and NSGs between clusters", |
| 31 | + labels.RequireNothing, |
| 32 | + labels.Medium, |
| 33 | + labels.Negative, |
| 34 | + labels.AroRpApiCompatible, |
| 35 | + func(ctx context.Context) { |
| 36 | + const ( |
| 37 | + customerNetworkSecurityGroupName = "customer-nsg-name" |
| 38 | + customerVnetName = "customer-vnet-name" |
| 39 | + customerVnetSubnetName = "customer-vnet-subnet" |
| 40 | + ) |
| 41 | + tc := framework.NewTestContext() |
| 42 | + |
| 43 | + if tc.UsePooledIdentities() { |
| 44 | + err := tc.AssignIdentityContainers(ctx, 3, 60*time.Second) |
| 45 | + Expect(err).NotTo(HaveOccurred()) |
| 46 | + } |
| 47 | + |
| 48 | + By("creating a resource group") |
| 49 | + resourceGroup, err := tc.NewResourceGroup(ctx, "rg-cluster-nsg-subnet-reuse", tc.Location()) |
| 50 | + Expect(err).NotTo(HaveOccurred()) |
| 51 | + |
| 52 | + By("creating customer resources") |
| 53 | + clusterParams1 := framework.NewDefaultClusterParams() |
| 54 | + clusterParams1.ClusterName = "basic-cluster" |
| 55 | + managedResourceGroupName1 := framework.SuffixName(*resourceGroup.Name, "-managed-1", 64) |
| 56 | + clusterParams1.ManagedResourceGroupName = managedResourceGroupName1 |
| 57 | + |
| 58 | + clusterParams1, err = tc.CreateClusterCustomerResources(ctx, |
| 59 | + resourceGroup, |
| 60 | + clusterParams1, |
| 61 | + map[string]any{ |
| 62 | + "customerNsgName": customerNetworkSecurityGroupName + "1", |
| 63 | + "customerVnetName": customerVnetName + "1", |
| 64 | + "customerVnetSubnetName": customerVnetSubnetName + "1", |
| 65 | + }, |
| 66 | + TestArtifactsFS, |
| 67 | + ) |
| 68 | + Expect(err).NotTo(HaveOccurred()) |
| 69 | + |
| 70 | + By("creating HCP cluster") |
| 71 | + err = tc.CreateHCPClusterFromParam( |
| 72 | + ctx, |
| 73 | + GinkgoLogr, |
| 74 | + *resourceGroup.Name, |
| 75 | + clusterParams1, |
| 76 | + 45*time.Minute, |
| 77 | + ) |
| 78 | + Expect(err).NotTo(HaveOccurred()) |
| 79 | + |
| 80 | + By("creating customer resources with the same subnet resource ID") |
| 81 | + clusterParams2 := framework.NewDefaultClusterParams() |
| 82 | + clusterParams2.ClusterName = "cluster-subnet-reuse" |
| 83 | + managedResourceGroupName2 := framework.SuffixName(*resourceGroup.Name, "-managed-2", 64) |
| 84 | + clusterParams2.ManagedResourceGroupName = managedResourceGroupName2 |
| 85 | + |
| 86 | + clusterParams2, err = tc.CreateClusterCustomerResources(ctx, |
| 87 | + resourceGroup, |
| 88 | + clusterParams2, |
| 89 | + map[string]any{ |
| 90 | + "customerNsgName": customerNetworkSecurityGroupName + "2", |
| 91 | + "customerVnetName": customerVnetName + "2", |
| 92 | + "customerVnetSubnetName": customerVnetSubnetName + "2", |
| 93 | + }, |
| 94 | + TestArtifactsFS, |
| 95 | + ) |
| 96 | + Expect(err).NotTo(HaveOccurred()) |
| 97 | + |
| 98 | + clusterParams2.SubnetResourceID = clusterParams1.SubnetResourceID |
| 99 | + |
| 100 | + By("attempting to create HCP cluster with already used subnet resource") |
| 101 | + err = tc.CreateHCPClusterFromParam( |
| 102 | + ctx, |
| 103 | + GinkgoLogr, |
| 104 | + *resourceGroup.Name, |
| 105 | + clusterParams2, |
| 106 | + 5*time.Minute, |
| 107 | + ) |
| 108 | + Expect(err).To(HaveOccurred()) |
| 109 | + GinkgoLogr.Error(err, "cluster deployment error") |
| 110 | + Expect(err.Error()).To(MatchRegexp("Subnet .* is already in use by another cluster")) |
| 111 | + |
| 112 | + By("creating customer resources with the same NSG resource ID") |
| 113 | + clusterParams3 := framework.NewDefaultClusterParams() |
| 114 | + clusterParams3.ClusterName = "cluster-nsg-reuse" |
| 115 | + managedResourceGroupName3 := framework.SuffixName(*resourceGroup.Name, "-managed-3", 64) |
| 116 | + clusterParams3.ManagedResourceGroupName = managedResourceGroupName3 |
| 117 | + |
| 118 | + clusterParams3, err = tc.CreateClusterCustomerResources(ctx, |
| 119 | + resourceGroup, |
| 120 | + clusterParams3, |
| 121 | + map[string]any{ |
| 122 | + "customerNsgName": customerNetworkSecurityGroupName + "3", |
| 123 | + "customerVnetName": customerVnetName + "3", |
| 124 | + "customerVnetSubnetName": customerVnetSubnetName + "3", |
| 125 | + }, |
| 126 | + TestArtifactsFS, |
| 127 | + ) |
| 128 | + Expect(err).NotTo(HaveOccurred()) |
| 129 | + |
| 130 | + clusterParams3.NsgResourceID = clusterParams1.NsgResourceID |
| 131 | + |
| 132 | + By("attempting to create HCP cluster with already used NSG resource") |
| 133 | + err = tc.CreateHCPClusterFromParam( |
| 134 | + ctx, |
| 135 | + GinkgoLogr, |
| 136 | + *resourceGroup.Name, |
| 137 | + clusterParams3, |
| 138 | + 5*time.Minute, |
| 139 | + ) |
| 140 | + Expect(err).To(HaveOccurred()) |
| 141 | + GinkgoLogr.Error(err, "cluster deployment error") |
| 142 | + Expect(err.Error()).To(MatchRegexp("Network Security Group .* is already in use by another cluster")) |
| 143 | + |
| 144 | + }) |
| 145 | +}) |
0 commit comments