Skip to content

Commit

Permalink
Add external VPC CC test
Browse files Browse the repository at this point in the history
  • Loading branch information
sedefsavas committed Sep 25, 2022
1 parent 1bc6ce8 commit 55a78fa
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- op: add
path: /spec/topology/variables/-
value:
name: byoInfra
value: "true"
- op: add
path: /spec/topology/variables/-
value:
name: vpcID
value: "${BYO_VPC_ID}"
- op: add
path: /spec/topology/variables/-
value:
name: publicSubnetID
value: "${BYO_PUBLIC_SUBNET_ID}"
- op: add
path: /spec/topology/variables/-
value:
name: privateSubnetID
value: "${BYO_PRIVATE_SUBNET_ID}"
- op: add
path: /spec/topology/variables/-
value:
name: fdForBYOSubnets
value: "us-west-2a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bases:
- ../topology/cluster-template.yaml

patches:
- path: ./byo-infra-variables.yaml
target:
group: cluster.x-k8s.io
version: v1beta1
kind: Cluster
- path: ./limited-az-variable.yaml
target:
group: cluster.x-k8s.io
version: v1beta1
kind: Cluster


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- op: add
path: /spec/topology/variables/-
value:
name: vpcAZUsageLimit
value: "1"
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ spec:
type: string
default: ""
example: "1"
- name: vpcID
required: false
schema:
openAPIV3Schema:
type: string
default: ""
- name: publicSubnetID
required: false
schema:
openAPIV3Schema:
type: string
default: ""
- name: privateSubnetID
required: false
schema:
openAPIV3Schema:
type: string
default: ""
- name: fdForBYOSubnets
required: false
schema:
openAPIV3Schema:
type: string
default: ""
- name: byoInfra
required: false
schema:
openAPIV3Schema:
type: string
default: "false"
- name: selfHosted
required: false
schema:
Expand Down Expand Up @@ -214,6 +244,55 @@ spec:
path: "/spec/template/spec/network/vpc/availabilityZoneUsageLimit"
valueFrom:
template: "{{ .vpcAZUsageLimit }}"
- name: byoInfra
enabledIf: '{{ eq .byoInfra "true" }}'
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSClusterTemplate
matchResources:
infrastructureCluster: true
jsonPatches:
- op: add
path: "/spec/template/spec/network/vpc/id"
valueFrom:
variable: vpcID
- op: add
path: "/spec/template/spec/network/subnets/0/id"
valueFrom:
variable: publicSubnetID
- op: add
path: "/spec/template/spec/network/subnets/1/id"
valueFrom:
variable: privateSubnetID
- name: awsMachineTemplateControlPlaneForBYO
enabledIf: '{{ eq .byoInfra "true" }}'
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSMachineTemplate
matchResources:
controlPlane: true
jsonPatches:
- op: replace
path: "/spec/template/spec/failureDomain"
valueFrom:
variable: fdForBYOSubnets
- name: awsMachineTemplateWorkerForBYO
enabledIf: '{{ eq .byoInfra "true" }}'
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSMachineTemplate
matchResources:
machineDeploymentClass:
names:
- default-worker
jsonPatches:
- op: replace
path: "/spec/template/spec/failureDomain"
valueFrom:
variable: fdForBYOSubnets
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSClusterTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,79 @@ var _ = ginkgo.Context("[unmanaged] [functional] [ClusterClass]", func() {
Expect(len(controlPlaneMachines)).To(Equal(1))
})
})

