Skip to content

Commit 45e5b26

Browse files
Add custom role support (#313)
* Add support for custom roles in NSG/Subnet
1 parent bb5aea3 commit 45e5b26

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

api/v1beta2/ocicluster_webhook_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,29 @@ func TestOCICluster_ValidateCreate(t *testing.T) {
244244
errorMgsShouldContain: "subnet role invalid",
245245
expectErr: true,
246246
},
247+
{
248+
name: "allow subnet custom role",
249+
c: &OCICluster{
250+
ObjectMeta: metav1.ObjectMeta{
251+
Name: goodClusterName,
252+
},
253+
Spec: OCIClusterSpec{
254+
CompartmentId: "ocid",
255+
OCIResourceIdentifier: "uuid",
256+
NetworkSpec: NetworkSpec{
257+
Vcn: VCN{
258+
CIDR: "10.0.0.0/16",
259+
Subnets: []*Subnet{
260+
&Subnet{
261+
Role: Custom,
262+
},
263+
},
264+
},
265+
},
266+
},
267+
},
268+
expectErr: false,
269+
},
247270
{
248271
name: "shouldn't allow invalid role",
249272
c: &OCICluster{
@@ -393,6 +416,26 @@ func TestOCICluster_ValidateCreate(t *testing.T) {
393416
errorMgsShouldContain: "networkSecurityGroup role invalid",
394417
expectErr: true,
395418
},
419+
{
420+
name: "allow nsg custom role",
421+
c: &OCICluster{
422+
ObjectMeta: metav1.ObjectMeta{
423+
Name: goodClusterName,
424+
},
425+
Spec: OCIClusterSpec{
426+
CompartmentId: "ocid",
427+
OCIResourceIdentifier: "uuid",
428+
NetworkSpec: NetworkSpec{
429+
Vcn: VCN{
430+
NetworkSecurityGroup: NetworkSecurityGroup{List: []*NSG{{
431+
Role: Custom,
432+
}}},
433+
},
434+
},
435+
},
436+
},
437+
expectErr: false,
438+
},
396439
{
397440
name: "should allow blank region",
398441
c: &OCICluster{

api/v1beta2/ocimanagedcluster_webhook_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@ func TestOCIManagedCluster_ValidateCreate(t *testing.T) {
267267
errorMgsShouldContain: "subnet role invalid",
268268
expectErr: true,
269269
},
270+
{
271+
name: "should allow custom subnet role",
272+
c: &OCIManagedCluster{
273+
ObjectMeta: metav1.ObjectMeta{
274+
Name: goodClusterName,
275+
},
276+
Spec: OCIManagedClusterSpec{
277+
Region: "",
278+
CompartmentId: "ocid",
279+
OCIResourceIdentifier: "uuid",
280+
NetworkSpec: NetworkSpec{
281+
Vcn: VCN{
282+
CIDR: "10.0.0.0/16",
283+
Subnets: []*Subnet{
284+
&Subnet{
285+
Role: Custom,
286+
},
287+
},
288+
},
289+
},
290+
},
291+
},
292+
expectErr: false,
293+
},
270294
{
271295
name: "should allow empty subnet name",
272296
c: &OCIManagedCluster{
@@ -380,6 +404,28 @@ func TestOCIManagedCluster_ValidateCreate(t *testing.T) {
380404
errorMgsShouldContain: "networkSecurityGroup role invalid",
381405
expectErr: true,
382406
},
407+
{
408+
name: "should allow custom NSG role",
409+
c: &OCIManagedCluster{
410+
ObjectMeta: metav1.ObjectMeta{
411+
Name: goodClusterName,
412+
},
413+
Spec: OCIManagedClusterSpec{
414+
CompartmentId: "ocid",
415+
OCIResourceIdentifier: "uuid",
416+
NetworkSpec: NetworkSpec{
417+
Vcn: VCN{
418+
NetworkSecurityGroup: NetworkSecurityGroup{
419+
List: []*NSG{{
420+
Role: Custom,
421+
}},
422+
},
423+
},
424+
},
425+
},
426+
},
427+
expectErr: false,
428+
},
383429
{
384430
name: "should allow blank region",
385431
c: &OCIManagedCluster{

api/v1beta2/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ const (
2424
PodRole = "pod"
2525
Private = "private"
2626
Public = "public"
27+
Custom = "custom"
2728
)
2829

2930
// OCIClusterSubnetRoles a slice of all the subnet roles for self managed cluster
30-
var OCIClusterSubnetRoles = []Role{ControlPlaneRole, ControlPlaneEndpointRole, WorkerRole, ServiceLoadBalancerRole}
31+
var OCIClusterSubnetRoles = []Role{ControlPlaneRole, ControlPlaneEndpointRole, WorkerRole, ServiceLoadBalancerRole, Custom}
3132

3233
// OCIManagedClusterSubnetRoles a slice of all the subnet roles for managed cluster
33-
var OCIManagedClusterSubnetRoles = []Role{PodRole, ControlPlaneEndpointRole, WorkerRole, ServiceLoadBalancerRole}
34+
var OCIManagedClusterSubnetRoles = []Role{PodRole, ControlPlaneEndpointRole, WorkerRole, ServiceLoadBalancerRole, Custom}
3435

3536
// NetworkDetails defines the configuration options for the network
3637
type NetworkDetails struct {

docs/src/networking/custom-networking.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,45 @@ spec:
300300
loadBalancerType: "lb"
301301
```
302302
303+
## Example spec to use custom role
304+
305+
CAPOCI can be used to create Subnet/NSG in the VCN for custom workloads such as private load balancers,
306+
dedicated subnet for DB connection etc. The roles for such custom subnest must be defined as `custom`.
307+
The following spec shows an example for this scenario.
308+
309+
```yaml
310+
---
311+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
312+
kind: OCICluster
313+
metadata:
314+
name: "${CLUSTER_NAME}"
315+
spec:
316+
compartmentId: "${OCI_COMPARTMENT_ID}"
317+
networkSpec:
318+
vcn:
319+
name: ${CLUSTER_NAME}
320+
subnets:
321+
- name: db
322+
role: custom
323+
type: public
324+
cidr: "172.16.5.0/28"
325+
networkSecurityGroup:
326+
list:
327+
- name: db
328+
role: custom
329+
egressRules:
330+
- egressRule:
331+
isStateless: false
332+
destination: "172.16.5.0/28"
333+
protocol: "6"
334+
destinationType: "CIDR_BLOCK"
335+
description: "All traffic to control plane nodes"
336+
tcpOptions:
337+
destinationPortRange:
338+
max: 6443
339+
min: 6443
340+
```
341+
303342
[sl-vs-nsg]: https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/securityrules.htm#comparison
304343
[externally-managed-cluster-infrastructure]: ../gs/externally-managed-cluster-infrastructure.md#example-spec-for-externally-managed-vcn-infrastructure
305344
[oci-nlb]: https://docs.oracle.com/en-us/iaas/Content/NetworkLoadBalancer/introducton.htm#Overview

0 commit comments

Comments
 (0)