Skip to content

Commit 042387f

Browse files
authored
Merge pull request #2818 from oracle-devrel/oke-rm
oke-rm-1.3.4
2 parents 1972dca + 1e53356 commit 042387f

File tree

24 files changed

+742
-326
lines changed

24 files changed

+742
-326
lines changed

app-dev/devops-and-containers/oke/oke-rm/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ This stack is used to create the initial network infrastructure for OKE. When co
1717
* You can apply this stack even on an existing VCN, so that only the NSGs for OKE will be created
1818
* The default CNI is the VCN Native CNI, and it is the recommended one
1919

20-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.3.3/infra.zip)
20+
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.3.4/infra.zip)
2121

2222
## Step 2: Create the OKE control plane
2323

2424
This stack is used to create the OKE control plane ONLY.
2525

26-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.3.3/oke.zip)
26+
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.3.4/oke.zip)
2727

2828
Also note that if the network infrastructure is located in a different compartment than the OKE cluster AND you are planning to use the OCI_VCN_NATIVE CNI,
2929
you must add these policies:
@@ -90,4 +90,5 @@ If you are looking to provision an OKE cluster for RDMA and GPUs using this stac
9090

9191
Provisioning an OKE cluster is just the first step, be sure to also check out these guides to learn how to configure it:
9292
* [OKE policies](../oke-policies/policies.md)
93-
* [GitOps with ArgoCD](../oke-gitops/README.md)
93+
* [Karpenter guide](oke-oci-karpenter-guide.md)
94+
* [OKE GitOps Solution](../oke-gitops/README.md)
1.23 KB
Binary file not shown.