// This test creates a workload cluster using an externally managed VPC and subnets. CAPA is still handling security group
// creation for the cluster. All applicable resources are restricted to us-west-2a for simplicity.
ginkgo.Describe("Workload cluster with external infrastructure", func() {
var namespace *corev1.Namespace
var requiredResources *shared.TestResource
specName := "functional-test-extinfra-clusterclass"
mgmtClusterName := fmt.Sprintf("%s-%s", specName, util.RandomString(6))
mgmtClusterInfra := new(shared.AWSInfrastructure)

// Some infrastructure creation was moved to a setup node to better organize the test.
ginkgo.JustBeforeEach(func() {
requiredResources = &shared.TestResource{EC2Normal: 2 * e2eCtx.Settings.InstanceVCPU, IGW: 2, NGW: 2, VPC: 2, ClassicLB: 2, EIP: 5}
requiredResources.WriteRequestedResources(e2eCtx, specName)
Expect(shared.AcquireResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath))).To(Succeed())
namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx)
ginkgo.By("Creating the management cluster infrastructure")
mgmtClusterInfra.New(shared.AWSInfrastructureSpec{
ClusterName: mgmtClusterName,
VpcCidr: "10.0.0.0/23",
PublicSubnetCidr: "10.0.0.0/24",
PrivateSubnetCidr: "10.0.1.0/24",
AvailabilityZone: "us-west-2a",
}, e2eCtx)
mgmtClusterInfra.CreateInfrastructure()
})

// Infrastructure cleanup is done in setup node so it is not bypassed if there is a test failure in the subject node.
ginkgo.JustAfterEach(func() {
shared.ReleaseResources(requiredResources, config.GinkgoConfig.ParallelNode, flock.New(shared.ResourceQuotaFilePath))
shared.DumpSpecResourcesAndCleanup(ctx, "", namespace, e2eCtx)
if !e2eCtx.Settings.SkipCleanup {
ginkgo.By("Deleting the management cluster infrastructure")
mgmtClusterInfra.DeleteInfrastructure()
}
})

ginkgo.It("should create workload cluster in external VPC", func() {
ginkgo.By("Validating management infrastructure")
Expect(mgmtClusterInfra.VPC).NotTo(BeNil())
Expect(*mgmtClusterInfra.State.VpcState).To(Equal("available"))
Expect(len(mgmtClusterInfra.Subnets)).To(Equal(2))
Expect(mgmtClusterInfra.InternetGateway).NotTo(BeNil())
Expect(mgmtClusterInfra.ElasticIP).NotTo(BeNil())
Expect(mgmtClusterInfra.NatGateway).NotTo(BeNil())
Expect(len(mgmtClusterInfra.RouteTables)).To(Equal(2))

shared.SetEnvVar("BYO_VPC_ID", *mgmtClusterInfra.VPC.VpcId, false)
shared.SetEnvVar("BYO_PUBLIC_SUBNET_ID", *mgmtClusterInfra.State.PublicSubnetID, false)
shared.SetEnvVar("BYO_PRIVATE_SUBNET_ID", *mgmtClusterInfra.State.PrivateSubnetID, false)

ginkgo.By("Creating a management cluster in a peered VPC")
mgmtConfigCluster := defaultConfigCluster(mgmtClusterName, namespace.Name)
mgmtConfigCluster.WorkerMachineCount = pointer.Int64Ptr(1)
mgmtConfigCluster.Flavor = "external-vpc-clusterclass"
mgmtCluster, mgmtMD, _ := createCluster(ctx, mgmtConfigCluster, result)

mgmtWM := framework.GetMachinesByMachineDeployments(ctx, framework.GetMachinesByMachineDeploymentsInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: mgmtClusterName,
Namespace: namespace.Name,
MachineDeployment: *mgmtMD[0],
})
mgmtCPM := framework.GetControlPlaneMachinesByCluster(ctx, framework.GetControlPlaneMachinesByClusterInput{
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
ClusterName: mgmtClusterName,
Namespace: namespace.Name,
})
Expect(len(mgmtWM)).To(Equal(1))
Expect(len(mgmtCPM)).To(Equal(1))
ginkgo.By("Deleting the management cluster")
deleteCluster(ctx, mgmtCluster)
})
})

})

0 comments on commit 55a78fa

Please sign in to comment.