@@ -125,4 +125,79 @@ var _ = ginkgo.Context("[unmanaged] [functional] [ClusterClass]", func() {
125
125
Expect (len (controlPlaneMachines )).To (Equal (1 ))
126
126
})
127
127
})
128
+
129
+ // This test creates a workload cluster using an externally managed VPC and subnets. CAPA is still handling security group
130
+ // creation for the cluster. All applicable resources are restricted to us-west-2a for simplicity.
131
+ ginkgo .Describe ("Workload cluster with external infrastructure" , func () {
132
+ var namespace * corev1.Namespace
133
+ var requiredResources * shared.TestResource
134
+ specName := "functional-test-extinfra-clusterclass"
135
+ mgmtClusterName := fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
136
+ mgmtClusterInfra := new (shared.AWSInfrastructure )
137
+
138
+ // Some infrastructure creation was moved to a setup node to better organize the test.
139
+ ginkgo .JustBeforeEach (func () {
140
+ requiredResources = & shared.TestResource {EC2Normal : 2 * e2eCtx .Settings .InstanceVCPU , IGW : 2 , NGW : 2 , VPC : 2 , ClassicLB : 2 , EIP : 5 }
141
+ requiredResources .WriteRequestedResources (e2eCtx , specName )
142
+ Expect (shared .AcquireResources (requiredResources , config .GinkgoConfig .ParallelNode , flock .New (shared .ResourceQuotaFilePath ))).To (Succeed ())
143
+ namespace = shared .SetupSpecNamespace (ctx , specName , e2eCtx )
144
+ ginkgo .By ("Creating the management cluster infrastructure" )
145
+ mgmtClusterInfra .New (shared.AWSInfrastructureSpec {
146
+ ClusterName : mgmtClusterName ,
147
+ VpcCidr : "10.0.0.0/23" ,
148
+ PublicSubnetCidr : "10.0.0.0/24" ,
149
+ PrivateSubnetCidr : "10.0.1.0/24" ,
150
+ AvailabilityZone : "us-west-2a" ,
151
+ }, e2eCtx )
152
+ mgmtClusterInfra .CreateInfrastructure ()
153
+ })
154
+
155
+ // Infrastructure cleanup is done in setup node so it is not bypassed if there is a test failure in the subject node.
156
+ ginkgo .JustAfterEach (func () {
157
+ shared .ReleaseResources (requiredResources , config .GinkgoConfig .ParallelNode , flock .New (shared .ResourceQuotaFilePath ))
158
+ shared .DumpSpecResourcesAndCleanup (ctx , "" , namespace , e2eCtx )
159
+ if ! e2eCtx .Settings .SkipCleanup {
160
+ ginkgo .By ("Deleting the management cluster infrastructure" )
161
+ mgmtClusterInfra .DeleteInfrastructure ()
162
+ }
163
+ })
164
+
165
+ ginkgo .It ("should create workload cluster in external VPC" , func () {
166
+ ginkgo .By ("Validating management infrastructure" )
167
+ Expect (mgmtClusterInfra .VPC ).NotTo (BeNil ())
168
+ Expect (* mgmtClusterInfra .State .VpcState ).To (Equal ("available" ))
169
+ Expect (len (mgmtClusterInfra .Subnets )).To (Equal (2 ))
170
+ Expect (mgmtClusterInfra .InternetGateway ).NotTo (BeNil ())
171
+ Expect (mgmtClusterInfra .ElasticIP ).NotTo (BeNil ())
172
+ Expect (mgmtClusterInfra .NatGateway ).NotTo (BeNil ())
173
+ Expect (len (mgmtClusterInfra .RouteTables )).To (Equal (2 ))
174
+
175
+ shared .SetEnvVar ("BYO_VPC_ID" , * mgmtClusterInfra .VPC .VpcId , false )
176
+ shared .SetEnvVar ("BYO_PUBLIC_SUBNET_ID" , * mgmtClusterInfra .State .PublicSubnetID , false )
177
+ shared .SetEnvVar ("BYO_PRIVATE_SUBNET_ID" , * mgmtClusterInfra .State .PrivateSubnetID , false )
178
+
179
+ ginkgo .By ("Creating a management cluster in a peered VPC" )
180
+ mgmtConfigCluster := defaultConfigCluster (mgmtClusterName , namespace .Name )
181
+ mgmtConfigCluster .WorkerMachineCount = pointer .Int64Ptr (1 )
182
+ mgmtConfigCluster .Flavor = "external-vpc-clusterclass"
183
+ mgmtCluster , mgmtMD , _ := createCluster (ctx , mgmtConfigCluster , result )
184
+
185
+ mgmtWM := framework .GetMachinesByMachineDeployments (ctx , framework.GetMachinesByMachineDeploymentsInput {
186
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
187
+ ClusterName : mgmtClusterName ,
188
+ Namespace : namespace .Name ,
189
+ MachineDeployment : * mgmtMD [0 ],
190
+ })
191
+ mgmtCPM := framework .GetControlPlaneMachinesByCluster (ctx , framework.GetControlPlaneMachinesByClusterInput {
192
+ Lister : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
193
+ ClusterName : mgmtClusterName ,
194
+ Namespace : namespace .Name ,
195
+ })
196
+ Expect (len (mgmtWM )).To (Equal (1 ))
197
+ Expect (len (mgmtCPM )).To (Equal (1 ))
198
+ ginkgo .By ("Deleting the management cluster" )
199
+ deleteCluster (ctx , mgmtCluster )
200
+ })
201
+ })
202
+
128
203
})
0 commit comments