app-dev/devops-and-containers/oke/oke-rm/infra/main.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ module "network" {
3333
worker_subnet_name = var.worker_subnet_name
3434
allow_worker_nat_egress = var.allow_worker_nat_egress
3535
# POD SUBNET
36-
create_pod_subnet = var.create_pod_subnet
37-
pod_subnet_cidr = local.subnets.cidr.pod
38-
pod_subnet_dns_label = local.subnets.dns.pod
39-
pod_subnet_name = var.pod_subnet_name
40-
allow_pod_nat_egress = var.allow_pod_nat_egress
36+
create_pod_subnet = var.create_pod_subnet
37+
pod_subnet_cidr = local.subnets.cidr.pod
38+
pod_subnet_dns_label = local.subnets.dns.pod
39+
pod_subnet_name = var.pod_subnet_name
40+
allow_pod_nat_egress = var.allow_pod_nat_egress
41+
create_additional_pod_cidr = var.create_additional_pod_cidr
42+
additional_pod_cidr = var.additional_pod_cidr
4143
# BASTION SUBNET
4244
create_bastion_subnet = var.create_bastion_subnet
4345
bastion_subnet_cidr = local.subnets.cidr.bastion

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/local.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ locals {
2828

2929
create_msg_subnet = var.create_msg_subnet && var.create_vcn
3030

31+
karpenter_role_tag_key = "karpenter-oci/role"
32+
karpenter_worker_role_tag_value = "worker"
33+
karpenter_pod_role_tag_value = "pod"
34+
35+
karpenter_worker_role_freeform_tag = { (local.karpenter_role_tag_key) = local.karpenter_worker_role_tag_value }
36+
karpenter_pod_role_freeform_tag = { (local.karpenter_role_tag_key) = local.karpenter_pod_role_tag_value }
37+
38+
vcn_cidr_blocks = var.create_additional_pod_cidr ? distinct(concat(var.vcn_cidr_blocks, var.additional_pod_cidr)) : var.vcn_cidr_blocks
39+
pod_ipv4cidr_blocks = var.create_additional_pod_cidr && length(var.additional_pod_cidr) > 0 ? concat([var.pod_subnet_cidr], var.additional_pod_cidr) : [var.pod_subnet_cidr]
40+
3141
tcp_protocol = "6"
3242
icmp_protocol = "1"
3343
udp_protocol = "17"

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/peering-nsg.tf

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
locals {
22
# Only used when NSG exists
3-
peer_vcns_set = local.create_drg_attachment ? toset(var.peer_vcns) : []
3+
peer_vcns_open_set = local.create_drg_attachment ? toset([for cidr in var.peer_vcns : cidr if cidr == "0.0.0.0/0"]) : []
4+
peer_vcns_safe_set = local.create_drg_attachment ? toset([for cidr in var.peer_vcns : cidr if cidr != "0.0.0.0/0"]) : []
45
}
56

67
resource "oci_core_network_security_group" "peering" {
@@ -13,7 +14,7 @@ resource "oci_core_network_security_group" "peering" {
1314
}
1415

1516
resource "oci_core_network_security_group_security_rule" "peering_egress" {
16-
for_each = local.peer_vcns_set
17+
for_each = local.peer_vcns_safe_set
1718
direction = "EGRESS"
1819
network_security_group_id = oci_core_network_security_group.peering.0.id
1920
protocol = "all"
@@ -24,12 +25,23 @@ resource "oci_core_network_security_group_security_rule" "peering_egress" {
2425
}
2526

2627
resource "oci_core_network_security_group_security_rule" "peering_ingress" {
27-
for_each = local.peer_vcns_set
28+
for_each = local.peer_vcns_safe_set
2829
direction = "INGRESS"
2930
network_security_group_id = oci_core_network_security_group.peering.0.id
3031
protocol = "all"
3132
source_type = "CIDR_BLOCK"
3233
source = each.value
3334
stateless = true
3435
description = "Allow ingress traffic from peered VCN ${each.value}"
35-
}
36+
}
37+
38+
resource "oci_core_network_security_group_security_rule" "peering_egress_open_stateful" {
39+
for_each = local.peer_vcns_open_set
40+
direction = "EGRESS"
41+
network_security_group_id = oci_core_network_security_group.peering.0.id
42+
protocol = "all"
43+
destination_type = "CIDR_BLOCK"
44+
destination = each.value
45+
stateless = false
46+
description = "Allow stateful egress traffic for open peering CIDR ${each.value}"
47+
}

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/pod-nsg.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "oci_core_network_security_group" "pod_nsg" {
22
compartment_id = var.network_compartment_id
33
vcn_id = local.vcn_id
44
display_name = "pod"
5-
freeform_tags = var.tag_value.freeformTags
5+
freeform_tags = merge(var.tag_value.freeformTags, local.karpenter_pod_role_freeform_tag)
66
defined_tags = var.tag_value.definedTags
77
count = local.is_npn ? 1 : 0
88
}

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/routing.tf

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
locals {
2+
peer_vcns_default_set = local.create_drg_attachment ? toset([for cidr in var.peer_vcns : cidr if cidr == "0.0.0.0/0"]) : toset([])
3+
peer_vcns_non_default_set = local.create_drg_attachment ? toset([for cidr in var.peer_vcns : cidr if cidr != "0.0.0.0/0"]) : toset([])
4+
5+
cp_has_default_route = (!var.cp_subnet_private) || local.cp_nat_mode
6+
lb_int_has_default_route = false
7+
worker_has_default_route = local.create_nat_gateway && var.allow_worker_nat_egress
8+
pod_has_default_route = local.create_nat_gateway && var.allow_pod_nat_egress
9+
10+
cp_drg_peer_vcns = setunion(local.peer_vcns_non_default_set, local.cp_has_default_route ? toset([]) : local.peer_vcns_default_set)
11+
lb_int_drg_peer_vcns = setunion(local.peer_vcns_non_default_set, local.lb_int_has_default_route ? toset([]) : local.peer_vcns_default_set)
12+
worker_drg_peer_vcns = setunion(local.peer_vcns_non_default_set, local.worker_has_default_route ? toset([]) : local.peer_vcns_default_set)
13+
pod_drg_peer_vcns = setunion(local.peer_vcns_non_default_set, local.pod_has_default_route ? toset([]) : local.peer_vcns_default_set)
14+
}
15+
116
resource "oci_core_route_table" "bastion_route_table" {
217
compartment_id = var.network_compartment_id
318
vcn_id = local.vcn_id
@@ -59,7 +74,7 @@ resource "oci_core_route_table" "cp_route_table" {
5974
}
6075
}
6176
dynamic "route_rules" {
62-
for_each = local.create_drg_attachment ? var.peer_vcns : []
77+
for_each = local.cp_drg_peer_vcns
6378
content {
6479
network_entity_id = local.drg_id
6580
destination_type = "CIDR_BLOCK"
@@ -98,7 +113,7 @@ resource "oci_core_route_table" "lb_int_route_table" {
98113
description = "Route for all internal OCI services in the region"
99114
}
100115
dynamic "route_rules" {
101-
for_each = local.create_drg_attachment ? var.peer_vcns : []
116+
for_each = local.lb_int_drg_peer_vcns
102117
content {
103118
network_entity_id = local.drg_id
104119
destination_type = "CIDR_BLOCK"
@@ -131,7 +146,7 @@ resource "oci_core_route_table" "worker_route_table" {
131146
}
132147
}
133148
dynamic "route_rules" {
134-
for_each = local.create_drg_attachment ? var.peer_vcns : []
149+
for_each = local.worker_drg_peer_vcns
135150
content {
136151
network_entity_id = local.drg_id
137152
destination_type = "CIDR_BLOCK"
@@ -164,7 +179,7 @@ resource "oci_core_route_table" "pod_route_table" {
164179
}
165180
}
166181
dynamic "route_rules" {
167-
for_each = local.create_drg_attachment ? var.peer_vcns : []
182+
for_each = local.pod_drg_peer_vcns
168183
content {
169184
network_entity_id = local.drg_id
170185
destination_type = "CIDR_BLOCK"
@@ -218,4 +233,4 @@ resource "oci_core_route_table" "msg_route_table" {
218233
description = "Route for all internal OCI services in the region"
219234
}
220235
count = local.create_msg_subnet ? 1 : 0
221-
}
236+
}

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/subnet.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ resource "oci_core_subnet" "worker_subnet" {
5454
route_table_id = oci_core_route_table.worker_route_table.0.id
5555
security_list_ids = [oci_core_security_list.worker_sl.0.id]
5656
dhcp_options_id = oci_core_dhcp_options.worker_dhcp[0].id
57-
freeform_tags = var.tag_value.freeformTags
57+
freeform_tags = merge(var.tag_value.freeformTags, local.karpenter_worker_role_freeform_tag)
5858
defined_tags = var.tag_value.definedTags
5959
count = local.create_worker_subnet ? 1 : 0
6060
}
6161

6262
resource "oci_core_subnet" "pods_subnet" {
63-
cidr_block = var.pod_subnet_cidr
63+
ipv4cidr_blocks = local.pod_ipv4cidr_blocks
6464
compartment_id = var.network_compartment_id
6565
vcn_id = local.vcn_id
6666
dns_label = var.pod_subnet_dns_label
@@ -69,7 +69,7 @@ resource "oci_core_subnet" "pods_subnet" {
6969
route_table_id = oci_core_route_table.pod_route_table.0.id
7070
security_list_ids = [oci_core_security_list.pod_sl.0.id]
7171
dhcp_options_id = oci_core_dhcp_options.pods_dhcp[0].id
72-
freeform_tags = var.tag_value.freeformTags
72+
freeform_tags = merge(var.tag_value.freeformTags, local.karpenter_pod_role_freeform_tag)
7373
defined_tags = var.tag_value.definedTags
7474
count = local.create_pod_subnet ? 1 : 0
7575
}

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/variable.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ variable "allow_pod_nat_egress" {
9393
type = bool
9494
}
9595

96+
variable "create_additional_pod_cidr" {
97+
type = bool
98+
}
99+
100+
variable "additional_pod_cidr" {
101+
type = list(string)
102+
}
103+
96104
# LB SUBNETS
97105

98106
variable "create_external_lb_subnet" {

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/vcn.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "oci_core_vcn" "spoke_vcn" {
22
compartment_id = var.network_compartment_id
33
display_name = var.vcn_name
4-
cidr_blocks = var.vcn_cidr_blocks
4+
cidr_blocks = local.vcn_cidr_blocks
55
dns_label = var.vcn_dns_label
66
freeform_tags = var.tag_value.freeformTags
77
defined_tags = var.tag_value.definedTags

0 commit comments

Comments
 (0)