Skip to content

Commit 55a78fa

Browse files
committed
Add external VPC CC test
1 parent 1bc6ce8 commit 55a78fa

File tree

5 files changed

+200
-0
lines changed

5 files changed

+200
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- op: add
2+
path: /spec/topology/variables/-
3+
value:
4+
name: byoInfra
5+
value: "true"
6+
- op: add
7+
path: /spec/topology/variables/-
8+
value:
9+
name: vpcID
10+
value: "${BYO_VPC_ID}"
11+
- op: add
12+
path: /spec/topology/variables/-
13+
value:
14+
name: publicSubnetID
15+
value: "${BYO_PUBLIC_SUBNET_ID}"
16+
- op: add
17+
path: /spec/topology/variables/-
18+
value:
19+
name: privateSubnetID
20+
value: "${BYO_PRIVATE_SUBNET_ID}"
21+
- op: add
22+
path: /spec/topology/variables/-
23+
value:
24+
name: fdForBYOSubnets
25+
value: "us-west-2a"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bases:
2+
- ../topology/cluster-template.yaml
3+
4+
patches:
5+
- path: ./byo-infra-variables.yaml
6+
target:
7+
group: cluster.x-k8s.io
8+
version: v1beta1
9+
kind: Cluster
10+
- path: ./limited-az-variable.yaml
11+
target:
12+
group: cluster.x-k8s.io
13+
version: v1beta1
14+
kind: Cluster
15+
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- op: add
2+
path: /spec/topology/variables/-
3+
value:
4+
name: vpcAZUsageLimit
5+
value: "1"

test/e2e/data/infrastructure-aws/kustomize_sources/topology/clusterclass-ci-default.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,36 @@ spec:
7676
type: string
7777
default: ""
7878
example: "1"
79+
- name: vpcID
80+
required: false
81+
schema:
82+
openAPIV3Schema:
83+
type: string
84+
default: ""
85+
- name: publicSubnetID
86+
required: false
87+
schema:
88+
openAPIV3Schema:
89+
type: string
90+
default: ""
91+
- name: privateSubnetID
92+
required: false
93+
schema:
94+
openAPIV3Schema:
95+
type: string
96+
default: ""
97+
- name: fdForBYOSubnets
98+
required: false
99+
schema:
100+
openAPIV3Schema:
101+
type: string
102+
default: ""
103+
- name: byoInfra
104+
required: false
105+
schema:
106+
openAPIV3Schema:
107+
type: string
108+
default: "false"
79109
- name: selfHosted
80110
required: false
81111
schema:
@@ -214,6 +244,55 @@ spec:
214244
path: "/spec/template/spec/network/vpc/availabilityZoneUsageLimit"
215245
valueFrom:
216246
template: "{{ .vpcAZUsageLimit }}"
247+
- name: byoInfra
248+
enabledIf: '{{ eq .byoInfra "true" }}'
249+
definitions:
250+
- selector:
251+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
252+
kind: AWSClusterTemplate
253+
matchResources:
254+
infrastructureCluster: true
255+
jsonPatches:
256+
- op: add
257+
path: "/spec/template/spec/network/vpc/id"
258+
valueFrom:
259+
variable: vpcID
260+
- op: add
261+
path: "/spec/template/spec/network/subnets/0/id"
262+
valueFrom:
263+
variable: publicSubnetID
264+
- op: add
265+
path: "/spec/template/spec/network/subnets/1/id"
266+
valueFrom:
267+
variable: privateSubnetID
268+
- name: awsMachineTemplateControlPlaneForBYO
269+
enabledIf: '{{ eq .byoInfra "true" }}'
270+
definitions:
271+
- selector:
272+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
273+
kind: AWSMachineTemplate
274+
matchResources:
275+
controlPlane: true
276+
jsonPatches:
277+
- op: replace
278+
path: "/spec/template/spec/failureDomain"
279+
valueFrom:
280+
variable: fdForBYOSubnets
281+
- name: awsMachineTemplateWorkerForBYO
282+
enabledIf: '{{ eq .byoInfra "true" }}'
283+
definitions:
284+
- selector:
285+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
286+
kind: AWSMachineTemplate
287+
matchResources:
288+
machineDeploymentClass:
289+
names:
290+
- default-worker
291+
jsonPatches:
292+
- op: replace
293+
path: "/spec/template/spec/failureDomain"
294+
valueFrom:
295+
variable: fdForBYOSubnets
217296
---
218297
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
219298
kind: AWSClusterTemplate

test/e2e/suites/unmanaged/unmanaged_functional_clusterclass_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,79 @@ var _ = ginkgo.Context("[unmanaged] [functional] [ClusterClass]", func() {
125125
Expect(len(controlPlaneMachines)).To(Equal(1))
126126
})
127127
})
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+
128203
})

0 commit comments

Comments
 (0)