Skip to content

Commit 08bf927

Browse files
Add support for externally managed VCN (#65)
1 parent 9d7eb36 commit 08bf927

File tree

12 files changed

+320
-177
lines changed

12 files changed

+320
-177
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SKIP_CREATE_MGMT_CLUSTER ?= false
4747
ARTIFACTS ?= $(ROOT_DIR)/_artifacts
4848
KUBETEST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance.yaml)
4949
KUBETEST_FAST_CONF_PATH ?= $(abspath $(E2E_DATA_DIR)/kubetest/conformance-fast.yaml)
50-
GINKGO_FOCUS ?= Workload cluster creation
50+
GINKGO_FOCUS ?= "PRBlocking"
5151
GINKGO_SKIP ?= "Bare Metal|Multi-Region|VCNPeering"
5252
# Image URL to use all building/pushing image targets
5353
IMG ?= controller:latest
@@ -255,6 +255,7 @@ generate-e2e-templates: kustomize
255255
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-cluster-class --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-cluster-class.yaml
256256
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-local-vcn-peering --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-local-vcn-peering.yaml
257257
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-remote-vcn-peering --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-remote-vcn-peering.yaml
258+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn.yaml
258259

259260
.PHONY: test-e2e-run
260261
test-e2e-run: generate-e2e-templates ginkgo $(ENVSUBST) ## Run e2e tests

api/v1beta1/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ type Role string
239239

240240
type SubnetType string
241241

242-
//Subnet defines the configuration for a network's subnet
242+
// Subnet defines the configuration for a network's subnet
243243
// https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingVCNs_topic-Overview_of_VCNs_and_Subnets.htm#Overview
244244
type Subnet struct {
245245
// Role defines the subnet role (eg. control-plane, control-plane-endpoint, service-lb, worker).
@@ -335,6 +335,11 @@ type LoadBalancer struct {
335335

336336
// NetworkSpec specifies what the OCI networking resources should look like.
337337
type NetworkSpec struct {
338+
// SkipNetworkManagement defines if the networking spec(VCN related) specified by the user needs to be reconciled(actioned-upon)
339+
// or used as it is. APIServerLB will still be reconciled.
340+
// +optional
341+
SkipNetworkManagement bool `json:"skipNetworkManagement,omitempty"`
342+
338343
// VCN configuration.
339344
// +optional
340345
Vcn VCN `json:"vcn,omitempty"`

config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ spec:
8282
description: LoadBalancer Name.
8383
type: string
8484
type: object
85+
skipNetworkManagement:
86+
description: SkipNetworkManagement defines if the networking spec(VCN
87+
related) specified by the user needs to be reconciled(actioned-upon)
88+
or used as it is. APIServerLB will still be reconciled.
89+
type: boolean
8590
vcn:
8691
description: VCN configuration.
8792
properties:

config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ spec:
9393
description: LoadBalancer Name.
9494
type: string
9595
type: object
96+
skipNetworkManagement:
97+
description: SkipNetworkManagement defines if the networking
98+
spec(VCN related) specified by the user needs to be
99+
reconciled(actioned-upon) or used as it is. APIServerLB
100+
will still be reconciled.
101+
type: boolean
96102
vcn:
97103
description: VCN configuration.
98104
properties:

controllers/ocicluster_controller.go

Lines changed: 127 additions & 115 deletions
Large diffs are not rendered by default.

controllers/ocicluster_controller_test.go

Lines changed: 70 additions & 54 deletions
Large diffs are not rendered by default.

docs/src/networking/custom-networking.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ kind: OCICluster
1919
metadata:
2020
name: "${CLUSTER_NAME}"
2121
spec:
22+
compartmentId: "${OCI_COMPARTMENT_ID}"
2223
networkSpec:
2324
vcn:
2425
name: ${CLUSTER_NAME}
@@ -53,6 +54,7 @@ kind: OCICluster
5354
metadata:
5455
name: "${CLUSTER_NAME}"
5556
spec:
57+
compartmentId: "${OCI_COMPARTMENT_ID}"
5658
networkSpec:
5759
vcn:
5860
name: ${CLUSTER_NAME}
@@ -179,6 +181,7 @@ kind: OCICluster
179181
metadata:
180182
name: "${CLUSTER_NAME}"
181183
spec:
184+
compartmentId: "${OCI_COMPARTMENT_ID}"
182185
networkSpec:
183186
vcn:
184187
name: ${CLUSTER_NAME}
@@ -270,4 +273,38 @@ spec:
270273
271274
Related documentation: [comparison of Security Lists and Network Security Groups][sl-vs-nsg]
272275
276+
## Example spec for externally managed VCN infrastructure
277+
278+
CAPOCI can be used to create a cluster using existing VCN infrastructure. In this case, only the
279+
API Server Load Balancer will be managed by CAPOCI.
280+
281+
Example spec is given below
282+
283+
```yaml
284+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
285+
kind: OCICluster
286+
metadata:
287+
name: "${CLUSTER_NAME}"
288+
spec:
289+
compartmentId: "${OCI_COMPARTMENT_ID}"
290+
networkSpec:
291+
skipNetworkManagement: true
292+
vcn:
293+
id: <Insert VCN OCID Here>
294+
networkSecurityGroups:
295+
- id: <Insert Control Plane Endpoint NSG OCID Here>
296+
role: control-plane-endpoint
297+
- id: <Insert Worker NSG OCID Here>
298+
role: worker
299+
- id: <Insert Control Plane NSG OCID Here>
300+
role: control-plane
301+
subnets:
302+
- id: <Insert Control Plane Endpoint Subnet OCID Here>
303+
role: control-plane-endpoint
304+
- id: <Insert Worker Subnet OCID Here>
305+
role: worker
306+
- id: <Insert control Plane Subnet OCID Here>
307+
role: control-plane
308+
```
309+
273310
[sl-vs-nsg]: https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/securityrules.htm#comparison

test/e2e/cluster_test.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var _ = Describe("Workload cluster creation", func() {
107107
dumpSpecResourcesAndCleanup(ctx, cleanInput)
108108
})
109109

110-
It("Default CNI - with 1 control-plane nodes and 1 worker nodes", func() {
110+
It("Default CNI - with 1 control-plane nodes and 1 worker nodes [PRBlocking]", func() {
111111
clusterName = getClusterName(clusterNamePrefix, "simple")
112112
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
113113
ClusterProxy: bootstrapClusterProxy,
@@ -130,7 +130,7 @@ var _ = Describe("Workload cluster creation", func() {
130130
}, result)
131131
})
132132

133-
It("Default CNI - With 3 control plane nodes spread across failure domains", func() {
133+
It("Default CNI - With 3 control plane nodes spread across failure domains [PRBlocking]", func() {
134134
clusterName = getClusterName(clusterNamePrefix, "3nodecontrolplane")
135135
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
136136
ClusterProxy: bootstrapClusterProxy,
@@ -198,7 +198,7 @@ var _ = Describe("Workload cluster creation", func() {
198198
validateOLImage(namespace.Name, clusterName)
199199
})
200200

201-
It("Cloud Provider OCI testing", func() {
201+
It("Cloud Provider OCI testing [PRBlocking]", func() {
202202
clusterName = getClusterName(clusterNamePrefix, "ccm-testing")
203203
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
204204
ClusterProxy: bootstrapClusterProxy,
@@ -283,7 +283,7 @@ var _ = Describe("Workload cluster creation", func() {
283283
deletePVC(nginxStatefulsetInfo, clusterClient)
284284
})
285285

286-
It("Custom networking NSG", func() {
286+
It("Custom networking NSG [PRBlocking]", func() {
287287
clusterName = getClusterName(clusterNamePrefix, "custom-nsg")
288288
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
289289
ClusterProxy: bootstrapClusterProxy,
@@ -467,7 +467,7 @@ var _ = Describe("Workload cluster creation", func() {
467467
}, result)
468468
})
469469

470-
It("ClusterClass - with 1 control-plane nodes and 1 worker nodes", func() {
470+
It("ClusterClass - with 1 control-plane nodes and 1 worker nodes [PRBlocking]", func() {
471471
clusterName = getClusterName(clusterNamePrefix, "clusterclass")
472472
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
473473
ClusterProxy: bootstrapClusterProxy,
@@ -489,6 +489,29 @@ var _ = Describe("Workload cluster creation", func() {
489489
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
490490
}, result)
491491
})
492+
493+
It("Externally managed VCN", func() {
494+
clusterName = getClusterName(clusterNamePrefix, "externally-managed-vcn")
495+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
496+
ClusterProxy: bootstrapClusterProxy,
497+
ConfigCluster: clusterctl.ConfigClusterInput{
498+
LogFolder: filepath.Join(artifactFolder, "clusters", bootstrapClusterProxy.GetName()),
499+
ClusterctlConfigPath: clusterctlConfigPath,
500+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
501+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
502+
Flavor: "externally-managed-vcn",
503+
Namespace: namespace.Name,
504+
ClusterName: clusterName,
505+
KubernetesVersion: e2eConfig.GetVariable(capi_e2e.KubernetesVersion),
506+
ControlPlaneMachineCount: pointer.Int64Ptr(1),
507+
WorkerMachineCount: pointer.Int64Ptr(1),
508+
},
509+
CNIManifestPath: e2eConfig.GetVariable(capi_e2e.CNIPath),
510+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
511+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
512+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
513+
}, result)
514+
})
492515
})
493516

494517
func verifyMultipleNsgSubnet(ctx context.Context, namespace string, clusterName string, mcDeployments []*clusterv1.MachineDeployment) {

test/e2e/config/e2e_conf.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ providers:
6868
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-cluster-class/clusterclass-test-cluster-class.yaml"
6969
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-local-vcn-peering.yaml"
7070
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-remote-vcn-peering.yaml"
71+
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-externally-managed-vcn.yaml"
7172
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
7273

7374

@@ -92,6 +93,13 @@ variables:
9293
LOCAL_DRG_ID: "${LOCAL_DRG_ID}"
9394
PEER_DRG_ID: "${PEER_DRG_ID}"
9495
PEER_REGION_NAME: "${PEER_REGION_NAME}"
96+
EXTERNAL_VCN_ID: "${EXTERNAL_VCN_ID}"
97+
EXTERNAL_VCN_CPE_NSG: "${EXTERNAL_VCN_CPE_NSG}"
98+
EXTERNAL_VCN_WORKER_NSG: "${EXTERNAL_VCN_WORKER_NSG}"
99+
EXTERNAL_VCN_CP_NSG: "${EXTERNAL_VCN_CP_NSG}"
100+
EXTERNAL_VCN_CPE_SUBNET: "${EXTERNAL_VCN_CPE_SUBNET}"
101+
EXTERNAL_VCN_WORKER_SUBNET: "${EXTERNAL_VCN_WORKER_SUBNET}"
102+
EXTERNAL_VCN_CP_SUBNET: "${EXTERNAL_VCN_CP_SUBNET}"
95103

96104
intervals:
97105
default/wait-controllers: ["3m", "10s"]

test/e2e/data/infrastructure-oci/v1beta1/cluster-template-cluster-class/clusterclass-test-cluster-class.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ spec:
203203
spec:
204204
metadata: {}
205205
shapeConfig: {}
206-
207206
---
208207
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
209208
kind: OCIMachineTemplate

0 commit comments

Comments
 (0)